/** * 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; }
/** * 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_SERVICE) { $problems = array(); $availableServices = $order->getServices(); foreach ($this->getItemBase()->getConfig() as $type => $value) { if ($value == true && !isset($availableServices[$type])) { $problems[$type] = 'available.none'; } if ($value !== null && $value !== '' && $value == false && isset($availableServices[$type])) { $problems[$type] = 'available.notallowed'; } } if (count($problems) > 0) { $code = array('service' => $problems); $msg = $this->getContext()->getI18n()->dt('mshop', 'Checks for available service items in basket failed'); throw new \Aimeos\MShop\Plugin\Provider\Exception($msg, -1, null, $code); } } return true; }
/** * 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) { $class = '\\Aimeos\\MShop\\Order\\Item\\Base\\Iface'; if (!$order instanceof $class) { throw new \Aimeos\MShop\Plugin\Exception(sprintf('Object is not of required type "%1$s"', $class)); } $ids = array(); $context = $this->getContext(); $services = $order->getServices(); if (count($order->getProducts()) === 0) { $priceManager = \Aimeos\MShop\Factory::createManager($context, 'price'); foreach ($services as $type => $service) { $service->setPrice($priceManager->createItem()); } return true; } foreach ($services as $type => $service) { $ids[$type] = $service->getServiceId(); } $serviceManager = \Aimeos\MShop\Factory::createManager($context, 'service'); $search = $serviceManager->createSearch(true); $expr = array($search->compare('==', 'service.id', $ids), $search->getConditions()); $search->setConditions($search->combine('&&', $expr)); $result = $serviceManager->searchItems($search, array('price')); foreach ($services as $type => $service) { if (isset($result[$service->getServiceId()])) { $provider = $serviceManager->getProvider($result[$service->getServiceId()]); if ($provider->isAvailable($order)) { $service->setPrice($provider->calcPrice($order)); $order->setService($service, $type); continue; } } $order->deleteService($type); } return true; }