... separate out the code (header and template).Code doing processing in an observer (or header files). Code displaying stuff (HTML / CSS) in the template files.
Sounds like fun! I'd probably do something like the following (untested):I do in fact want an indicator next to each "always free shipping" product [in the shopping cart and checkout].. I might mess around and see if I can make myself a combo platter here..![]()
Create "/includes/classes/observers/freeShippingObserver.php"
Create "/includes/auto_loaders/config.freeShippingObserver.php"Code:<?php class freeShippingObserver extends base { protected $logfile; function __construct() { $this->attach($this, array( 'NOTIFY_HEADER_END_SHOPPING_CART', 'NOTIFY_HEADER_END_CHECKOUT_SHIPPING', 'NOTIFY_HEADER_END_CHECKOUT_PAYMENT', 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION' )); } function update(&$class, $eventID, $paramsArray = array()) { global $cart_includes_free_shipping_product; $cart_includes_free_shipping_product = false; if(array_key_exists('cart', $_SESSION)) { $cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1'); global $products; $n=sizeof($products); if($n > 0) { switch($eventID) { case 'NOTIFY_HEADER_END_SHOPPING_CART': global $productArray; for ($i=0; $i<$n; $i++) { $productArray[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping']; } break; case 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION': global $order; for ($i=0; $i<$n; $i++) { $order->products[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping']; } default: } } } } }
Then in the templates for those four pages one can look use:Code:<?php if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $autoLoadConfig[10][] = array( 'autoType'=>'class', 'loadFile'=>'observers/freeShippingObserver.php' ); $autoLoadConfig[200][] = array( 'autoType'=>'classInstantiate', 'className'=>'freeShippingObserver', 'objectName'=>'freeShippingObserver' );
In the shopping cart template (inside the foreach starting at line 63) one can use:Code:if($cart_includes_free_shipping_product) { // Do something }
In the checkout_confirmation template one can use:Code:if($product['product_is_always_free_shipping'] == '1') { // Do something }
Code:if($order->products[$i]['product_is_always_free_shipping'] == '1') { // Do something }


Code doing processing in an observer (or header files). Code displaying stuff (HTML / CSS) in the template files.
Reply With Quote
