Example #1
0
 /**
  * Retrieve small image url
  *
  * @param ModelProduct|\Magento\Framework\DataObject $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;
 }
Example #2
0
 /**
  * Check attribute unique value
  *
  * @param AbstractAttribute $attribute
  * @param \Magento\Framework\DataObject $object
  * @return bool
  */
 public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
 {
     $connection = $this->getConnection();
     $select = $connection->select();
     if ($attribute->getBackend()->getType() === 'static') {
         $value = $object->getData($attribute->getAttributeCode());
         $bind = ['value' => trim($value)];
         $select->from($this->getEntityTable(), $this->getEntityIdField())->where($attribute->getAttributeCode() . ' = :value');
     } else {
         $value = $object->getData($attribute->getAttributeCode());
         if ($attribute->getBackend()->getType() == 'datetime') {
             $value = (new \DateTime($value))->format('Y-m-d H:i:s');
         }
         $bind = ['attribute_id' => $attribute->getId(), 'value' => trim($value)];
         $select->from($attribute->getBackend()->getTable(), $object->getResource()->getLinkField())->where('attribute_id = :attribute_id')->where('value = :value');
     }
     if ($this->getEntityTable() == \Magento\Eav\Model\Entity::DEFAULT_ENTITY_TABLE) {
         $bind['entity_type_id'] = $this->getTypeId();
         $select->where('entity_type_id = :entity_type_id');
     }
     $data = $connection->fetchCol($select, $bind);
     if ($object->getId()) {
         if (isset($data[0])) {
             return $data[0] == $object->getId();
         }
         return true;
     }
     return !count($data);
 }