Exemple #1
0
 /**
  * Copys all data from a given product item.
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item to copy from
  */
 public function copyFrom(\Aimeos\MShop\Product\Item\Iface $product)
 {
     $this->setProductCode($product->getCode());
     $this->setProductId($product->getId());
     $this->setType($product->getType());
     $this->setName($product->getName());
     $items = $product->getRefItems('supplier', 'default', 'default');
     if (($item = reset($items)) !== false) {
         $this->setSupplierCode($item->getCode());
     }
     $items = $product->getRefItems('media', 'default', 'default');
     if (($item = reset($items)) !== false) {
         $this->setMediaUrl($item->getPreview());
     }
     $this->setModified();
     return $this;
 }
 /**
  * Returns the product variants of a selection product that match the given attributes.
  *
  * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item including sub-products
  * @param array $variantAttributeIds IDs for the variant-building attributes
  * @param array $domains Names of the domain items that should be fetched too
  * @return array List of products matching the given attributes
  */
 protected function getProductVariants(\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, array $domains = array('attribute', 'media', 'price', 'text'))
 {
     $subProductIds = array();
     foreach ($productItem->getRefItems('product', 'default', 'default') as $item) {
         $subProductIds[] = $item->getId();
     }
     if (count($subProductIds) === 0) {
         return array();
     }
     $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
     $search = $productManager->createSearch(true);
     $expr = array($search->compare('==', 'product.id', $subProductIds), $search->getConditions());
     if (count($variantAttributeIds) > 0) {
         foreach ($variantAttributeIds as $key => $id) {
             $variantAttributeIds[$key] = (string) $id;
         }
         $listTypeItem = $this->getProductListTypeItem('attribute', 'variant');
         $param = array('attribute', $listTypeItem->getId(), $variantAttributeIds);
         $cmpfunc = $search->createFunction('product.contains', $param);
         $expr[] = $search->compare('==', $cmpfunc, count($variantAttributeIds));
     }
     $search->setConditions($search->combine('&&', $expr));
     return $productManager->searchItems($search, $domains);
 }
Exemple #3
0
 /**
  * Adds all texts belonging to an product item.
  *
  * @param \Aimeos\MW\Container\Content\Iface $contentItem Content item
  * @param \Aimeos\MShop\Product\Item\Iface $item product item object
  * @param string $langid Language id
  */
 protected function addItem(\Aimeos\MW\Container\Content\Iface $contentItem, \Aimeos\MShop\Product\Item\Iface $item, $langid)
 {
     $listTypes = array();
     foreach ($item->getListItems('text') as $listItem) {
         $listTypes[$listItem->getRefId()] = $listItem->getType();
     }
     foreach ($this->getTextTypes('product') as $textTypeItem) {
         $textItems = $item->getRefItems('text', $textTypeItem->getCode());
         if (!empty($textItems)) {
             foreach ($textItems as $textItem) {
                 $listType = isset($listTypes[$textItem->getId()]) ? $listTypes[$textItem->getId()] : '';
                 $items = array($langid, $item->getType(), $item->getCode(), $listType, $textTypeItem->getCode(), '', '');
                 // use language of the text item because it may be null
                 if (($textItem->getLanguageId() == $langid || is_null($textItem->getLanguageId())) && $textItem->getTypeId() == $textTypeItem->getId()) {
                     $items[0] = $textItem->getLanguageId();
                     $items[5] = $textItem->getId();
                     $items[6] = $textItem->getContent();
                 }
                 $contentItem->add($items);
             }
         } else {
             $items = array($langid, $item->getType(), $item->getCode(), 'default', $textTypeItem->getCode(), '', '');
             $contentItem->add($items);
         }
     }
 }
 /**
  * Adds the bundled products to the order product item.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Order product item
  * @param \Aimeos\MShop\Product\Item\Iface $productItem Bundle product item
  * @param array $variantAttributeIds List of product variant attribute IDs
  * @param string $warehouse
  */
 protected function addBundleProducts(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $warehouse)
 {
     $quantity = $orderBaseProductItem->getQuantity();
     $products = $subProductIds = $orderProducts = array();
     $orderProductManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product');
     foreach ($productItem->getRefItems('product', null, 'default') as $item) {
         $subProductIds[] = $item->getId();
     }
     if (count($subProductIds) > 0) {
         $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
         $search = $productManager->createSearch(true);
         $expr = array($search->compare('==', 'product.id', $subProductIds), $search->getConditions());
         $search->setConditions($search->combine('&&', $expr));
         $products = $productManager->searchItems($search, array('attribute', 'media', 'price', 'text'));
     }
     foreach ($products as $product) {
         $prices = $product->getRefItems('price', 'default', 'default');
         $orderProduct = $orderProductManager->createItem();
         $orderProduct->copyFrom($product);
         $orderProduct->setWarehouseCode($warehouse);
         $orderProduct->setPrice($this->calcPrice($orderProduct, $prices, $quantity));
         $orderProducts[] = $orderProduct;
     }
     $orderBaseProductItem->setProducts($orderProducts);
 }