/**
  * Receives a notification from a publisher object
  *
  * @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
  * @param string $action Name of the action to listen for
  * @param mixed $value Object or value changed in publisher
  * @throws MShop_Plugin_Provider_Exception if checks fail
  * @return bool true if checks succeed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     if ($value & MShop_Order_Item_Base_Abstract::PARTS_ADDRESS) {
         $problems = array();
         $availableAddresses = $order->getAddresses();
         foreach ($this->_getItem()->getConfig() as $type => $value) {
             if ($value == true && !isset($availableAddresses[$type])) {
                 $problems[$type] = 'available.none';
             }
             if ($value !== null && $value !== '' && $value == false && isset($availableAddresses[$type])) {
                 $problems[$type] = 'available.notallowed';
             }
         }
         if (count($problems) > 0) {
             $code = array('address' => $problems);
             throw new MShop_Plugin_Provider_Exception(sprintf('Checks for available addresses in basket failed'), -1, null, $code);
         }
     }
     return true;
 }
Example #2
0
 /**
  * Receives a notification from a publisher object
  *
  * @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
  * @param string $action Name of the action to listen for
  * @param mixed $value Object or value changed in publisher
  * @throws MShop_Plugin_Provider_Exception if an error occurs
  * @return bool true if subsequent plugins should be processed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $context = $this->_getContext();
     $services = $order->getServices();
     $addresses = $order->getAddresses();
     if (($userid = $context->getUserId()) !== null && $this->_getConfigValue('autofill.useorder', true) == true && (empty($addresses) || empty($services))) {
         $orderManager = MShop_Factory::createManager($context, 'order');
         $search = $orderManager->createSearch();
         $search->setConditions($search->compare('==', 'order.base.customerid', $userid));
         $search->setSortations(array($search->sort('-', 'order.ctime')));
         $search->setSlice(0, 1);
         $result = $orderManager->searchItems($search);
         if (($item = reset($result)) !== false) {
             $this->_setAddresses($order, $item);
             $this->_setServices($order, $item);
         }
     }
     $this->_setServicesDefault($order);
     return true;
 }
Example #3
0
 /**
  * Receives a notification from a publisher object
  *
  * @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
  * @param string $action Name of the action to listen for
  * @param mixed $value Object or value changed in publisher
  * @throws MShop_Plugin_Provider_Exception if an error occurs
  * @return bool true if subsequent plugins should be processed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $class = 'MShop_Order_Item_Base_Interface';
     if (!$order instanceof $class) {
         throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
     }
     $context = $this->_getContext();
     $services = $order->getServices();
     $addresses = $order->getAddresses();
     if (($userid = $context->getUserId()) !== null && $this->_getConfigValue('autofill.useorder', true) == true && (empty($addresses) || empty($services))) {
         $orderManager = MShop_Factory::createManager($context, 'order');
         $search = $orderManager->createSearch();
         $search->setConditions($search->compare('==', 'order.base.customerid', $userid));
         $search->setSortations(array($search->sort('-', 'order.ctime')));
         $search->setSlice(0, 1);
         $result = $orderManager->searchItems($search);
         if (($item = reset($result)) !== false) {
             $this->_setAddresses($order, $item);
             $this->_setServices($order, $item);
         }
     }
     $this->_setServicesDefault($order);
     return true;
 }