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


PHP CollectionFactory::create方法代码示例

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


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

示例1: execute

 /**
  * Update product(s) status action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $productIds = $collection->getAllIds();
     $storeId = (int) $this->getRequest()->getParam('store', 0);
     $attributeSetId = (int) $this->getRequest()->getParam('changeattributeset');
     try {
         foreach ($collection->getItems() as $product) {
             //echo get_class($product->getTypeInstance());die();
             if ($this->validateConfigurable($product, $attributeSetId, $storeId) == false) {
                 $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
                 return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
                 break;
             }
             $product->setAttributeSetId($attributeSetId)->setStoreId($storeId);
         }
         $collection->save();
         //$product->getTypeInstance();
         $this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds)));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_getSession()->addException($e, __('Something went wrong while updating the product(s) atrribute set.'));
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
 }
开发者ID:salelsol,项目名称:magento2-extension-change-attribute-set,代码行数:33,代码来源:MassChangeattributeset.php

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

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

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

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

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

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

示例8: _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

示例9: executeInternal

 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $this->attributeHelper->setProductIds($collection->getAllIds());
     if (!$this->_validateProducts()) {
         return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
     }
     $resultPage = $this->resultPageFactory->create();
     $resultPage->getConfig()->getTitle()->prepend(__('Update Attributes'));
     return $resultPage;
 }
开发者ID:nblair,项目名称:magescotch,代码行数:14,代码来源:Edit.php

示例10: execute

 /**
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $productDeleted = 0;
     foreach ($collection->getItems() as $product) {
         $product->delete();
         $productDeleted++;
     }
     $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $productDeleted));
     return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:MassDelete.php

示例11: getProducts

 /**
  * {@inheritdoc}
  */
 public function getProducts(ProductInterface $product)
 {
     if (!isset($this->products[$product->getId()])) {
         if ($this->requestSafety->isSafeMethod()) {
             $productIds = $this->resource->getConnection()->fetchCol('(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')');
             $this->products[$product->getId()] = $this->collectionFactory->create()->addAttributeToSelect(['price', 'special_price'])->addIdFilter($productIds);
         } else {
             $this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
         }
     }
     return $this->products[$product->getId()];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:ConfigurableOptionsProvider.php

示例12: _getProductCollection

 /**
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 protected function _getProductCollection()
 {
     if ($this->_productCollection === null) {
         /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
         $collection = $this->_productCollectionFactory->create();
         $this->_catalogLayer->prepareProductCollection($collection);
         $collection->getSelect()->order('rand()');
         $collection->addStoreFilter();
         $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
         $collection->setPage(1, $numProducts);
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:Random.php

示例13: getCount

 /**
  * {@inheritdoc}
  */
 public function getCount($status = null)
 {
     $products = $this->productsFactory->create();
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $products */
     switch ($status) {
         case Status::STATUS_ENABLED:
             $products->addAttributeToFilter('status', Status::STATUS_ENABLED);
             break;
         case Status::STATUS_DISABLED:
             $products->addAttributeToFilter('status', Status::STATUS_DISABLED);
             break;
     }
     return $products->getSize();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:ProductManagement.php

示例14: _prepareCollection

 /**
  * Premare block data
  * @return $this
  */
 protected function _prepareCollection()
 {
     $post = $this->_coreRegistry->registry('current_blog_post');
     $this->_itemCollection = $this->_productCollectionFactory->create()->addAttributeToSelect('required_options')->addStoreFilter()->addAttributeToFilter('entity_id', array('in' => $post->getRelatedProductIds() ?: array(0)));
     if ($this->_moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->setPageSize((int) $this->_scopeConfig->getValue('mfblog/post_view/related_products/number_of_products', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
开发者ID:samitrimal,项目名称:Blog-Extension-for-Magento-2,代码行数:19,代码来源:RelatedProducts.php

示例15: getProductCollection

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param int $storeId
  * @return $this
  */
 public function getProductCollection(\Magento\Catalog\Model\Category $category, $storeId)
 {
     /** @var $layer \Magento\Catalog\Model\Layer */
     $layer = $this->catalogLayer->setStore($storeId);
     $collection = $category->getResourceCollection();
     $collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
     /** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $productCollection = $this->collectionFactory->create();
     $currentCategory = $layer->setCurrentCategory($category);
     $layer->prepareProductCollection($productCollection);
     $productCollection->addCountToCategories($collection);
     $category->getProductCollection()->setStoreId($storeId);
     $products = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
     return $products;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Category.php


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