/** * Add products to items and item options * * @return $this */ protected function _assignProducts() { \Magento\Framework\Profiler::start('QUOTE:' . __METHOD__, array('group' => 'QUOTE', 'method' => __METHOD__)); $productIds = array(); foreach ($this as $item) { $productIds[] = (int) $item->getProductId(); } $this->_productIds = array_merge($this->_productIds, $productIds); $productCollection = $this->_productCollectionFactory->create()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect($this->_quoteConfig->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData(); $this->_eventManager->dispatch('prepare_catalog_product_collection_prices', array('collection' => $productCollection, 'store_id' => $this->getStoreId())); $this->_eventManager->dispatch('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()->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(); } \Magento\Framework\Profiler::stop('QUOTE:' . __METHOD__); return $this; }
public function testGetProductAttributes() { $attributes = array('attribute_one', 'attribute_two'); $this->_attributeConfig->expects($this->once())->method('getAttributeNames')->with('sales_quote_item')->will($this->returnValue($attributes)); $this->assertEquals($attributes, $this->_model->getProductAttributes()); }