Pregunta

I've been struggling for 2 hours now, searching all over for a solution to this.

I'm working with a Zen-Cart installation, and I've decided to thrown on some dynamic banners. Basically I use jQuery.get() to load a URL from banner1.php - banner1.php has an array of a few urls (which are product pages), and it echoes out a random url from the array.

Once the random URL is loaded by jQuery, I then use the jQuery.load() function to load the image of the product, the price of the product and the name of the product.

All this works absolutely fine, but the problem is that it seems the load() function is interfering with my Zen-Cart "redirect" function. Say if you are viewing a product, let's call it "Product A" - and you decide to log in from that page by clicking the "Login" button - what happens is that you are taken to the Login page, you enter your login details, and hit "Submit". The standard outcome is that if you are logged in successfully, you are taken back to the "Product A" page. But with my little dynamic jQuery banner concoction, instead of redirecting back the "Product A", it loads one of the pages that the jQuery.load() used to generate the random banner. I have 3 banners, each dynamically loading a random url, but here is an example of Banner 1:

<script type="text/javascript">


$.get("banner1.php", function(getbannerlink1) {

$( document ).ready(function() {


$("#banner1").load(getbannerlink1+ " #globalproductimage"); 

$('#banner1name').load(getbannerlink1+ " #productName", function(result) {
var banner1text = $('#banner1name').html();
banner1text = jQuery(banner1text).text();
$("#banner1name").html(banner1text);

});

$('#banner1price').load(getbannerlink1+ " #productPrices", function(result) {
var banner1prices = $('#banner1price').html();
banner1prices = jQuery(banner1prices ).text();
$("#banner1price").html(banner1prices );

});


var bannerlink1 = $("<a>").attr("href", getbannerlink1);
$("#banner1name").wrap(bannerlink1);
$("#banner1price").wrap(bannerlink1);
$("#banner1").wrap(bannerlink1);
});

});
</script>

The thing is I'm not too concerned about the wrongful redirection once a customer logs in, the problem also occurs most disappointingly when the customer once to actually Checkout. For instance, if they were to have products in their shopping basket, click the Checkout button, which then asks them to login, and once they login, instead of continuing with the standard shopping cart function of taking them to the first step of the checkout process, it redirects them to one of the pages that the dynamic banner has loaded. I don't know how to sort this out, I tried some weird things to no avail. For the sake of reference, this might be needed, this is the Zen-Cart function that handles redirection after a login:

if (sizeof($_SESSION['navigation']->snapshot) > 0) {
      //    $back = sizeof($_SESSION['navigation']->path)-2;
      //if (isset($_SESSION['navigation']->path[$back]['page'])) {
      //    if (sizeof($_SESSION['navigation']->path)-2 > 0) {
      $origin_href = zen_href_link($_SESSION['navigation']->snapshot['page'], zen_array_to_string($_SESSION['navigation']->snapshot['get'], array(zen_session_name())), $_SESSION['navigation']->snapshot['mode']);
      //            $origin_href = zen_back_link_only(true);
      $_SESSION['navigation']->clear_snapshot();
      zen_redirect($origin_href);
    } else {
      zen_redirect(zen_href_link(FILENAME_DEFAULT, '', $request_type));
    } 

Please help! Perhaps there is an easier way I should be doing this :/

I noticed that the page it loads is always the last banner that jQuery.load() loaded. Like I mentioned there are 3 banners in total, so if Banner 2's price was the last one to load, that's the URL that's loaded in the redirection.

Edit: banner1.php (this simply generates a random url from an array, but currently for testing purposes I only have one URL in the array):

<?php
$strings = array('http://example.com/index.php?main_page=product_info&cPath=3&products_id=104');
echo $strings[array_rand($strings)];
?>
¿Fue útil?

Solución

It appears that the banner page is setting the snapshot href. I assume you are including some of the Zen cart libraries in your banner urls that are setting the Session navigation snapshot. You maybe able to set something to ignore your url for the snapshot.

Adding the banner code may help solve this issue.

Although I would not recommend it, you could add logic to not redirect to certain pages after login.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top