示例#1
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
  */
 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));
     }
     $notAvailable = array();
     if (self::$_lock === false) {
         self::$_lock = true;
         $couponManager = MShop_Factory::createManager($this->_getContext(), 'coupon');
         foreach ($order->getCoupons() as $code => $products) {
             $search = $couponManager->createSearch(true);
             $expr = array($search->compare('==', 'coupon.code.code', $code), $search->getConditions());
             $search->setConditions($search->combine('&&', $expr));
             $search->setSlice(0, 1);
             $results = $couponManager->searchItems($search);
             if (($couponItem = reset($results)) !== false) {
                 $couponProvider = $couponManager->getProvider($couponItem, $code);
                 $couponProvider->updateCoupon($order);
             } else {
                 $notAvailable[$code] = 'coupon.gone';
             }
         }
         self::$_lock = false;
     }
     if (count($notAvailable) > 0) {
         $codes = array('coupon' => $notAvailable);
         $msg = sprintf('Coupon in basket is not available any more');
         throw new MShop_Plugin_Provider_Exception($msg, -1, null, $codes);
     }
     return true;
 }
示例#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 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;
 }
示例#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 checks fail
  * @return bool true if checks succeed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $context = $this->_getContext();
     $logger = $context->getLogger();
     $logger->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
     if ($context->getConfig()->get('mshop/plugin/provider/order/complete/disable', false)) {
         $logger->log(__METHOD__ . ': Is disabled', MW_Logger_Abstract::DEBUG);
         return true;
     }
     $class = 'MShop_Order_Item_Base_Interface';
     if (!$order instanceof $class) {
         throw new MShop_Plugin_Provider_Exception(sprintf('Object is not of required type "%1$s"', $class));
     }
     if (!($value & MShop_Order_Item_Base_Abstract::PARTS_PRODUCT)) {
         return true;
     }
     $count = 0;
     $sum = MShop_Factory::createManager($context, 'price')->createItem();
     foreach ($order->getProducts() as $product) {
         $sum->addItem($product->getPrice(), $product->getQuantity());
         $count += $product->getQuantity();
     }
     $this->_checkLimits($sum, $count);
     return true;
 }
示例#4
0
 /**
  * Subscribes itself to a publisher
  *
  * @param MW_Observer_Publisher_Interface $p Object implementing publisher interface
  */
 public function register(MW_Observer_Publisher_Interface $p)
 {
     $p->addListener($this, 'addProduct.after');
     $p->addListener($this, 'deleteProduct.after');
     $p->addListener($this, 'setService.after');
     $p->addListener($this, 'addCoupon.after');
 }
示例#5
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 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_Order_Exception(sprintf('Object is not of required type "%1$s"', $class));
     }
     if (!($value & MShop_Order_Item_Base_Abstract::PARTS_PRODUCT)) {
         return true;
     }
     $attrIds = $prodCodes = $changedProducts = array();
     $orderProducts = $order->getProducts();
     foreach ($orderProducts as $pos => $item) {
         if ($item->getFlags() & MShop_Order_Item_Base_Product_Abstract::FLAG_IMMUTABLE) {
             unset($orderProducts[$pos]);
         }
         $prodCodes[] = $item->getProductCode();
         foreach ($item->getAttributes() as $ordAttrItem) {
             if (($id = $ordAttrItem->getAttributeId()) != '') {
                 $attrIds[$id] = null;
             }
         }
     }
     $attributes = $this->_getAttributes(array_keys($attrIds));
     $prodMap = $this->_getProducts($prodCodes);
     foreach ($orderProducts as $pos => $orderProduct) {
         $refPrices = array();
         // fetch prices of articles/sub-products
         if (isset($prodMap[$orderProduct->getProductCode()])) {
             $refPrices = $prodMap[$orderProduct->getProductCode()]->getRefItems('price', 'default', 'default');
         }
         $orderPosPrice = $orderProduct->getPrice();
         $price = $this->_getPrice($orderProduct, $refPrices, $attributes, $pos);
         if ($orderPosPrice->compare($price) === false) {
             $orderProduct->setPrice($price);
             $order->deleteProduct($pos);
             $order->addProduct($orderProduct, $pos);
             $changedProducts[$pos] = 'price.changed';
         }
     }
     if (count($changedProducts) > 0) {
         $code = array('product' => $changedProducts);
         $msg = sprintf('Please have a look at the prices of the products in your basket');
         throw new MShop_Plugin_Provider_Exception($msg, -1, null, $code);
     }
     return true;
 }
示例#6
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 checks fail
  * @return bool true if checks succeed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $context = $this->_getContext();
     $logger = $context->getLogger();
     $logger->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
     $class = 'MShop_Order_Item_Base_Interface';
     if (!$order instanceof $class) {
         throw new MShop_Plugin_Order_Exception(sprintf('Object is not of required type "%1$s"', $class));
     }
     if (!($value & MShop_Order_Item_Base_Abstract::PARTS_PRODUCT)) {
         return true;
     }
     $productIds = array();
     foreach ($order->getProducts() as $pr) {
         $productIds[] = $pr->getProductId();
     }
     $productManager = MShop_Factory::createManager($context, 'product');
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.id', $productIds));
     $checkItems = $productManager->searchItems($search);
     $notAvailable = array();
     $now = date('Y-m-d H-i-s');
     foreach ($order->getProducts() as $position => $orderProduct) {
         if (!array_key_exists($orderProduct->getProductId(), $checkItems)) {
             $notAvailable[$position] = 'gone.notexist';
             continue;
         }
         $product = $checkItems[$orderProduct->getProductId()];
         if ($product->getStatus() <= 0) {
             $notAvailable[$position] = 'gone.status';
             continue;
         }
         $start = $product->getDateStart();
         $end = $product->getDateEnd();
         if ($start !== null && $start >= $now || $end !== null && $now > $end) {
             $notAvailable[$position] = 'gone.timeframe';
         }
     }
     if (count($notAvailable) > 0) {
         $code = array('product' => $notAvailable);
         throw new MShop_Plugin_Provider_Exception(sprintf('Products in basket not available'), -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 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;
 }
示例#8
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;
 }
示例#9
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
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $context = $this->_getContext();
     $logger = $context->getLogger();
     $logger->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
     $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));
     }
     $config = $this->_getItem()->getConfig();
     if (!isset($config['threshold'])) {
         return true;
     }
     try {
         $delivery = $order->getService('delivery');
     } catch (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 = MShop_Factory::createManager($context, '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;
 }
示例#10
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 checks fail
  * @return bool true if checks succeed
  */
 public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
 {
     $context = $this->_getContext();
     $context->getLogger()->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
     $class = 'MShop_Order_Item_Base_Interface';
     if (!$order instanceof $class) {
         throw new MShop_Plugin_Order_Exception(sprintf('Object is not of required type "%1$s"', $class));
     }
     if (!($value & MShop_Order_Item_Base_Abstract::PARTS_PRODUCT)) {
         return true;
     }
     $siteConfig = $context->getLocale()->getSite()->getConfig();
     $outOfStock = $productQuantities = $positions = array();
     foreach ($order->getProducts() as $position => $pr) {
         $productQuantities[$pr->getProductId()] = $pr->getQuantity();
         $positions[$pr->getProductId()] = $position;
     }
     $stockManager = MShop_Factory::createManager($context, 'product/stock');
     $search = $stockManager->createSearch();
     $expr = array($search->compare('==', 'product.stock.productid', array_keys($productQuantities)));
     if (isset($siteConfig['repository'])) {
         $expr[] = $search->compare('==', 'product.stock.warehouse.code', $siteConfig['repository']);
     }
     $search->setConditions($search->combine('&&', $expr));
     $checkItems = $stockManager->searchItems($search);
     foreach ($checkItems as $checkItem) {
         $stocklevel = $checkItem->getStocklevel();
         if ($stocklevel !== null && $stocklevel < $productQuantities[$checkItem->getProductId()]) {
             $outOfStock[$positions[$checkItem->getProductId()]] = 'stock.notenough';
         }
     }
     if (count($outOfStock) > 0) {
         $code = array('product' => $outOfStock);
         throw new MShop_Plugin_Provider_Exception(sprintf('Products out of stock'), -1, null, $code);
     }
     return true;
 }
示例#11
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 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 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));
     }
     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;
 }
示例#13
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;
 }
示例#14
0
 /**
  * Subscribes itself to a publisher
  *
  * @param MW_Observer_Publisher_Interface $p Object implementing publisher interface
  */
 public function register(MW_Observer_Publisher_Interface $p)
 {
     $p->addListener($this, 'addProduct.before');
 }