예제 #1
0
파일: Product.php 프로젝트: aiesh/magento2
 /**
  * Prepare multiselect attribute value
  *
  * @param mixed $value
  * @param \Magento\Framework\Object $object
  * @return mixed
  */
 protected function _prepareMultiselectValue($value, $object)
 {
     $attribute = $object->getResource()->getAttribute($this->getAttribute());
     if ($attribute && $attribute->getFrontendInput() == 'multiselect') {
         $value = strlen($value) ? explode(',', $value) : array();
     }
     return $value;
 }
예제 #2
0
 /**
  * Validate product attribute value for condition
  *
  * @param \Magento\Framework\Object $object
  * @return bool
  */
 public function validate(\Magento\Framework\Object $object)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getAvailableInCategories());
     } elseif (!isset($this->_entityAttributeValues[$object->getId()])) {
         if (!$object->getResource()) {
             return false;
         }
         $attr = $object->getResource()->getAttribute($attrCode);
         if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
             $this->setValue(strtotime($this->getValue()));
             $value = strtotime($object->getData($attrCode));
             return $this->validateAttribute($value);
         }
         if ($attr && $attr->getFrontendInput() == 'multiselect') {
             $value = $object->getData($attrCode);
             $value = strlen($value) ? explode(',', $value) : array();
             return $this->validateAttribute($value);
         }
         return parent::validate($object);
     } else {
         $result = false;
         // any valid value will set it to TRUE
         // remember old attribute state
         $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
         foreach ($this->_entityAttributeValues[$object->getId()] as $value) {
             $attr = $object->getResource()->getAttribute($attrCode);
             if ($attr && $attr->getBackendType() == 'datetime') {
                 $value = strtotime($value);
             } elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
                 $value = strlen($value) ? explode(',', $value) : array();
             }
             $object->setData($attrCode, $value);
             $result |= parent::validate($object);
             if ($result) {
                 break;
             }
         }
         if (is_null($oldAttrValue)) {
             $object->unsetData($attrCode);
         } else {
             $object->setData($attrCode, $oldAttrValue);
         }
         return (bool) $result;
     }
 }
예제 #3
0
 /**
  * Retrieve small image url
  *
  * @param ModelProduct|\Magento\Framework\Object $product
  * @return string|bool
  */
 public function getSmallImageUrl($product)
 {
     $url = false;
     $attribute = $product->getResource()->getAttribute('small_image');
     if (!$product->getSmallImage()) {
         $url = $this->_assetRepo->getUrl('Magento_Catalog::images/product/placeholder/small_image.jpg');
     } elseif ($attribute) {
         $url = $attribute->getFrontend()->getUrl($product);
     }
     return $url;
 }