Beispiel #1
0
 /**
  * Saves the attribute related data to the storage
  *
  * @param MShop_Product_Item_Interface $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(MShop_Product_Item_Interface $product, array $data)
 {
     $context = $this->_getContext();
     $manager = MShop_Factory::createManager($context, 'attribute');
     $listManager = MShop_Factory::createManager($context, 'product/list');
     $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.list.type']) || isset($map[$pos]['product.list.type']) && $map[$pos]['product.list.type'] === $listItem->getType())) {
                     $pos++;
                     continue;
                 }
             }
             $listItems[$listId] = null;
             $delete[] = $listId;
             $pos++;
         }
         $listManager->deleteItems($delete);
         foreach ($map as $pos => $list) {
             if ($list['attribute.code'] === '' || $list['attribute.type'] === '' || isset($list['product.list.type']) && $this->_listTypes !== null && !in_array($list['product.list.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.list.type']) ? $list['product.list.type'] : 'default';
                 $list['product.list.typeid'] = $this->_getTypeId('product/list/type', 'attribute', $typecode);
                 $list['product.list.refid'] = $attrItem->getId();
                 $list['product.list.parentid'] = $product->getId();
                 $list['product.list.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;
 }
Beispiel #2
0
 /**
  * Saves the product related data to the storage
  *
  * @param MShop_Product_Item_Interface $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(MShop_Product_Item_Interface $product, array $data)
 {
     $context = $this->_getContext();
     $manager = MShop_Factory::createManager($context, 'media');
     $listManager = MShop_Factory::createManager($context, 'product/list');
     $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 (!isset($list['media.url']) || $list['media.url'] === '' || isset($list['product.list.type']) && $this->_listTypes !== null && !in_array($list['product.list.type'], (array) $this->_listTypes)) {
                 continue;
             }
             $urls = explode($separator, $list['media.url']);
             $type = isset($list['media.type']) ? $list['media.type'] : 'default';
             $typecode = isset($list['product.list.type']) ? $list['product.list.type'] : 'default';
             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.domain'] = 'product';
                 $list['media.url'] = $url;
                 $refItem->fromArray($this->_addItemDefaults($list));
                 $manager->saveItem($refItem);
                 $list['product.list.typeid'] = $this->_getTypeId('product/list/type', 'media', $typecode);
                 $list['product.list.parentid'] = $product->getId();
                 $list['product.list.refid'] = $refItem->getId();
                 $list['product.list.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;
 }
Beispiel #3
0
 /**
  * Saves the product related data to the storage
  *
  * @param MShop_Product_Item_Interface $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(MShop_Product_Item_Interface $product, array $data)
 {
     $listManager = MShop_Factory::createManager($this->_getContext(), 'product/list');
     $manager = 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.list.type']) && $this->_listTypes !== null && !in_array($list['product.list.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.list.type']) ? $list['product.list.type'] : 'default';
             $list['product.list.typeid'] = $this->_getTypeId('product/list/type', 'price', $typecode);
             $list['product.list.parentid'] = $product->getId();
             $list['product.list.refid'] = $refItem->getId();
             $list['product.list.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;
 }
Beispiel #4
0
 protected function _delete(MShop_Product_Item_Interface $product)
 {
     $manager = MShop_Product_Manager_Factory::createManager($this->_context);
     $listManager = $manager->getSubManager('list');
     foreach ($product->getListItems('attribute') as $listItem) {
         $listManager->deleteItem($listItem->getId());
     }
     $manager->deleteItem($product->getId());
 }
Beispiel #5
0
 /**
  * Adds all texts belonging to an product item.
  *
  * @param MW_Container_Content_Interface $contentItem Content item
  * @param MShop_Product_Item_Interface $item product item object
  * @param string $langid Language id
  */
 protected function _addItem(MW_Container_Content_Interface $contentItem, MShop_Product_Item_Interface $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);
         }
     }
 }
Beispiel #6
0
 /**
  * Returns the pool of list items that can be reassigned
  *
  * @param MShop_Product_Item_Interface $product Product item object
  * @param array $map List of associative arrays containing the chunked properties
  * @return array List of list items implementing MShop_Common_Item_List_Interface
  */
 protected function _getListItemPool(MShop_Product_Item_Interface $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 = MShop_Factory::createManager($this->_getContext(), 'product/list');
     $listManager->deleteItems($delete);
     return $listItems;
 }