/** * 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); } } }
/** * 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(); }
/** * Returns the product variants of a selection product that match the given attributes. * * @param MShop_Product_Item_Interface $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(MShop_Product_Item_Interface $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 = MShop_Factory::createManager($this->_getContext(), 'product'); $search = $productManager->createSearch(true); $expr = array($search->compare('==', 'product.id', $subProductIds), $search->getConditions()); if (count($variantAttributeIds) > 0) { $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); }