/** * 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) { $ids = array(); $context = $this->_getContext(); $services = $order->getServices(); if (count($order->getProducts()) === 0) { $priceManager = 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 = 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; }
/** * 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_SERVICE) { $problems = array(); $availableServices = $order->getServices(); foreach ($this->_getItem()->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); throw new MShop_Plugin_Provider_Exception(sprintf('Checks for available service items in basket failed'), -1, null, $code); } } return true; }
/** * 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; }
/** * 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) { $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)); } $ids = array(); $context = $this->_getContext(); $services = $order->getServices(); if (count($order->getProducts()) === 0) { $priceManager = 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 = 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; }
/** * 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; }