Example #1
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;
 }
 public function testGetProductOptionsCollection()
 {
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Collection', $this->_model->getProductOptionsCollection());
 }
 /**
  * {@inheritdoc}
  */
 public function getProductOptionsCollection()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getProductOptionsCollection');
     if (!$pluginInfo) {
         return parent::getProductOptionsCollection();
     } else {
         return $this->___callPlugins('getProductOptionsCollection', func_get_args(), $pluginInfo);
     }
 }