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


PHP Product::hasData方法代码示例

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


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

示例1: getConfigurationsFromProduct

 /**
  * Get configurations from product
  *
  * @param \Magento\Catalog\Model\Product $configurableProduct
  * @return array
  */
 private function getConfigurationsFromProduct(\Magento\Catalog\Model\Product $configurableProduct)
 {
     $result = [];
     $configurableMatrix = $configurableProduct->hasData('configurable-matrix') ? $configurableProduct->getData('configurable-matrix') : [];
     foreach ($configurableMatrix as $item) {
         if (!$item['newProduct']) {
             $result[$item['id']] = $this->mapData($item);
             if (isset($item['qty'])) {
                 $result[$item['id']]['quantity_and_stock_status']['qty'] = $item['qty'];
             }
         }
     }
     return $result;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:UpdateConfigurations.php

示例2: getProductAttributeValue

 /**
  * Retrieve Product Attribute Value
  *
  * @param Product $product
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return \Magento\Framework\Phrase|string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return __('N/A');
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), ['select', 'boolean', 'multiselect'])) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return (string) $value == '' ? __('No') : $value;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:ListCompare.php

示例3: getUsedProducts

 /**
  * Retrieve array of "subproducts"
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @param  array $requiredAttributeIds
  * @return array
  */
 public function getUsedProducts($product, $requiredAttributeIds = null)
 {
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __METHOD__]);
     if (!$product->hasData($this->_usedProducts)) {
         if (is_null($requiredAttributeIds) && is_null($product->getData($this->_configurableAttributes))) {
             // If used products load before attributes, we will load attributes.
             $this->getConfigurableAttributes($product);
             // After attributes loading products loaded too.
             \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
             return $product->getData($this->_usedProducts);
         }
         $usedProducts = [];
         $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('*')->addFilterByRequiredOptions()->setStoreId($product->getStoreId());
         if (is_array($requiredAttributeIds)) {
             foreach ($requiredAttributeIds as $attributeId) {
                 $attribute = $this->getAttributeById($attributeId, $product);
                 if (!is_null($attribute)) {
                     $collection->addAttributeToFilter($attribute->getAttributeCode(), ['notnull' => 1]);
                 }
             }
         }
         foreach ($collection as $item) {
             $usedProducts[] = $item;
         }
         $product->setData($this->_usedProducts, $usedProducts);
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $product->getData($this->_usedProducts);
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:36,代码来源:Configurable.php

示例4: getAmount

    /**
     * Get weee tax amount for product based on website
     *
     * @param   \Magento\Catalog\Model\Product $product
     * @param   mixed $website
     * @return  float
     */
    public function getAmount($product, $website = null)
    {
        if (!$product->hasData($this->cacheProductWeeeAmount)) {
            /** @var \Magento\Store\Model\Store $store */
            if ($website) {
                $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
            } else {
                $store = $product->getStore();
            }

            $amount = 0;
            if ($this->isEnabled($store)) {
                $amount = $this->_weeeTax->getWeeeAmount($product, null, null, $website);
            }

            $product->setData($this->cacheProductWeeeAmount, $amount);
        }
        return $product->getData($this->cacheProductWeeeAmount);
    }
开发者ID:nblair,项目名称:magescotch,代码行数:26,代码来源:Data.php

示例5: getSelectionsCollection

 /**
  * Retrieve bundle selections collection based on used options
  *
  * @param array $optionIds
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Model\ResourceModel\Selection\Collection
  */
 public function getSelectionsCollection($optionIds, $product)
 {
     $keyOptionIds = is_array($optionIds) ? implode('_', $optionIds) : '';
     $key = $this->_keySelectionsCollection . $keyOptionIds;
     if (!$product->hasData($key)) {
         $storeId = $product->getStoreId();
         $selectionsCollection = $this->_bundleCollection->create()->addAttributeToSelect($this->_config->getProductAttributes())->addAttributeToSelect('tax_class_id')->setFlag('require_stock_items', true)->setFlag('product_children', true)->setPositionOrder()->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->addFilterByRequiredOptions()->setOptionIdsFilter($optionIds);
         if (!$this->_catalogData->isPriceGlobal() && $storeId) {
             $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
             $selectionsCollection->joinPrices($websiteId);
         }
         $product->setData($key, $selectionsCollection);
     }
     return $product->getData($key);
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:22,代码来源:Type.php

示例6: hasLinks

 /**
  * Check if product has links
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return boolean
  */
 public function hasLinks($product)
 {
     if ($product->hasData('links_exist')) {
         return $product->getData('links_exist');
     }
     return count($this->getLinks($product)) > 0;
 }
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:Type.php

示例7: getUsedProducts

 /**
  * Retrieve array of "subproducts"
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @param  array $requiredAttributeIds
  * @return array
  */
 public function getUsedProducts($product, $requiredAttributeIds = null)
 {
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __METHOD__]);
     if (!$product->hasData($this->_usedProducts)) {
         $usedProducts = [];
         $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('*')->addAttributeToSelect('media_gallery')->addFilterByRequiredOptions()->setStoreId($product->getStoreId());
         if (is_array($requiredAttributeIds)) {
             foreach ($requiredAttributeIds as $attributeId) {
                 $attribute = $this->getAttributeById($attributeId, $product);
                 if (!is_null($attribute)) {
                     $collection->addAttributeToFilter($attribute->getAttributeCode(), ['notnull' => 1]);
                 }
             }
         }
         foreach ($collection as $item) {
             /** @var \Magento\Catalog\Model\Product $item */
             $item->getResource()->getAttribute('media_gallery')->getBackend()->afterLoad($item);
             $usedProducts[] = $item;
         }
         $product->setData($this->_usedProducts, $usedProducts);
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $product->getData($this->_usedProducts);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:31,代码来源:Configurable.php

示例8: getAssociatedProductIds

 /**
  * Retrieve related products identifiers
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 public function getAssociatedProductIds($product)
 {
     if (!$product->hasData($this->_keyAssociatedProductIds)) {
         $associatedProductIds = [];
         /** @var $item \Magento\Catalog\Model\Product */
         foreach ($this->getAssociatedProducts($product) as $item) {
             $associatedProductIds[] = $item->getId();
         }
         $product->setData($this->_keyAssociatedProductIds, $associatedProductIds);
     }
     return $product->getData($this->_keyAssociatedProductIds);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:Grouped.php

示例9: hasData

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

示例10: isSalable

 /**
  * Check is product available for sale
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return bool
  */
 public function isSalable($product)
 {
     $salable = $product->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
     if ($salable && $product->hasData('is_salable')) {
         $salable = $product->getData('is_salable');
     }
     return (bool) (int) $salable;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:14,代码来源:AbstractType.php

示例11: setStoreToProduct

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param array $rowData
  * @return void
  */
 protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, array $rowData)
 {
     if (!empty($rowData[ImportProduct::COL_STORE]) && ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))) {
         $product->setStoreId($storeId);
     } elseif (!$product->hasData(\Magento\Catalog\Model\Product::STORE_ID)) {
         $product->setStoreId(Store::DEFAULT_STORE_ID);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:AfterImportDataObserver.php

示例12: getUsedProducts

 /**
  * Retrieve array of "subproducts"
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @param  array $requiredAttributeIds
  * @return array
  */
 public function getUsedProducts($product, $requiredAttributeIds = null)
 {
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __METHOD__]);
     if (!$product->hasData($this->_usedProducts)) {
         $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
         $productId = $product->getData($metadata->getLinkField());
         $key = md5(implode('_', [__METHOD__, $productId, $product->getStoreId(), $this->getCustomerSession()->getCustomerGroupId(), json_encode($requiredAttributeIds)]));
         $collection = $this->getUsedProductCollection($product);
         $data = unserialize($this->getCache()->load($key));
         if (!empty($data)) {
             $usedProducts = [];
             foreach ($data as $item) {
                 $productItem = $collection->getNewEmptyItem()->setData($item);
                 $usedProducts[] = $productItem;
             }
         } else {
             $collection->setFlag('has_stock_status_filter', true)->addAttributeToSelect($this->getCatalogConfig()->getProductAttributes())->addFilterByRequiredOptions()->setStoreId($product->getStoreId());
             $requiredAttributes = ['name', 'price', 'weight', 'image', 'thumbnail', 'status', 'media_gallery'];
             foreach ($requiredAttributes as $attributeCode) {
                 $collection->addAttributeToSelect($attributeCode);
             }
             foreach ($this->getUsedProductAttributes($product) as $usedProductAttribute) {
                 $collection->addAttributeToSelect($usedProductAttribute->getAttributeCode());
             }
             $collection->addMediaGalleryData();
             $collection->addTierPriceData();
             $usedProducts = $collection->getItems();
             $this->getCache()->save(serialize(array_map(function ($item) {
                 return $item->getData();
             }, $usedProducts)), $key, array_merge($product->getIdentities(), [\Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Catalog\Model\Product::CACHE_TAG, 'price', self::TYPE_CODE . '_' . $productId]));
         }
         $product->setData($this->_usedProducts, $usedProducts);
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     $usedProducts = $product->getData($this->_usedProducts);
     return $usedProducts;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:44,代码来源:Configurable.php

示例13: getUsedProducts

 /**
  * Retrieve array of "subproducts"
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @param  array $requiredAttributeIds
  * @return array
  */
 public function getUsedProducts($product, $requiredAttributeIds = null)
 {
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __METHOD__]);
     if (!$product->hasData($this->_usedProducts)) {
         $usedProducts = [];
         $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('weight')->addAttributeToSelect('image')->addAttributeToSelect('thumbnail')->addAttributeToSelect('status')->addAttributeToSelect($this->getCatalogConfig()->getProductAttributes())->addFilterByRequiredOptions()->setStoreId($product->getStoreId());
         if (is_array($requiredAttributeIds)) {
             foreach ($requiredAttributeIds as $attributeId) {
                 $attribute = $this->getAttributeById($attributeId, $product);
                 if (!is_null($attribute)) {
                     $collection->addAttributeToFilter($attribute->getAttributeCode(), ['notnull' => 1]);
                 }
             }
         }
         foreach ($collection as $item) {
             /** @var \Magento\Catalog\Model\Product $item */
             $this->getGalleryReadHandler()->execute('', $item);
             $usedProducts[] = $item;
         }
         $product->setData($this->_usedProducts, $usedProducts);
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $product->getData($this->_usedProducts);
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:31,代码来源:Configurable.php

示例14: 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

示例15: 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');
     }
     /**
      * Check "Use Default Value" checkboxes values
      */
     $useDefaults = (array) $this->request->getPost('use_default', []);
     foreach ($useDefaults as $attributeCode => $useDefaultState) {
         if ($useDefaultState) {
             $product->setData($attributeCode, null);
             // UI component sends value even if field is disabled, so 'Use Config Settings' must be reset to false
             if ($product->hasData('use_config_' . $attributeCode)) {
                 $product->setData('use_config_' . $attributeCode, false);
             }
         }
     }
     $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:Doability,项目名称:magento2dev,代码行数:97,代码来源:Helper.php


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