当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getAttributes方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getAttributes方法的具体用法?PHP Product::getAttributes怎么用?PHP Product::getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getAttributes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetAttributes

 public function testGetAttributes()
 {
     // fixture required
     $this->_model->load(1);
     $attributes = $this->_model->getAttributes();
     $this->assertArrayHasKey('name', $attributes);
     $this->assertArrayHasKey('sku', $attributes);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attributes['sku']);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:9,代码来源:ProductGettersTest.php

示例2: getProductAttribute

 /**
  * Return Product attribute by attribute's ID
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $attributeId
  * @return null|\Magento\Catalog\Model\Entity\Attribute Product's attribute
  */
 public function getProductAttribute(\Magento\Catalog\Model\Product $product, $attributeId)
 {
     if (!isset($this->_productAttributes[$product->getId()])) {
         $attributes = $product->getAttributes();
         foreach ($attributes as $attribute) {
             $this->_productAttributes[$product->getId()][$attribute->getAttributeId()] = $attribute;
         }
     }
     return isset($this->_productAttributes[$product->getId()][$attributeId]) ? $this->_productAttributes[$product->getId()][$attributeId] : null;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Product.php

示例3: testGetAttributes

 public function testGetAttributes()
 {
     $productType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->setMethods(['getEditableAttributes'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->productTypeInstanceMock->expects($this->any())->method('factory')->will($this->returnValue($productType));
     $attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['__wakeup', 'isInGroup'])->disableOriginalConstructor()->getMockForAbstractClass();
     $attribute->expects($this->any())->method('isInGroup')->will($this->returnValue(true));
     $productType->expects($this->any())->method('getEditableAttributes')->will($this->returnValue([$attribute]));
     $expect = [$attribute];
     $this->assertEquals($expect, $this->model->getAttributes(5));
     $this->assertEquals($expect, $this->model->getAttributes());
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:11,代码来源:ProductTest.php

示例4: populateBuilderWithAttributes

 /**
  * Loads the values from a product model
  *
  * @param \Magento\Catalog\Model\Product $productModel
  * @return void
  */
 protected function populateBuilderWithAttributes(\Magento\Catalog\Model\Product $productModel)
 {
     $attributes = array();
     foreach ($productModel->getAttributes() as $attribute) {
         $attrCode = $attribute->getAttributeCode();
         $value = $productModel->getDataUsingMethod($attrCode) ?: $productModel->getData($attrCode);
         if (null !== $value) {
             if ($attrCode != 'entity_id') {
                 $attributes[$attrCode] = $value;
             }
         }
     }
     $attributes[ProductDataObject::STORE_ID] = $productModel->getStoreId();
     $this->productBuilder->populateWithArray($attributes);
     return;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:22,代码来源:Converter.php

示例5: initializeFromData

 /**
  * Initialize product from data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $productData
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function initializeFromData(\Magento\Catalog\Model\Product $product, array $productData)
 {
     unset($productData['custom_attributes']);
     unset($productData['extension_attributes']);
     if ($productData) {
         $stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
         $productData['stock_data'] = $this->stockFilter->filter($stockData);
     }
     $productData = $this->normalize($productData);
     if (!empty($productData['is_downloadable'])) {
         $productData['product_has_weight'] = 0;
     }
     foreach (['category_ids', 'website_ids'] as $field) {
         if (!isset($productData[$field])) {
             $productData[$field] = [];
         }
     }
     foreach ($productData['website_ids'] as $websiteId => $checkboxValue) {
         if (!$checkboxValue) {
             unset($productData['website_ids'][$websiteId]);
         }
     }
     $wasLockedMedia = false;
     if ($product->isLockedAttribute('media')) {
         $product->unlockAttribute('media');
         $wasLockedMedia = true;
     }
     $dateFieldFilters = [];
     $attributes = $product->getAttributes();
     foreach ($attributes as $attrKey => $attribute) {
         if ($attribute->getBackend()->getType() == 'datetime') {
             if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
                 $dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
             }
         }
     }
     $inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
     $productData = $inputFilter->getUnescaped();
     if (isset($productData['options'])) {
         $productOptions = $productData['options'];
         unset($productData['options']);
     } else {
         $productOptions = [];
     }
     $product->addData($productData);
     if ($wasLockedMedia) {
         $product->lockAttribute('media');
     }
     if ($this->storeManager->hasSingleStore() && empty($product->getWebsiteIds())) {
         $product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
     }
     /**
      * Check "Use Default Value" checkboxes values
      */
     $useDefaults = (array) $this->request->getPost('use_default', []);
     foreach ($useDefaults as $attributeCode => $useDefaultState) {
         if ($useDefaultState) {
             $product->setData($attributeCode, null);
         }
     }
     $product = $this->setProductLinks($product);
     /**
      * Initialize product options
      */
     if ($productOptions && !$product->getOptionsReadonly()) {
         // mark custom options that should to fall back to default value
         $options = $this->mergeProductOptions($productOptions, $this->request->getPost('options_use_default'));
         $customOptions = [];
         foreach ($options as $customOptionData) {
             if (empty($customOptionData['is_delete'])) {
                 if (isset($customOptionData['values'])) {
                     $customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
                         return empty($valueData['is_delete']);
                     });
                 }
                 $customOption = $this->getCustomOptionFactory()->create(['data' => $customOptionData]);
                 $customOption->setProductSku($product->getSku());
                 $customOption->setOptionId(null);
                 $customOptions[] = $customOption;
             }
         }
         $product->setOptions($customOptions);
     }
     $product->setCanSaveCustomOptions(!empty($productData['affect_product_custom_options']) && !$product->getOptionsReadonly());
     return $product;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:96,代码来源:Helper.php

示例6: getRequiredDataFromProduct

 /**
  * @param Product $product
  * @return array
  */
 protected function getRequiredDataFromProduct(Product $product)
 {
     $parentProductData = [];
     foreach ($product->getAttributes() as $attribute) {
         if ($attribute->getIsUserDefined() && $attribute->getIsRequired()) {
             $parentProductData[$attribute->getAttributeCode()] = $product->getData($attribute->getAttributeCode());
         }
     }
     return $parentProductData;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:14,代码来源:Plugin.php

示例7: initialize

 /**
  * Initialize product before saving
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function initialize(\Magento\Catalog\Model\Product $product)
 {
     $productData = $this->request->getPost('product');
     unset($productData['custom_attributes']);
     unset($productData['extension_attributes']);
     if ($productData) {
         $stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
         $productData['stock_data'] = $this->stockFilter->filter($stockData);
     }
     foreach (['category_ids', 'website_ids'] as $field) {
         if (!isset($productData[$field])) {
             $productData[$field] = [];
         }
     }
     $wasLockedMedia = false;
     if ($product->isLockedAttribute('media')) {
         $product->unlockAttribute('media');
         $wasLockedMedia = true;
     }
     $dateFieldFilters = [];
     $attributes = $product->getAttributes();
     foreach ($attributes as $attrKey => $attribute) {
         if ($attribute->getBackend()->getType() == 'datetime') {
             if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
                 $dateFieldFilters[$attrKey] = $this->dateFilter;
             }
         }
     }
     $inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
     $productData = $inputFilter->getUnescaped();
     $product->addData($productData);
     if ($wasLockedMedia) {
         $product->lockAttribute('media');
     }
     if ($this->storeManager->hasSingleStore()) {
         $product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
     }
     /**
      * Check "Use Default Value" checkboxes values
      */
     $useDefaults = $this->request->getPost('use_default');
     if ($useDefaults) {
         foreach ($useDefaults as $attributeCode) {
             $product->setData($attributeCode, false);
         }
     }
     $links = $this->request->getPost('links');
     $links = is_array($links) ? $links : [];
     $linkTypes = ['related', 'upsell', 'crosssell'];
     foreach ($linkTypes as $type) {
         if (isset($links[$type])) {
             $links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]);
         }
     }
     $product = $this->productLinks->initializeLinks($product, $links);
     $productLinks = $product->getProductLinks();
     $linkTypes = ['related' => $product->getRelatedReadonly(), 'upsell' => $product->getUpsellReadonly(), 'crosssell' => $product->getCrosssellReadonly()];
     foreach ($linkTypes as $linkType => $readonly) {
         if (isset($links[$linkType]) && !$readonly) {
             foreach ($links[$linkType] as $linkId => $linkData) {
                 $linkProduct = $this->productRepository->getById($linkId);
                 $link = $this->productLinkFactory->create();
                 $link->setSku($product->getSku())->setLinkedProductSku($linkProduct->getSku())->setLinkType($linkType)->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0);
                 $productLinks[] = $link;
             }
         }
     }
     $product->setProductLinks($productLinks);
     /**
      * Initialize product options
      */
     if (isset($productData['options']) && !$product->getOptionsReadonly()) {
         // mark custom options that should to fall back to default value
         $options = $this->mergeProductOptions($productData['options'], $this->request->getPost('options_use_default'));
         $customOptions = [];
         foreach ($options as $customOptionData) {
             if (!(bool) $customOptionData['is_delete']) {
                 $customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
                 $customOption->setProductSku($product->getSku());
                 $customOption->setOptionId(null);
                 $customOptions[] = $customOption;
             }
         }
         $product->setOptions($customOptions);
     }
     $product->setCanSaveCustomOptions((bool) $this->request->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
     return $product;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:97,代码来源:Helper.php

示例8: getAttributes

 /**
  * {@inheritdoc}
  */
 public function getAttributes($groupId = null, $skipSuper = false)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAttributes');
     if (!$pluginInfo) {
         return parent::getAttributes($groupId, $skipSuper);
     } else {
         return $this->___callPlugins('getAttributes', func_get_args(), $pluginInfo);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Interceptor.php

示例9: buildTags

 /**
  * @param Product $product
  * @return array
  */
 protected function buildTags(Product $product)
 {
     $tags = [];
     foreach ($product->getAttributes() as $attr) {
         if ($attr->getIsVisibleOnFront() && $product->hasData($attr->getAttributeCode())) {
             $label = $attr->getStoreLabel();
             $value = $attr->getFrontend()->getValue($product);
             if (is_string($label) && strlen($label) && is_string($value) && strlen($value)) {
                 $tags[] = "{$label}: {$value}";
             }
         }
     }
     if (!$product->canConfigure()) {
         $tags[] = \NostoProduct::PRODUCT_ADD_TO_CART;
     }
     return $tags;
 }
开发者ID:Nosto,项目名称:nosto-magento2,代码行数:21,代码来源:Builder.php


注:本文中的Magento\Catalog\Model\Product::getAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。