Ejemplo n.º 1
0
 /**
  * Retrieve bundle selections collection based on ids
  *
  * @param array $selectionIds
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Model\ResourceModel\Selection\Collection
  */
 public function getSelectionsByIds($selectionIds, $product)
 {
     sort($selectionIds);
     $usedSelections = $product->getData($this->_keyUsedSelections);
     $usedSelectionsIds = $product->getData($this->_keyUsedSelectionsIds);
     if (!$usedSelections || $usedSelectionsIds !== $selectionIds) {
         $storeId = $product->getStoreId();
         $usedSelections = $this->_bundleCollection->create()->addAttributeToSelect('*')->setFlag('require_stock_items', true)->setFlag('product_children', true)->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->setPositionOrder()->addFilterByRequiredOptions()->setSelectionIdsFilter($selectionIds);
         if (!$this->_catalogData->isPriceGlobal() && $storeId) {
             $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
             $usedSelections->joinPrices($websiteId);
         }
         $product->setData($this->_keyUsedSelections, $usedSelections);
         $product->setData($this->_keyUsedSelectionsIds, $selectionIds);
     }
     return $usedSelections;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve bundle selections collection based on ids
  *
  * @param array $selectionIds
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Model\ResourceModel\Selection\Collection
  */
 public function getSelectionsByIds($selectionIds, $product)
 {
     sort($selectionIds);
     $usedSelections = $product->getData($this->_keyUsedSelections);
     $usedSelectionsIds = $product->getData($this->_keyUsedSelectionsIds);
     if (!$usedSelections || $usedSelectionsIds !== $selectionIds) {
         $storeId = $product->getStoreId();
         $usedSelections = $this->_bundleCollection->create()->addAttributeToSelect('*')->setFlag('require_stock_items', true)->setFlag('product_children', true)->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->setPositionOrder()->addFilterByRequiredOptions()->setSelectionIdsFilter($selectionIds);
         if (count($usedSelections->getItems()) !== count($selectionIds)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('The options you selected are not available.'));
         }
         if (!$this->_catalogData->isPriceGlobal() && $storeId) {
             $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
             $usedSelections->joinPrices($websiteId);
         }
         $product->setData($this->_keyUsedSelections, $usedSelections);
         $product->setData($this->_keyUsedSelectionsIds, $selectionIds);
     }
     return $usedSelections;
 }