[osCommerce] Added to Cart popup doesn't work, help

Magic SEO URLs for CRE Loaded.
trastomatico
Posts: 3
Joined: Fri Oct 03, 2014 1:53 am

[osCommerce] Added to Cart popup doesn't work, help

Postby trastomatico » Fri Oct 03, 2014 11:20 am

I've modified OC to show a added to cart message when someone buys a product in product listing page keeping the customer in the same page. Keeping the customer in the same page works fine but message is not displayed.

To keep in the product listing page, i've modified includes/modules/product_listing.php

Before:

Code: Select all

<?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '" class="simpleBTN comprar tiny" alt="comprar">';?>


After:

Code: Select all

<?php echo '<a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '" class="simpleBTN comprar tiny" alt="comprar">';?>


To show the message, I've modified incluces/application_top.php and includes/header.php.
1 - In application_top.php, in "buy_now" action switch, I register two session variables: show_message and show_nombre_producto. The first checks if page has to show the message and the second contains the name of the product that has been purchased.

Code: Select all

switch ($HTTP_GET_VARS['action']) {
    [...]
    case 'buy_now' :
        [...]
         tep_session_register('show_message');
         $show_nombre_producto = $producto['products_name'];
         if (!tep_session_is_registered('show_nombre_producto')) tep_session_register('show_nombre_producto');
         
         tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
    break;


2 - In header.php I check if session variable 'show_message' is registered. If true, the message is displayed and 'show_message' variable is unregistered to not show the message in other pages

Code: Select all

 if (tep_session_is_registered('show_message')) {
            echo "<div class='box_conseguido'>El producto $show_nombre_producto se ha a&ntilde;adido a la cesta correctamente.</div>";
            tep_session_unregister('show_message');
          }


The problem is that message is not displayed. If i disable line tep_session_unregister('show_message'); in header.php, message is displayed, so i think page is loading twice: the first shows message and unregister the session variable and the second is that is displayed.

This is apache's log:

Code: Select all

xxx.xx.xx.xxx - - [03/Oct/2014:14:44:33 +0200] "GET /cartuchos-de-tinta-47/cartuchos-brother-196/ HTTP/1.1" 200 9334 - Product listing url
xxx.xx.xx.xxx - - [03/Oct/2014:14:44:37 +0200] "GET //index.php?cPath=196&sort=2a&action=buy_now&products_id=987 HTTP/1.1" 301 580 - url when press buy button
xxx.xx.xx.xxx - - [03/Oct/2014:14:44:37 +0200] "GET /index.php?cPath=196&sort=2a HTTP/1.1" 301 9525 -  url redirect in application_top.php [ tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); ]
xxx.xx.xx.xxx - - [03/Oct/2014:14:44:39 +0200] "GET /cartuchos-de-tinta-47/cartuchos-brother-196/ HTTP/1.1" 200 9361 - url displayed


I think in third step shows the message and unregister the session variable and is redirected to url of fourth step, but i'm not sure of this and i don't know how to solve it. Please note that it works perfectly in a development environment without Inveo SEO plugin. Only fails in production with SEO plugin.

Please, can anyone help me?

Thank you.

inveo
Inveo Support
Posts: 1285
Joined: Sat Feb 02, 2008 12:07 pm
Contact:

Re: [osCommerce] Added to Cart popup doesn't work, help

Postby inveo » Fri Oct 03, 2014 11:25 am

Please edit includes/classes/message_stack.php file:


Find:

Code: Select all

tep_session_unregister('messageToStack');


Replace:

Code: Select all

$_POST['SomeArrayItem'] = true;
tep_session_unregister('messageToStack');


and let me know how it works.

trastomatico
Posts: 3
Joined: Fri Oct 03, 2014 1:53 am

Re: [osCommerce] Added to Cart popup doesn't work, help

Postby trastomatico » Mon Oct 06, 2014 9:39 am

Thank you for your reply

I tried without success:

$_POST['SomeArrayItem'] = true;

$_POST['show_message'] = true;

$_POST['show_nombre_producto'] = true;

Any other idea? Thank you

inveo
Inveo Support
Posts: 1285
Joined: Sat Feb 02, 2008 12:07 pm
Contact:

Re: [osCommerce] Added to Cart popup doesn't work, help

Postby inveo » Mon Oct 06, 2014 9:58 am

Never mind. That fix was for ZenCart (which shares a lot of code with osCommerce).

Please open-up includes/application_top.php file:

Find:

Code: Select all

include(DIR_WS_INCLUDES . 'magic_seo_urls.php');


Replace with:

Code: Select all

if (tep_session_is_registered('messageToStack')) $_POST['SomeArrayItem'] = true;
include(DIR_WS_INCLUDES . 'magic_seo_urls.php');


It should do the trick.

trastomatico
Posts: 3
Joined: Fri Oct 03, 2014 1:53 am

Re: [osCommerce] Added to Cart popup doesn't work, help

Postby trastomatico » Mon Oct 06, 2014 10:56 am

Works like a charm :D

Thank you for your support