Ejemplo n.º 1
0
 /**
  * Receives a notification from a publisher object
  *
  * @param \Aimeos\MW\Observer\Publisher\Iface $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 \Aimeos\MShop\Plugin\Provider\Exception if an error occurs
  * @return bool true if subsequent plugins should be processed
  */
 public function update(\Aimeos\MW\Observer\Publisher\Iface $order, $action, $value = null)
 {
     if (!$order instanceof \Aimeos\MShop\Order\Item\Base\Iface) {
         $msg = $this->getContext()->getI18n()->dt('mshop', 'Object is not of required type "%1$s"');
         throw new \Aimeos\MShop\Plugin\Exception(sprintf($msg, '\\Aimeos\\MShop\\Order\\Item\\Base\\Iface'));
     }
     $context = $this->getContext();
     $services = $order->getServices();
     $addresses = $order->getAddresses();
     if (($userid = $context->getUserId()) !== null && (bool) $this->getConfigValue('autofill.useorder', false) === true && (empty($addresses) || empty($services))) {
         $orderManager = \Aimeos\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->setAddressDefault($order);
     $this->setServicesDefault($order);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Receives a notification from a publisher object
  *
  * @param \Aimeos\MW\Observer\Publisher\Iface $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 \Aimeos\MShop\Plugin\Provider\Exception if checks fail
  * @return bool true if checks succeed
  */
 public function update(\Aimeos\MW\Observer\Publisher\Iface $order, $action, $value = null)
 {
     if (!$order instanceof \Aimeos\MShop\Order\Item\Base\Iface) {
         $msg = $this->getContext()->getI18n()->dt('mshop', 'Object is not of required type "%1$s"');
         throw new \Aimeos\MShop\Plugin\Exception(sprintf($msg, '\\Aimeos\\MShop\\Order\\Item\\Base\\Iface'));
     }
     if ($value & \Aimeos\MShop\Order\Item\Base\Base::PARTS_ADDRESS) {
         $problems = array();
         $availableAddresses = $order->getAddresses();
         foreach ($this->getItemBase()->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);
             $msg = $this->getContext()->getI18n()->dt('mshop', 'Checks for available addresses in basket failed');
             throw new \Aimeos\MShop\Plugin\Provider\Exception($msg, -1, null, $code);
         }
     }
     return true;
 }