本文整理汇总了PHP中Mage_Catalog_Model_Resource_Product_Collection::getItemByColumnValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Resource_Product_Collection::getItemByColumnValue方法的具体用法?PHP Mage_Catalog_Model_Resource_Product_Collection::getItemByColumnValue怎么用?PHP Mage_Catalog_Model_Resource_Product_Collection::getItemByColumnValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Resource_Product_Collection
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Resource_Product_Collection::getItemByColumnValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _process
/**
* @param Mage_Catalog_Model_Resource_Product_Collection $products
* @return bool
*/
protected function _process($products)
{
$processor = $this->_htmlProcessor;
$helper = $this->_getHelper();
foreach ($products as $product) {
$product->setData('url', $product->getProductUrl());
}
$items = $processor->query($helper->getCssSelector('related_product_link'));
if (count($items) === 0) {
return false;
}
$positions = array();
foreach ($items as $i => $item) {
/** @var $item DOMElement */
$url = $item->getAttribute('href');
$product = $products->getItemByColumnValue('url', $url);
if (!$product) {
continue;
}
if ($helper->isEnabledForProduct($product)) {
$positions[] = $i;
}
}
$processor->replace($helper->getCssSelector('related_product_price'), $this->_getHelper()->prepareReplacement(), $positions);
}
示例2: _linkProducts
/**
* Update product links for the given type of links - up sell, related, cross sell
* @param Mage_Catalog_Model_Product $product Product to add links to
* @param array $linkUpdates Product links data
* @param string $linkType Type of product links to create
* @return array Any links that could not be added
*/
protected function _linkProducts(Mage_Catalog_Model_Product $product, $linkUpdates, $linkType)
{
$opFilter = function ($operation) {
return function ($el) use($operation) {
return strtolower($el['operation_type']) === $operation;
};
};
$skuMap = function ($link) {
return $link['link_to_unique_id'];
};
// get all currently linked products of this link type
$linkedProductsGetter = $this->_linkTypes[$linkType]['linked_products_getter_method'];
$linkedProducts = $product->{$linkedProductsGetter}();
// remove any links that are supposed to be getting deleted
$deleteSkus = array_map($skuMap, array_filter($linkUpdates, $opFilter('delete')));
$linkedProducts = array_filter($linkedProducts, function ($prod) use($deleteSkus) {
return !in_array($prod->getSku(), $deleteSkus);
});
$addSkus = array_map($skuMap, array_filter($linkUpdates, $opFilter('add')));
// Go through the skus to add and look up the product id for each one.
// If any are missing, add the product link for that sku to a list of links that
// cannot be resolved yet.
$missingLinks = array();
$idsToAdd = array();
foreach ($addSkus as $sku) {
$linkProduct = $this->_products->getItemByColumnValue('sku', $sku);
$id = $linkProduct ? $linkProduct->getId() : null;
if ($id) {
$idsToAdd[] = $id;
} else {
$missingLinks[] = $this->_buildProductLinkForSku($sku, $linkType, 'Add');
}
}
// get a list of all products that should be linked
$linkIds = array_filter(array_unique(array_merge(array_map(function ($prod) {
return $prod->getId();
}, $linkedProducts), $idsToAdd)));
$linkData = array();
foreach ($linkIds as $id) {
$linkData[$id] = array('position' => '');
}
// add the updated links to the product
$product->setData($this->_linkTypes[$linkType]['data_attribute'], $linkData);
// return links that were not resolved
return $missingLinks;
}
示例3: addImportErrors
/**
* given a Mage_Catalog_Model_Resource_Product_Collection object and a list of SKUs
* if the SKUs in the list of sku is not in the collection then add error confirmation node
* to feed file about sku was not imported
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
* @param array list of SKUs that were suppose to be imported
* @param string the file the sku was found on
* @param string the event type
* @return self
*/
protected function addImportErrors(Mage_Catalog_Model_Resource_Product_Collection $collection, array $skus, $fileName, $type)
{
foreach ($skus as $sku) {
$product = $collection->getItemByColumnValue('sku', $sku);
if (is_null($product)) {
$this->appendError(self::SKU_NOT_IMPORTED, '', $type, $fileName, $sku);
}
}
return $this;
}