/** * 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 */ 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')); } $config = $this->getItemBase()->getConfig(); if (!isset($config['threshold'])) { return true; } try { $delivery = $order->getService('delivery'); } catch (\Aimeos\MShop\Order\Exception $oe) { // no delivery item available yet return true; } $this->checkThreshold($order, $delivery->getPrice(), $config['threshold']); 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 */ 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)); } $config = $this->getItemBase()->getConfig(); if (!isset($config['threshold'])) { return true; } try { $delivery = $order->getService('delivery'); } catch (\Aimeos\MShop\Order\Exception $oe) { // no delivery item available yet return true; } $price = $delivery->getPrice(); $currency = $price->getCurrencyId(); if (!isset($config['threshold'][$currency])) { return true; } $sum = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price')->createItem(); foreach ($order->getProducts() as $product) { $sum->addItem($product->getPrice(), $product->getQuantity()); } if ($sum->getValue() + $sum->getRebate() >= $config['threshold'][$currency] && $price->getCosts() > '0.00') { $price->setRebate($price->getCosts()); $price->setCosts('0.00'); } else { if ($sum->getValue() + $sum->getRebate() < $config['threshold'][$currency] && $price->getRebate() > '0.00') { $price->setCosts($price->getRebate()); $price->setRebate('0.00'); } } return true; }