Jump to content

Random good at empty basket


Recommended Posts

/modules/blockcart/blockcart.php

After:

       $smarty->assign(array(
           'products'=> $params['cart']->getProducts(true),
           'customizedDatas' => Product::getAllCustomizedDatas(intval($params['cart']->id)),
           'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
           'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
           'discounts' => $params['cart']->getDiscounts(),
           'nb_total_products' =>$params['cart']->nbProducts(),
           'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal(true, 5), $currency),
           'show_wrapping' => floatval($params['cart']->getOrderTotal(true, 6)) > 0 ? true : false,
           'wrapping_cost' => Tools::displayPrice($params['cart']->getOrderTotal(true, 6), $currency),
           'product_total' => Tools::displayPrice($params['cart']->getOrderTotal(true, 4), $currency),
           'total' => Tools::displayPrice($params['cart']->getOrderTotal(), $currency),
           'id_carrier' => $params['cart']->id_carrier,
           'ajax_allowed' => intval(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false
       ));



After it add:

       $totalProducts = $params['cart']->nbProducts();
       if (null == $totalProducts) {
           $smarty->assign('randomProduct' ,Db::getInstance()->GetRow('SELECT `id_product`, `name` FROM `' . _DB_PREFIX_ . 'product_lang` ORDER BY RAND()'));
       }



/modules/blockcart/blockcart.tpl

          {if $cart_qties > 0}
              here goes your template if cart not empty
          {else}
              You may be interested in «{$randomProduct.name}».
          {/if}



I think the way I did it is wrong (mixing logic with business logic - we must follow MVC pattern). There must be method getRandom() at classes/Cart.php - but when I id there - how can I call it?

global $cart;
var_dump($cart); 


showing not this class :(

Link to comment
Share on other sites

×
×
  • Create New...