Example #1
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param bool $isStrictProcessMode
  * @param \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection
  * @param int[] $options
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $optionsCollection, $options)
 {
     if (!$product->getSkipCheckRequiredOption() && $isStrictProcessMode) {
         foreach ($optionsCollection->getItems() as $option) {
             if ($option->getRequired() && !isset($options[$option->getId()])) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Please select all required options.'));
             }
         }
     }
 }
Example #2
0
 /**
  * Check if product can be bought
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function checkProductBuyState($product)
 {
     if (!$product->getSkipCheckRequiredOption() && $product->getHasOptions()) {
         $options = $product->getProductOptionsCollection();
         foreach ($options as $option) {
             if ($option->getIsRequire()) {
                 $customOption = $product->getCustomOption(self::OPTION_PREFIX . $option->getId());
                 if (!$customOption || strlen($customOption->getValue()) == 0) {
                     $product->setSkipCheckRequiredOption(true);
                     throw new \Magento\Framework\Exception\LocalizedException(__('The product has required options.'));
                 }
             }
         }
     }
     return $this;
 }