コード例 #1
0
ファイル: Bundle.php プロジェクト: Coplex/magento2
 /**
  * @return array
  */
 public function getOptions()
 {
     if (!$this->options) {
         $product = $this->getProduct();
         $typeInstance = $product->getTypeInstance();
         $typeInstance->setStoreFilter($product->getStoreId(), $product);
         $optionCollection = $typeInstance->getOptionsCollection($product);
         $selectionCollection = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
         $this->options = $optionCollection->appendSelections($selectionCollection, false, $this->catalogProduct->getSkipSaleableCheck());
     }
     return $this->options;
 }
コード例 #2
0
ファイル: Type.php プロジェクト: rafaelstz/magento2
 /**
  * Check if product can be bought
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function checkProductBuyState($product)
 {
     parent::checkProductBuyState($product);
     $productOptionIds = $this->getOptionsIds($product);
     $productSelections = $this->getSelectionsCollection($productOptionIds, $product);
     $selectionIds = $product->getCustomOption('bundle_selection_ids');
     $selectionIds = unserialize($selectionIds->getValue());
     $buyRequest = $product->getCustomOption('info_buyRequest');
     $buyRequest = new \Magento\Framework\DataObject(unserialize($buyRequest->getValue()));
     $bundleOption = $buyRequest->getBundleOption();
     if (empty($bundleOption)) {
         throw new \Magento\Framework\Exception\LocalizedException($this->getSpecifyOptionMessage());
     }
     $skipSaleableCheck = $this->_catalogProduct->getSkipSaleableCheck();
     foreach ($selectionIds as $selectionId) {
         /* @var $selection \Magento\Bundle\Model\Selection */
         $selection = $productSelections->getItemById($selectionId);
         if (!$selection || !$selection->isSalable() && !$skipSaleableCheck) {
             throw new \Magento\Framework\Exception\LocalizedException(__('The required options you selected are not available.'));
         }
     }
     $product->getTypeInstance()->setStoreFilter($product->getStoreId(), $product);
     $optionsCollection = $this->getOptionsCollection($product);
     foreach ($optionsCollection->getItems() as $option) {
         if ($option->getRequired() && empty($bundleOption[$option->getId()])) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please select all required options.'));
         }
     }
     return $this;
 }
コード例 #3
0
 /**
  * Get Allowed Products
  *
  * @return array
  */
 public function getAllowProducts()
 {
     if (!$this->hasAllowProducts()) {
         $products = [];
         $skipSaleableCheck = $this->catalogProduct->getSkipSaleableCheck();
         $allProducts = $this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct(), null);
         foreach ($allProducts as $product) {
             if ($product->isSaleable() || $skipSaleableCheck) {
                 $products[] = $product;
             }
         }
         $this->setAllowProducts($products);
     }
     return $this->getData('allow_products');
 }
コード例 #4
0
ファイル: Product.php プロジェクト: nblair/magescotch
 /**
  * Check whether the product type or stock allows to purchase the product
  *
  * @return bool
  */
 public function isAvailable()
 {
     return $this->getTypeInstance()->isSalable($this) || $this->_catalogProduct->getSkipSaleableCheck();
 }