當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AbstractAttribute::getAttribute方法代碼示例

本文整理匯總了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:PHP AbstractAttribute::getAttribute方法的具體用法?PHP AbstractAttribute::getAttribute怎麽用?PHP AbstractAttribute::getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Eav\Model\Entity\Attribute\AbstractAttribute的用法示例。


在下文中一共展示了AbstractAttribute::getAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: storeImage

 /**
  * Save image information to DB.
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $images
  * @return void
  */
 protected function storeImage($product, $images)
 {
     $baseImage = '';
     $i = 1;
     $mediaAttribute = $this->eavConfig->getAttribute('catalog_product', 'media_gallery');
     foreach ($images as $image) {
         if (empty($image)) {
             $this->errors[] = $product->getSku();
             continue;
         }
         if (strpos($image, '_main') !== false) {
             $baseImage = $image;
         }
         $id = $this->galleryResource->insertGallery(['attribute_id' => $mediaAttribute->getAttributeId(), 'entity_id' => $product->getId(), 'value' => $image]);
         $this->galleryResource->insertGalleryValueInStore(['value_id' => $id, 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'entity_id' => $product->getId(), 'label' => 'Image', 'position' => $i, 'disables' => 0]);
         $this->galleryResource->bindValueToEntity($id, $product->getId());
         $i++;
     }
     if (empty($baseImage)) {
         $baseImage = $images[0];
     }
     if ($baseImage) {
         $imageAttribute = $product->getResource()->getAttribute('image');
         $smallImageAttribute = $product->getResource()->getAttribute('small_image');
         $thumbnailAttribute = $product->getResource()->getAttribute('thumbnail');
         $adapter = $product->getResource()->getConnection();
         foreach ([$imageAttribute, $smallImageAttribute, $thumbnailAttribute] as $attribute) {
             $table = $imageAttribute->getBackend()->getTable();
             /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter*/
             $data = [$attribute->getBackend()->getEntityIdField() => $product->getId(), 'attribute_id' => $attribute->getId(), 'value' => $baseImage];
             $adapter->insertOnDuplicate($table, $data, ['value']);
         }
     }
 }
開發者ID:koliaGI,項目名稱:magento2,代碼行數:41,代碼來源:Gallery.php

示例2: _isCallableAttributeInstance

 /**
  * Check whether attribute instance (attribute, backend, frontend or source) has method and applicable
  *
  * @param AbstractAttribute|\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend|\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $instance
  * @param string $method
  * @param array $args array of arguments
  * @return boolean
  */
 protected function _isCallableAttributeInstance($instance, $method, $args)
 {
     if ($instance instanceof \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend && ($method == 'beforeSave' || $method == 'afterSave')) {
         $attributeCode = $instance->getAttribute()->getAttributeCode();
         if (isset($args[0]) && $args[0] instanceof \Magento\Framework\DataObject && $args[0]->getData($attributeCode) === false) {
             return false;
         }
     }
     return parent::_isCallableAttributeInstance($instance, $method, $args);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:18,代碼來源:AbstractResource.php


注:本文中的Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。