-
-
Save kstasik/f8883daecbf863df4c55a45a8f67d52a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _assignProducts() | |
{ | |
Varien_Profiler::start('QUOTE:'.__METHOD__); | |
$productIds = array(); | |
foreach ($this as $item) { | |
$productIds[] = (int)$item->getProductId(); | |
} | |
$this->_productIds = array_merge($this->_productIds, $productIds); | |
$productCollection = Mage::getModel('catalog/product')->getCollection() | |
->setStoreId($this->getStoreId()) | |
->addIdFilter($this->_productIds) | |
->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes()) | |
->addOptionsToResult() | |
->addStoreFilter() | |
->addUrlRewrite() | |
->addTierPriceData(); | |
Mage::dispatchEvent('prepare_catalog_product_collection_prices', array( | |
'collection' => $productCollection, | |
'store_id' => $this->getStoreId(), | |
)); | |
Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array( | |
'product_collection' => $productCollection | |
)); | |
$recollectQuote = false; | |
foreach ($this as $item) { | |
$product = $productCollection->getItemById($item->getProductId()); | |
if ($product) { | |
$product->setCustomOptions(array()); | |
$qtyOptions = array(); | |
$optionProductIds = array(); | |
foreach ($item->getOptions() as $option) { | |
/** | |
* Call type-specific logic for product associated with quote item | |
*/ | |
$product->getTypeInstance(true)->assignProductToOption( | |
$productCollection->getItemById($option->getProductId()), | |
$option, | |
$product | |
); | |
if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) { | |
$optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId(); | |
} | |
} | |
if ($optionProductIds) { | |
foreach ($optionProductIds as $optionProductId) { | |
$qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId); | |
if ($qtyOption) { | |
$qtyOptions[$optionProductId] = $qtyOption; | |
} | |
} | |
} | |
$item->setQtyOptions($qtyOptions)->setProduct($product); | |
} else { | |
$item->isDeleted(true); | |
$recollectQuote = true; | |
} | |
$item->checkData(); | |
} | |
if ($recollectQuote && $this->_quote) { | |
$this->_quote->collectTotals(); | |
} | |
Varien_Profiler::stop('QUOTE:'.__METHOD__); | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment