/** * Saves the product property 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) { $manager = 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; }
/** * Saves the product stock 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) { $manager = 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; }
/** * 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; }
/** * 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; }
/** * Copys all data from a given product item. * * @param MShop_Product_Item_Interface $product Product item to copy from */ public function copyFrom(MShop_Product_Item_Interface $product) { $this->setName($product->getName()); $this->setType($product->getType()); $this->setSupplierCode($product->getSupplierCode()); $this->setProductCode($product->getCode()); $this->setProductId($product->getId()); $items = $product->getRefItems('media', 'default', 'default'); if (($item = reset($items)) !== false) { $this->setMediaUrl($item->getUrl()); } $this->setModified(); }
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()); }
/** * 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; }
/** * Create new product item object initialized with given parameters. * * @param MShop_Product_Item_Interface $item Product item object * @return array Associative list of key/value pairs suitable for product item constructor */ protected function _createArray(MShop_Product_Item_Interface $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()); }
/** * Edits the changed product to the basket if it's in stock. * * @param MShop_Order_Item_Base_Product_Interface $product Old order product from basket * @param MShop_Product_Item_Interface $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 Controller_Frontend_Basket_Exception If there's not enough stock available */ private function _editProductInStock(MShop_Order_Item_Base_Product_Interface $product, MShop_Product_Item_Interface $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->_basket->deleteProduct($position); if ($stocklevel === null || $stocklevel > 0) { $this->_basket->addProduct($product, $position); $this->_domainManager->setSession($this->_basket); } if ($stocklevel !== null && $stocklevel < $quantity) { $msg = sprintf('There are not enough products "%1$s" in stock', $productItem->getName()); throw new Controller_Frontend_Basket_Exception($msg); } }
/** * 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 = $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 = MShop_Factory::createManager($this->_getContext(), 'catalog/list'); $listManager->deleteItems($delete); return $listItems; }
protected function _delete(MShop_Product_Item_Interface $product) { $manager = MShop_Product_Manager_Factory::createManager($this->_context); $manager->deleteItem($product->getId()); }