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


PHP Product\CollectionFactory类代码示例

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


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

示例1: execute

 /**
  * Enable requested attribute for products, if no products are using it
  *
  * Date attributes is supported for attribute_from values only.
  *
  * @param  array $data Key => Value pairs of attribute_code and count
  * @return void
  */
 public function execute($data)
 {
     $visibility = $this->catalogProductVisibility->getVisibleInCatalogIds();
     $attributes = $this->attributeCollectionFactory->create()->addFieldToFilter('attribute_code', ['in' => array_keys($data)]);
     foreach ($attributes as $attribute) {
         $collection = $this->productCollectionFactory->create()->setPageSize(1)->setCurPage(1);
         switch ($attribute->getFrontendInput()) {
             case 'boolean':
                 $value = 1;
                 $collection->addAttributeToFilter($attribute, 1);
                 break;
             case 'date':
                 $value = $this->localeDate->date()->format('Y-m-d H:i:s');
                 $collection->addAttributeToFilter($attribute, [['date' => true, 'to' => $value]]);
                 break;
         }
         if ($collection->getSize()) {
             // customer already has some products with specified attribute
             continue;
         }
         foreach ($this->getStoreIds() as $storeId) {
             $visibleProducts = $this->productCollectionFactory->create()->setStoreId($storeId)->setVisibility($visibility)->addStoreFilter($storeId)->setPageSize($data[$attribute->getAttributeCode()])->setCurPage(1);
             if (!$visibleProducts->getSize()) {
                 continue;
             }
             foreach ($visibleProducts as $product) {
                 $product->addAttributeUpdate($attribute->getAttributeCode(), (int) in_array(0, $this->getStoreIds()), 0);
                 $product->setStoreId($storeId)->setData($attribute->getAttributeCode(), $value)->save();
             }
         }
     }
 }
开发者ID:swissup,项目名称:core,代码行数:40,代码来源:Products.php

示例2: __construct

 /**
  * Construct
  *
  * @param string $name
  * @param string $primaryFieldName
  * @param string $requestFieldName
  * @param CollectionFactory $collectionFactory
  * @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
  * @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
  * @param array $meta
  * @param array $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, array $addFieldStrategies = [], array $addFilterStrategies = [], array $meta = [], array $data = [])
 {
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
     $this->collection = $collectionFactory->create();
     $this->addFieldStrategies = $addFieldStrategies;
     $this->addFilterStrategies = $addFilterStrategies;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:ProductDataProvider.php

示例3: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         return;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         return;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:33,代码来源:ImagesResizeCommand.php

示例4: __construct

 /**
  * @param SampleDataContext $sampleDataContext
  * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
  * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
  */
 public function __construct(SampleDataContext $sampleDataContext, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Framework\App\Config\Storage\WriterInterface $configWriter)
 {
     $this->fixtureManager = $sampleDataContext->getFixtureManager();
     $this->csvReader = $sampleDataContext->getCsvReader();
     $this->productCollection = $productCollectionFactory->create()->addAttributeToSelect('sku');
     $this->configWriter = $configWriter;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:Msrp.php

示例5: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:ImagesResizeCommand.php

示例6: setUp

 protected function setUp()
 {
     $this->productCollection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $this->productCollectionFactory = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->productCollectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection);
     $this->attributeSetFinder = (new ObjectManager($this))->getObject(AttributeSetFinder::class, ['productCollectionFactory' => $this->productCollectionFactory]);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:7,代码来源:AttributeSetFinderTest.php

示例7: __construct

 /**
  * @param \Magento\Catalog\Model\Category\TreeFactory $categoryTreeFactory
  * @param \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryResourceTreeFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
  */
 public function __construct(\Magento\Catalog\Model\Category\TreeFactory $categoryTreeFactory, \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryResourceTreeFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory)
 {
     $this->categoryTree = $categoryTreeFactory->create(['categoryTree' => $categoryResourceTreeFactory->create(), 'categoryCollection' => $categoryCollectionFactory->create()]);
     $this->eavConfig = $eavConfig;
     $this->attributeCollectionFactory = $attributeCollectionFactory;
     $this->attrOptionCollectionFactory = $attrOptionCollectionFactory;
     $this->productCollection = $productCollectionFactory->create();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:Converter.php

示例8: findAttributeSetIdsByProductIds

 /**
  * {@inheritdoc}
  */
 public function findAttributeSetIdsByProductIds(array $productIds)
 {
     /** @var $collection Collection */
     $collection = $this->productCollectionFactory->create();
     $select = $collection->getSelect()->reset(Select::COLUMNS)->columns(ProductInterface::ATTRIBUTE_SET_ID)->where('entity_id IN (?)', $productIds)->group(ProductInterface::ATTRIBUTE_SET_ID);
     $result = $collection->getConnection()->fetchCol($select);
     return $result;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:AttributeSetFinder.php

示例9: setUp

 /**
  * @return void
  */
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['toArray', 'isLoaded', 'addAttributeToFilter', 'load', 'getSize', 'addFilterByRequiredOptions', 'addStoreFilter'])->getMock();
     $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($this->collectionMock);
     $this->dataHelperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->setMethods(['getAllowedSelectionTypes'])->getMock();
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:12,代码来源:BundleDataProviderTest.php

示例10: getFeaturedProduct

 /**
  * get featured product collection
  */
 public function getFeaturedProduct()
 {
     $limit = $this->getProductLimit();
     $collection = $this->_productCollectionFactory->create();
     $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $collection->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setPageSize($limit)->addAttributeToSelect('*');
     $collection->addAttributeToFilter('et_featured', '1');
     return $collection;
 }
开发者ID:emizentech,项目名称:magento2-featured-products,代码行数:12,代码来源:Featuredproduct.php

示例11: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock);
     $this->poolMock = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock();
     $this->modifierMockOne = $this->getMockBuilder(ModifierInterface::class)->setMethods(['getData', 'getMeta'])->getMockForAbstractClass();
     $this->model = $this->objectManager->getObject(ProductDataProvider::class, ['name' => 'testName', 'primaryFieldName' => 'testPrimaryFieldName', 'requestFieldName' => 'testRequestFieldName', 'collectionFactory' => $this->collectionFactoryMock, 'pool' => $this->poolMock]);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:ProductDataProviderTest.php

示例12: setUp

 protected function setUp()
 {
     $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->collectionMock = $this->getMockBuilder(AbstractCollection::class)->disableOriginalConstructor()->setMethods(['load', 'getSelect', 'getTable', 'getIterator', 'isLoaded', 'toArray', 'getSize'])->getMockForAbstractClass();
     $this->dbSelectMock = $this->getMockBuilder(DbSelect::class)->disableOriginalConstructor()->getMock();
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->dataProvider = $this->objectManagerHelper->getObject(ProductCustomOptionsDataProvider::class, ['collectionFactory' => $this->collectionFactoryMock, 'request' => $this->requestMock]);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:10,代码来源:ProductCustomOptionsDataProviderTest.php

示例13: _getProductCollection

 /**
  * @return Collection
  */
 protected function _getProductCollection()
 {
     if ($this->_productCollection === null) {
         /** @var Collection $collection */
         $collection = $this->_productCollectionFactory->create();
         $this->_catalogLayer->prepareProductCollection($collection);
         $collection->addAttributeToFilter('promotion', 1)->addStoreFilter();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Promotion.php

示例14: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->getMockForAbstractClass();
     $this->productLinkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass();
     $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->productRepositoryMock->expects($this->any())->method('getById')->willReturn($this->productMock);
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:12,代码来源:AbstractDataProviderTest.php

示例15: getCollection

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function getCollection(\Magento\Catalog\Model\Category $category)
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
     $collection = $this->collectionFactory->create();
     $collection->addCategoryFilter($category);
     return $collection;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:ItemCollectionProvider.php


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