* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Shop'); /** * Event_Handler_Shop * * An empty event handler * * @version 0.1.1 * @package WB * @subpackage base * @deprecated in favour of ValueAce */ class WBEvent_Handler_Shop_Cart extends WBEvent_Handler_Shop { /** * handler config * * Parameters: * - loadcart: this parameter holds the id-fields name to load cart data * * @var array */ protected $config = array( 'loadcart' => '' ); /** * @var WBShop_Cart */ protected $cart; /** * constructor * */ public function __construct() { $params = array(); $params['mode'] = WBShop_Cart::CART_MODE_ADMIN; $this->cart = WBClass::create('WBShop_Cart', $params); // set dummy user $this->cart->setUser('1'); } /** * Load Cart * * Check config -> "loadcart". If not empty, get cart's id from event data where "loadcart" * points to. * * @param WBEvent $e */ protected function loadCart($e) { // no need to load if (empty($this->config['loadcart'])) { return; } $id = $e->get($this->config['loadcart'], ''); if (empty($id)) { $ex = array( 'msg' => 'Loading cart failed - cart id is empty', 'code' => 1, 'class' => __CLASS__ ); throw WBClass::create('WBException_Config', $ex); } $this->cart->load($id, false, true); if ('__new' == $this->cart->getId()) { $ex = array( 'msg' => 'Loading cart failed - cart not found', 'code' => 2, 'class' => __CLASS__ ); throw WBClass::create('WBException_Datasource', $ex); } } /** * Merge Cart's Data With Event * * Add cart data to event data and prefix keys with "cart_" * @param WBEvent $e */ protected function mergeCartData($e) { $cart = $this->cart->get(); foreach ($cart as $k => $v) { $e->set('cart_' . $k, $v); } } }