Ejemplo n.º 1
0
 /**
  * Validate option type fields
  *
  * @param Option $option
  * @return bool
  */
 protected function validateOptionValue(Option $option)
 {
     $values = $option->getData('values');
     if (!is_array($values) || $this->isEmpty($values)) {
         return false;
     }
     //forbid removal of last value for option
     if ($this->checkAllValuesRemoved($values)) {
         return false;
     }
     foreach ($option->getData('values') as $value) {
         $type = isset($value['price_type']) ? $value['price_type'] : '';
         $price = isset($value['price']) ? $value['price'] : 0;
         $title = isset($value['title']) ? $value['title'] : '';
         if (!$this->isInRange($type, $this->priceTypes) || $this->isNegative($price) || $this->isEmpty($title)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Validate option type fields
  *
  * @param Option $option
  * @return bool
  */
 protected function validateOptionValue(Option $option)
 {
     $values = $option->getData('values');
     if (!is_array($values) || $this->isEmpty($values)) {
         return false;
     }
     //forbid removal of last value for option
     if ($this->checkAllValuesRemoved($values)) {
         return false;
     }
     $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
     if ($option->getProduct()) {
         $storeId = $option->getProduct()->getStoreId();
     }
     foreach ($option->getData('values') as $value) {
         $type = isset($value['price_type']) ? $value['price_type'] : null;
         $price = isset($value['price']) ? $value['price'] : null;
         $title = isset($value['title']) ? $value['title'] : null;
         if (!$this->isValidOptionPrice($type, $price, $storeId) || !$this->isValidOptionTitle($title, $storeId)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Retrieve option data
  *
  * @param \Magento\Catalog\Model\Product\Option $option
  * @return array
  */
 protected function getOptionData(\Magento\Catalog\Model\Product\Option $option)
 {
     $result = [];
     foreach (array_keys($this->_assertOptions) as $assertKey) {
         $result[$assertKey] = $option->getData($assertKey);
     }
     return $result;
 }