Ubercart basket in popup window. Drupal 6

The customer needed a popup basket on his website.
Googling, we did not find any ready-made solution or at least a description of such a thing under Ubercart.
I had to do it myself from what was already invented.
The uc ajax cart modules were used to add a dynamic basket, colorbox for pop-up windows, uc js cart for dynamic counting of goods, and tpl and css were a bit dopped.

So the first one is uc ajax cart. It has a folder with templates, we edit .tpl a bit to implement the appearance and some functionality.
We also add a hidden div with the contents of the basket and a colorbox link to display this content in a pop-up window.
I have it like this:
<a href="?width=850&height=auto&inline=true#cartOpen"class="colorbox-inline">
В корзине 
<?
    $a = count(uc_cart_get_contents());
    echo $a.' товар'.numberProduct($a, array('','а','ов'));
?>
</a>
    <divclass="price-of-cart">на <strong><?phpprint $total ;?></strong></div>
    <divid="myCart" style="display:none;">
       <divid="cartOpen">
         <h2class="cart_header">Корзина</h2>  
              <?phpprintubercart_popup(); ?>          
       </div>
    </div>

In appearance it looks like this:
total number of goods, total price, declination of the word Product, depending on the number of products
There is still a function for declining goods , goods , goods, there are:
functionnumberProduct($number, $titles){
    $cases = array (2, 0, 1, 1, 1, 2);
    return $titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ];
}


Next, as you saw in the template, there is an output of the contents of the basket
<?phpprint ubercart_popup(); ?>

This is the function that rips out the contents of the basket, you need to write it in template.php
It looks like this:
functionubercart_popup(){
  if (module_exists('uc_cart')) {
    $items = uc_cart_get_contents();   
    if (empty($items)) {
      return theme('uc_empty_cart');
    }   
    $output = '';
    foreach (uc_cart_cart_pane_list($items) as $pane) {
      if ($pane['enabled']) {
        $output .= $pane['body'];
      }
    }    
    return'<div id = "uc_popup">'. $output .'</div>';  
  }
}


In general, the contents are already displayed in the popup, but there are a few points. This does not trigger javascript to update product positions from the uc ajax cart module (you can solve it by slightly correcting the code, but this yourself). For this reason, I disabled the “Ajaxify cart page” feature in the module settings.
Next, install the uc js cart module - it is precisely this that allows you to dynamically calculate the cost.
That's almost it. The rest can be done using css.
One thing remains, when we open the basket and add or reduce the number of positions, nothing changes in the basket block itself when closing the window popup. Here, too, you need to add a piece of javascript code for the update. (We are doing this)
It looks like this to me like this:
ubercart basket in popup window

If one of the readers solved this stuffing more elegantly, correctly and most importantly quickly and even like a thread, please tell me pliz.
Thanks to all!

PS

At the moment, we have a need to write a pop-up basket module. This is what we are doing. The module will be posted for testing on drupal.ru and will be available for both the 6th and 7th branches of Drupal.

Also popular now: