Exemplo n.º 1
0
 /**
  * Saves the attribute related data to the storage
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items
  * @param array $data List of CSV fields with position as key and data as value
  * @return array List of data which hasn't been imported
  */
 public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
 {
     $context = $this->getContext();
     $manager = \Aimeos\MShop\Factory::createManager($context, 'attribute');
     $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
     $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n");
     $manager->begin();
     try {
         $pos = 0;
         $delete = $attrcodes = array();
         $map = $this->getMappedChunk($data);
         $listItems = $product->getListItems('attribute', $this->listTypes);
         foreach ($listItems as $listId => $listItem) {
             if (isset($map[$pos])) {
                 if (!isset($map[$pos]['attribute.code']) || !isset($map[$pos]['attribute.type'])) {
                     unset($map[$pos]);
                     continue;
                 }
                 $refItem = $listItem->getRefItem();
                 if ($refItem !== null && $map[$pos]['attribute.code'] === $refItem->getCode() && $map[$pos]['attribute.type'] === $refItem->getType() && (!isset($map[$pos]['product.lists.type']) || isset($map[$pos]['product.lists.type']) && $map[$pos]['product.lists.type'] === $listItem->getType())) {
                     $pos++;
                     continue;
                 }
             }
             $listItems[$listId] = null;
             $delete[] = $listId;
             $pos++;
         }
         $listManager->deleteItems($delete);
         foreach ($map as $pos => $list) {
             if (!isset($list['attribute.code']) || $list['attribute.code'] === '' || $list['attribute.type'] === '' || isset($list['product.lists.type']) && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes)) {
                 continue;
             }
             $codes = explode($separator, $list['attribute.code']);
             foreach ($codes as $code) {
                 $attrItem = $this->getAttributeItem($code, $list['attribute.type']);
                 $attrItem->fromArray($list);
                 $attrItem->setCode($code);
                 $manager->saveItem($attrItem);
                 if (($listItem = array_shift($listItems)) === null) {
                     $listItem = $listManager->createItem();
                 }
                 $typecode = isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default';
                 $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode);
                 $list['product.lists.refid'] = $attrItem->getId();
                 $list['product.lists.parentid'] = $product->getId();
                 $list['product.lists.domain'] = 'attribute';
                 $listItem->fromArray($this->addListItemDefaults($list, $pos));
                 $listManager->saveItem($listItem);
             }
         }
         $remaining = $this->getObject()->process($product, $data);
         $manager->commit();
     } catch (\Exception $e) {
         $manager->rollback();
         throw $e;
     }
     return $remaining;
 }
Exemplo n.º 2
0
 /**
  * Saves the product related data to the storage
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items
  * @param array $data List of CSV fields with position as key and data as value
  * @return array List of data which hasn't been imported
  */
 public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
 {
     $context = $this->getContext();
     $manager = \Aimeos\MShop\Factory::createManager($context, 'media');
     $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
     $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n");
     $manager->begin();
     try {
         $map = $this->getMappedChunk($data);
         $listItems = $product->getListItems('media');
         foreach ($map as $pos => $list) {
             if ($this->checkEntry($list) === false) {
                 continue;
             }
             $urls = explode($separator, $list['media.url']);
             $type = $this->getValue($list, 'media.type', 'default');
             $typecode = $this->getValue($list, 'product.lists.type', 'default');
             if (($langid = $this->getValue($list, 'media.languageid', null)) === '') {
                 $langid = null;
             }
             foreach ($urls as $url) {
                 if (($listItem = array_shift($listItems)) !== null) {
                     $refItem = $listItem->getRefItem();
                 } else {
                     $listItem = $listManager->createItem();
                     $refItem = $manager->createItem();
                 }
                 $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type);
                 $list['media.languageid'] = $langid;
                 $list['media.domain'] = 'product';
                 $list['media.url'] = $url;
                 $refItem->fromArray($this->addItemDefaults($list));
                 $manager->saveItem($refItem);
                 $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode);
                 $list['product.lists.parentid'] = $product->getId();
                 $list['product.lists.refid'] = $refItem->getId();
                 $list['product.lists.domain'] = 'media';
                 $listItem->fromArray($this->addListItemDefaults($list, $pos++));
                 $listManager->saveItem($listItem);
             }
         }
         foreach ($listItems as $listItem) {
             $manager->deleteItem($listItem->getRefItem()->getId());
             $listManager->deleteItem($listItem->getId());
         }
         $remaining = $this->getObject()->process($product, $data);
         $manager->commit();
     } catch (\Exception $e) {
         $manager->rollback();
         throw $e;
     }
     return $remaining;
 }
Exemplo n.º 3
0
 /**
  * Saves the product property related data to the storage
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items
  * @param array $data List of CSV fields with position as key and data as value
  * @return array List of data which hasn't been imported
  */
 public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
 {
     $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property');
     $manager->begin();
     try {
         $pos = 0;
         $delete = array();
         $map = $this->getMappedChunk($data);
         $items = $this->getPropertyItems($product->getId());
         foreach ($items as $id => $item) {
             if (isset($map[$pos])) {
                 if (!isset($map[$pos]['product.property.type']) || !isset($map[$pos]['product.property.value'])) {
                     unset($map[$pos]);
                     continue;
                 }
                 if ($map[$pos]['product.property.type'] === $item->getType() && $map[$pos]['product.property.value'] === $item->getValue() && (!isset($map[$pos]['product.property.languageid']) || isset($map[$pos]['product.property.languageid']) && $map[$pos]['product.property.languageid'] === $item->getLanguageId())) {
                     $pos++;
                     continue;
                 }
             }
             $items[$id] = null;
             $delete[] = $id;
             $pos++;
         }
         $manager->deleteItems($delete);
         foreach ($map as $pos => $list) {
             if ($list['product.property.type'] == '' || $list['product.property.value'] == '') {
                 continue;
             }
             $typecode = $list['product.property.type'];
             $list['product.property.typeid'] = $this->getTypeId('product/property/type', 'product/property', $typecode);
             $list['product.property.parentid'] = $product->getId();
             if (($item = array_shift($items)) === null) {
                 $item = $manager->createItem();
             }
             $item->fromArray($list);
             $manager->saveItem($item);
         }
         $remaining = $this->getObject()->process($product, $data);
         $manager->commit();
     } catch (\Exception $e) {
         $manager->rollback();
         throw $e;
     }
     return $remaining;
 }
Exemplo n.º 4
0
 /**
  * Saves the product related data to the storage
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items
  * @param array $data List of CSV fields with position as key and data as value
  * @return array List of data which hasn't been imported
  */
 public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
 {
     $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists');
     $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price');
     $manager->begin();
     try {
         $listItems = $product->getListItems('price');
         $map = $this->getMappedChunk($data);
         foreach ($map as $pos => $list) {
             if (!isset($list['price.value']) || $list['price.value'] === '' || isset($list['product.lists.type']) && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes)) {
                 continue;
             }
             if (($listItem = array_shift($listItems)) !== null) {
                 $refItem = $listItem->getRefItem();
             } else {
                 $listItem = $listManager->createItem();
                 $refItem = $manager->createItem();
             }
             $typecode = isset($list['price.type']) ? $list['price.type'] : 'default';
             $list['price.typeid'] = $this->getTypeId('price/type', 'product', $typecode);
             $list['price.domain'] = 'product';
             $refItem->fromArray($this->addItemDefaults($list));
             $manager->saveItem($refItem);
             $typecode = isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default';
             $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'price', $typecode);
             $list['product.lists.parentid'] = $product->getId();
             $list['product.lists.refid'] = $refItem->getId();
             $list['product.lists.domain'] = 'price';
             $listItem->fromArray($this->addListItemDefaults($list, $pos));
             $listManager->saveItem($listItem);
         }
         foreach ($listItems as $listItem) {
             $manager->deleteItem($listItem->getRefItem()->getId());
             $listManager->deleteItem($listItem->getId());
         }
         $remaining = $this->getObject()->process($product, $data);
         $manager->commit();
     } catch (\Exception $e) {
         $manager->rollback();
         throw $e;
     }
     return $remaining;
 }
Exemplo n.º 5
0
 /**
  * Saves the product stock related data to the storage
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items
  * @param array $data List of CSV fields with position as key and data as value
  * @return array List of data which hasn't been imported
  */
 public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
 {
     $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/stock');
     $manager->begin();
     try {
         $pos = 0;
         $delete = array();
         $map = $this->getMappedChunk($data);
         $items = $this->getStockItems($product->getId());
         foreach ($map as $pos => $list) {
             if (!array_key_exists('product.stock.stocklevel', $list)) {
                 continue;
             }
             $whcode = isset($list['product.stock.warehouse']) ? $list['product.stock.warehouse'] : 'default';
             if (!isset($list['product.stock.warehouseid'])) {
                 $list['product.stock.warehouseid'] = $this->cache->get($whcode);
             }
             if (isset($list['product.stock.dateback']) && $list['product.stock.dateback'] === '') {
                 $list['product.stock.dateback'] = null;
             }
             if ($list['product.stock.stocklevel'] === '') {
                 $list['product.stock.stocklevel'] = null;
             }
             $list['product.stock.productid'] = $product->getId();
             if (($item = array_pop($items)) === null) {
                 $item = $manager->createItem();
             }
             $item->fromArray($list);
             $manager->saveItem($item);
         }
         $manager->deleteItems(array_keys($items));
         $remaining = $this->getObject()->process($product, $data);
         $manager->commit();
     } catch (\Exception $e) {
         $manager->rollback();
         throw $e;
     }
     return $remaining;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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);
         }
     }
 }
Exemplo n.º 8
0
 protected function delete(\Aimeos\MShop\Product\Item\Iface $product)
 {
     $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context);
     $listManager = $manager->getSubManager('lists');
     foreach ($product->getListItems('attribute') as $listItem) {
         $listManager->deleteItem($listItem->getId());
     }
     $manager->deleteItem($product->getId());
 }
Exemplo n.º 9
0
 /**
  * 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);
 }
Exemplo n.º 10
0
 protected function delete(\Aimeos\MShop\Product\Item\Iface $product)
 {
     $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context);
     $manager->deleteItem($product->getId());
 }
Exemplo n.º 11
0
 /**
  * Edits the changed product to the basket if it's in stock.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Old order product from basket
  * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item that belongs to the order product
  * @param integer $quantity New product quantity
  * @param integer $position Position of the old order product in the basket
  * @param array Associative list of options
  * @throws \Aimeos\Controller\Frontend\Basket\Exception If there's not enough stock available
  */
 protected function editProductInStock(\Aimeos\MShop\Order\Item\Base\Product\Iface $product, \Aimeos\MShop\Product\Item\Iface $productItem, $quantity, $position, array $options)
 {
     $stocklevel = null;
     if (!isset($options['stock']) || $options['stock'] != false) {
         $stocklevel = $this->getStockLevel($productItem->getId(), $product->getWarehouseCode());
     }
     $product->setQuantity($stocklevel !== null && $stocklevel > 0 ? min($stocklevel, $quantity) : $quantity);
     $this->get()->deleteProduct($position);
     if ($stocklevel === null || $stocklevel > 0) {
         $this->get()->addProduct($product, $position);
     }
     if ($stocklevel !== null && $stocklevel < $quantity) {
         $msg = sprintf('There are not enough products "%1$s" in stock', $productItem->getName());
         throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
     }
 }
Exemplo n.º 12
0
 /**
  * Create new product item object initialized with given parameters.
  *
  * @param \Aimeos\MShop\Product\Item\Iface $item Product item object
  * @return array Associative list of key/value pairs suitable for product item constructor
  */
 protected function createArray(\Aimeos\MShop\Product\Item\Iface $item)
 {
     return array('id' => $item->getId(), 'typeid' => $item->getTypeId(), 'type' => $item->getType(), 'status' => $item->getStatus(), 'label' => $item->getLabel(), 'start' => $item->getDateStart(), 'end' => $item->getDateEnd(), 'code' => $item->getCode(), 'suppliercode' => $item->getSupplierCode(), 'ctime' => $item->getTimeCreated(), 'mtime' => $item->getTimeModified(), 'editor' => $item->getEditor());
 }
Exemplo n.º 13
0
 /**
  * Returns the pool of list items that can be reassigned
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item object
  * @param array $map List of associative arrays containing the chunked properties
  * @return array List of list items implementing \Aimeos\MShop\Common\Item\Lists\Iface
  */
 protected function getListItemPool(\Aimeos\MShop\Product\Item\Iface $product, array $map)
 {
     $pos = 0;
     $delete = array();
     $listItems = $this->getListItems($product->getId(), $this->listTypes);
     foreach ($listItems as $listId => $listItem) {
         if (isset($map[$pos]) && (!isset($map[$pos]['catalog.code']) || $this->cache->get($map[$pos]['catalog.code']) == $listItem->getParentId())) {
             $pos++;
             continue;
         }
         $listItems[$listId] = null;
         $delete[] = $listId;
         $pos++;
     }
     $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists');
     $listManager->deleteItems($delete);
     return $listItems;
 }
Exemplo n.º 14
0
 /**
  * Returns the pool of list items that can be reassigned
  *
  * @param \Aimeos\MShop\Product\Item\Iface $product Product item object
  * @param array $map List of associative arrays containing the chunked properties
  * @return array List of list items implementing \Aimeos\MShop\Common\Item\Lists\Iface
  */
 protected function getListItemPool(\Aimeos\MShop\Product\Item\Iface $product, array $map)
 {
     $pos = 0;
     $delete = array();
     $listItems = $product->getListItems('product', $this->listTypes);
     foreach ($listItems as $listId => $listItem) {
         $refItem = $listItem->getRefItem();
         if (isset($map[$pos]) && (!isset($map[$pos]['product.code']) || $refItem !== null && $map[$pos]['product.code'] === $refItem->getCode())) {
             $pos++;
             continue;
         }
         $listItems[$listId] = null;
         $delete[] = $listId;
         $pos++;
     }
     $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists');
     $listManager->deleteItems($delete);
     return $listItems;
 }