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


PHP Collection::fetchItem方法代码示例

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


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

示例1: prepareData

 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', ['in' => $productIds])->addAttributeToFilter('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]);
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = [];
             $variations = [];
             $variationsPrices = [];
             $variationsLabels = [];
             foreach ($productAttributeOption as $optValues) {
                 $variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
                 $priceType = $optValues['pricing_is_percent'] ? 'percent' : 'fixed';
                 $variationsPrices[] = 'name=' . $optValues['attribute_code'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'value=' . $optValues['option_title'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price=' . $optValues['pricing_value'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price_type=' . $priceType;
                 if (!empty($optValues['super_attribute_label'])) {
                     $variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
                 }
             }
             foreach ($variations as $sku => $values) {
                 $variations[$sku] = 'sku=' . $sku . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
             }
             $variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
             $variationsPrices = array_unique($variationsPrices);
             $variationsPrices = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variationsPrices);
             $variationsLabels = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
             $this->configurableData[$product->getId()] = ['configurable_variations' => $variations, 'configurable_variation_prices' => $variationsPrices, 'configurable_variation_labels' => $variationsLabels];
         }
     }
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:36,代码来源:RowCustomizer.php

示例2: prepareData

 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToFilter('type_id', array('eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE));
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = array();
             foreach ($productAttributeOption as $optionValues) {
                 $priceType = $optionValues['pricing_is_percent'] ? '%' : '';
                 $this->configurableData[$product->getId()][] = array('_super_products_sku' => $optionValues['sku'], '_super_attribute_code' => $optionValues['attribute_code'], '_super_attribute_option' => $optionValues['option_title'], '_super_attribute_price_corr' => $optionValues['pricing_value'] . $priceType);
             }
         }
     }
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:21,代码来源:RowCustomizer.php


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