Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Cart Details outside of OS


elogicmedia

Recommended Posts

Hi, I want to create a file that will show the carts details outside of the files within the oscommerce/catalog.

 

For Example:

see here: http://www.profilehealthservices.com/catal...opping_cart.php I have the cart going on the side, this is great, I how want to be able to display this on any page within the site such as:

 

http://www.profilehealthservices.com/physi...ducts/index.htm

 

Notice the current cart on this is static and does not collect the carts details from sessions and mysql etc.

 

So how could I go about doing this? I have tried including the classes/shopping_cart.php and configure.php files then having the below code on the site but I just get errors such as:

 

Fatal error: Call to a member function on a non-object in /home/virtual/site25/fst/var/www/html/any_cart.php on line 15

 

 

Is there some other files I will need to include to get this working?

 

Above Mentioned Code:

  <?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_SHOPPING_CART);

 //new infoBoxHeading($info_box_contents, false, true, tep_href_link(FILENAME_SHOPPING_CART));

 $cart_contents_string = '';
 if ($cart->count_contents() > 0) {
   $cart_contents_string = '<table border="0" width="100%" cellspacing="0" cellpadding="0">';
   $products = $cart->get_products();
   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
     $cart_contents_string .= '<tr><td align="right" valign="top">';

     if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
       $cart_contents_string .= '<span class="newItemInCart">';
     } else {
       $cart_contents_string .= '<span class="infoBoxContents">';
     }

     $cart_contents_string .= $products[$i]['quantity'] . ' x </span></td><td valign="top" class="infoBoxContents"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">';

     if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
       $cart_contents_string .= '<span class="newItemInCart">';
     } else {
       $cart_contents_string .= '<span class="infoBoxContents">';
     }

     $cart_contents_string .= $products[$i]['name'] . '</span></a></td></tr>';

     if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
       tep_session_unregister('new_products_id_in_cart');
     }
   }
   $cart_contents_string .= '</table>';
 } else {
   $cart_contents_string .= BOX_SHOPPING_CART_EMPTY;
 }

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $cart_contents_string);

 if ($cart->count_contents() > 0) {
   $info_box_contents[] = array('text' => tep_draw_separator());
   $info_box_contents[] = array('align' => 'right',
                                'text' => $currencies->format($cart->show_total()));
 }

 new infoBox($info_box_contents);
?>

Link to comment
Share on other sites

Hi, I am using the above contribution you mentioned and it seems to be close to what I want however for some reason the carts contents does not show up when you click back out of os..

 

You can see this via the below links

 

The Page outside of OS with the contribution installed.. (cart contents)

 

AND

 

 

The shopping cart page

 

Each time you clikc back you get an empty cart again, something must be emptying the cart for some reason...

 

I am using this contribution: http://www.oscommerce.com/community/contributions,1444

 

Anyone able to help me fix this problem?

 

Thankyou

Link to comment
Share on other sites

I haven't used or studied those contributions, I wonder if they are meant to deal with your situation. It seems to me like they pull up static information, while the cart is dynamic.

 

The cart's persistence depends on the session id ... which itself persists either oscommerce's links and buttons being embedded with the session id or via cookies.

 

Cookies are problematic if you have a shared certificate and/or your clients turn cookies off in the browser.

 

What I have done for my non-osc pages is to copy catalog/index.php to catalog/mypage.php and then clear out all the undesired content (e.g. everything between <body> and </body>)

 

if you want to conserve the cart only, then see what is in includes/column_right.php

that relates to the cart info box and include that in your page mypage.php

 

I made a post a few days ago that explains how to create the links correctly ...

 

http://www.oscommerce.com/forums/index.php?sho...30entry679430

Link to comment
Share on other sites

Thanks I see, so the problem is to do with the sessions and the linking back to the orignal page without loosing the sessions.

 

So I tried this:

 

<a href="<?php echo tep_href_link("http://www.profilehealthservices.com/physio_products/index.php", '', 'NONSSL'); ?>">
   <img src="includes/languages/english/images/buttons/button_continue_shopping.gif" border="0"></a>

 

but this makes the link come out like:

http://www.profilehealthservices.com/catal...ducts/index.php

 

How can this be fixed?

 

Thanks Again

Link to comment
Share on other sites

OK I got the link to work by doing the following:

 

<a href="<?php echo tep_href_link("../physio_products/index.php", '', 'NONSSL'); ?>">
   <img src="includes/languages/english/images/buttons/button_continue_shopping.gif" border="0"></a>

 

however this is still emptying the carts contents , anyone else able to give me any suggestions to get this working?

 

Would the above link now be keeping the session or is it still killing it for some reason?

 

I thought the session would be saved within the browser unless you closed it, not by leaving the os folder?

Link to comment
Share on other sites

Does the page in which you have placed the tep function get the session id posted (GET) to it?

 

that is, the calling page must pass the session id to your new page and then the new page has to assign the session ID to OSC's session variable.

 

It should if you have included/required all the oscommerce modules that go above the content ... e.g. includes/application_top.php includes/header.php etc.

 

try you can see if the calling page passes it to your new page by printing (echo) out the session ...

 

Include the following TEMPORARILY in the middle of your new page ...

 

<?php echo 'the session I have is:' . $HTTP_GET_VARS['osCsid'] ?>

 

should not be blank.

 

(warning for those new to (cgi) programming .... this is just php ...oscommerce has its own functions for form input; and they should be used if you are going to do any serious modifications down the road ... not sure about php, but in Perl ... you should untaint variables before you do anything with them and thus avoid hack exploits ... this code is not by itself dangerous, however.)

 

>>> I thought the session would be saved within the browser unless you closed it, not by leaving the os folder?

 

As for this question ... I have read that if you cookie setting are set up properly in your osc config file, then the session would be conserved. [i apparenently don't have them set up right.] Even if so, you'd have to assure that the osc code in your new page was present to read the cookie.

 

Those who advocate just sessions, say that you should not depend on cookies ... Some people have them disabled in their browsers. Also I think from reading other people's posts and my own experience that if you have a shared certificate, cookies will not work well because there will be two sets of cookies ... one pointing to your regular url and one to your ssl url.

Link to comment
Share on other sites

OK I got the link to work by doing the following:

 

<a href="<?php echo tep_href_link("../physio_products/index.php", '', 'NONSSL'); ?>">
? ?<img src="includes/languages/english/images/buttons/button_continue_shopping.gif" border="0"></a>

 

however this is still emptying the carts contents , anyone else able to give me any suggestions to get this working?

 

Would the above link now be keeping the session or is it still killing it for some reason?

 

I thought the session would be saved within the browser unless you closed it, not by leaving the os folder?

 

 

Just something to mention.... I'm on a MAC and I use Safari alot. I noticed that the browser caches pages alot. So for instance, if I had an error while editing a PHP file on the site, then fixed it and hit refresh I would now have the proper page.....but lets say I navigate around a few pages, and then start hitting the back button, I get the cached error page. I was freaking out forever trying to figure this out.....turns out its just the browser. maybe this is the problem? maybe it really didn't remove from the cart.

Link to comment
Share on other sites

Hmm,

 

This has been good for me because it is causing me to question more about how cookies work for OSC. I haven't figured cookies out yet ... but I think I do have a handle on sessions.

 

How are you getting to shopping cart?

 

a. are you just putting this in the url input for your browser:

 

http://yoursite.com/catalog/shopping_cart.php

 

b. or are you first going to an OSC page where you see the session id in the url and THEN clicking around to the shopping cart?

 

 

if a. then the session is not being passed to the shopping cart.

 

 

if b. it worked for me but not the first time. when I put the code just below the HTML <body ... > tag it worked. I think the first time I may have placed it within an if-then block that wasn't run because the conditions were not met ...

 

<?php echo 'the session I have is:' . $HTTP_GET_VARS['osCsid'] ?>

 

As for th browser ?? back clicking should generate a certain amount of post "errrors" but not sure about caching ... see what happens on a different browser ... the goal is to get it to work on all browsers but seeing how it goes on different browsers will help you figure out the problem.

Link to comment
Share on other sites

Here's a thought. I am actually skipping the index page of the cart totally, maybe this is the problem. Does the index page set the session when you first click onto it?

 

What I am currently doing is starting with the products page (outside of OS with contribution) adding a product to the cart and going straight to the cart page within OS, then returning to the products page...

 

Maybe this is my problem? So if it is, is there some code on the index page that I need to put onto my products page (outside of OS) so set the session in the first place.

 

Currently no session is ever displayed within the address bar...

Link to comment
Share on other sites

Another thing I have found:

 

The Products Page outside of OS with contrib

 

Then

 

The OS index page

 

 

OK both of the above pages have products set up on them, the first has the add to cart buttons and the second page has the new products box.

 

Anyway what I am getting at is, mouse over one of the products within the new products box and you will see the session is getting passed, however it isn't from my page...

 

It has to be this session thing, just working out how is the problem...

 

Cheers

Link to comment
Share on other sites

Another thing I have found:

 

The Products Page outside of OS with contrib

 

Then

 

The OS index page

OK both of the above pages have products set up on them, the first has the add to cart buttons and the second page has the new products box.

 

Anyway what I am getting at is, mouse over one of the products within the new products box and you will see the session is getting passed, however it isn't from my page...

 

It has to be this session thing, just working out how is the problem...

 

Cheers

 

It's all working for me. When I go to the products page outside of OS, I still have a cart.

 

if I am on the products page outside of OS, does it show up in the Who's Online toolbar?

Link to comment
Share on other sites

It's all working for me.  When I go to the products page outside of OS, I still have a cart.

 

if I am on the products page outside of OS, does it show up in the Who's Online toolbar?

 

Yeah the cart is there alright however if you add a product to the cart, then press continue shopping it takes you back to the original page and the cart is empty again

Link to comment
Share on other sites

Yeah the cart is there alright however if you add a product to the cart, then press continue shopping it takes you back to the original page and the cart is empty again

 

Not so with me. Works fine. Added to cart, clicked continue shopping, product still in cart. Left page to check ebay real fast, came back.....cart still full :)

 

Again, I'm on a MAC using Safari 2.0 I hear that Safari/Netscape/Firefox are somewhat forgiving in certain matters.

 

anyways I have a products page within subdirectories of my cart. They are just regular PHP pages using the External Sessions contrib to at least pass the osCID to the pages. But what I need, is for those pages to keep their directory structure but also show up in the who's online tool. Right now the products/productname/index.php page is showing up as the referrer, but I need to see who is coming into THAT page, rather from that page into the shopping cart. Know what I mean? it's somewhat confusing.

Link to comment
Share on other sites

  • 2 weeks later...

I ran into something similar and cannot figure out what happens see this topic

 

in brief:

I want to be able to move from the shop to the studio (cms system) site and backwithout loosing the sid

 

so when you you look at the links on top right (the exitdoor) to move from shop to studio and back these links are really hardcoded like

 

<a href="http://funjumping.de/contenido/cms">zum Studio</a>  <a href="http://funjumping.de/contenido/cms"><img border="0" src="../shop/images/exit.jpg"></a>

 

on both sides studio and shop and as said I did not modify anything to pass the osCsid yet the cart remains full, good, but I would like tounderstand it as well and now if it's only for me lie this

 

test it here and let me now if your session stays alive as well whilest skipping

 

that confuses me the whole night already (damn morning hs broken and no forthcoming on this arggggghhhhh)

 

I do not use cookies and store session to db

 

dahui

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...