Exemplo n.º 1
0
 /**
  * Migrates the products 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 copyProducts(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
 {
     foreach ($basket->getProducts() as $pos => $product) {
         if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE) {
             continue;
         }
         try {
             $attrIds = array();
             foreach ($product->getAttributes() as $attrItem) {
                 $attrIds[$attrItem->getType()][] = $attrItem->getAttributeId();
             }
             $this->addProduct($product->getProductId(), $product->getQuantity(), array(), $this->getValue($attrIds, 'variant', array()), $this->getValue($attrIds, 'config', array()), $this->getValue($attrIds, 'hidden', array()), $this->getValue($attrIds, 'custom', array()), $product->getWarehouseCode());
             $basket->deleteProduct($pos);
         } catch (\Exception $e) {
             $code = $product->getProductCode();
             $logger = $this->getContext()->getLogger();
             $str = 'Error migrating product 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['product'][$pos] = $e->getMessage();
         }
     }
     return $errors;
 }