예제 #1
0
 /**
  * Adds the "additional" section to the XML object
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $base Order base object
  * @param \DOMDocument $dom DOM document object with contains the XML structure
  * @param \DOMElement $orderitem DOM element which will be the parent of the new child
  * @throws DOMException If an error occures
  */
 protected function buildXMLAdditional(\Aimeos\MShop\Order\Item\Base\Iface $base, \DOMDocument $dom, \DOMElement $orderitem)
 {
     $additional = $dom->createElement('additional');
     $this->appendChildCDATA('comment', '', $dom, $additional);
     $couponItem = $dom->createElement('discount');
     foreach ($base->getCoupons() as $code => $products) {
         $this->appendChildCDATA('code', $code, $dom, $couponItem);
     }
     $additional->appendChild($couponItem);
     $orderitem->appendChild($additional);
 }
예제 #2
0
 /**
  * Saves the coupons of the order to the storage.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing coupon items
  */
 protected function storeCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket)
 {
     $manager = $this->getSubManager('coupon');
     $item = $manager->createItem();
     $item->setBaseId($basket->getId());
     foreach ($basket->getCoupons() as $code => $products) {
         $item->setCode($code);
         if (empty($products)) {
             $item->setId(null);
             $manager->saveItem($item);
             continue;
         }
         foreach ($products as $product) {
             $item->setId(null);
             $item->setProductId($product->getId());
             $manager->saveItem($item);
         }
     }
 }
예제 #3
0
 /**
  * Migrates the coupons from the old basket to the current one.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
  * @param array $errors Associative list of previous errors
  * @param string $localeKey Unique identifier of the site, language and currency
  * @return array Associative list of errors occured
  */
 protected function copyCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
 {
     foreach ($basket->getCoupons() as $code => $list) {
         try {
             $this->addCoupon($code);
             $basket->deleteCoupon($code, true);
         } catch (\Exception $e) {
             $logger = $this->getContext()->getLogger();
             $str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s';
             $logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
             $errors['coupon'][$code] = $e->getMessage();
         }
     }
     return $errors;
 }