本文整理汇总了PHP中Magento\Catalog\Model\ResourceModel\Product\CollectionFactory类的典型用法代码示例。如果您正苦于以下问题:PHP CollectionFactory类的具体用法?PHP CollectionFactory怎么用?PHP CollectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CollectionFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: _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
示例16: _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
示例17: getRelatedProducts
/**
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
public function getRelatedProducts()
{
$ids = $this->getRelatedProductIds();
$ids[] = 0;
$collection = $this->productCollectionFactory->create()->addAttributeToSelect('*')->addFieldToFilter('entity_id', $ids);
return $collection;
}
开发者ID:mirasvit,项目名称:module-blog,代码行数:10,代码来源:Post.php
示例18: _prepareCollection
/**
* Prepare collection
*
* @return Extended
*/
protected function _prepareCollection()
{
$post = $this->getPost();
$collection = $this->_productCollectionFactory->create()->addAttributeToSelect('*')->joinField('websites', 'catalog_product_website', 'website_id', 'product_id=entity_id', null, 'left');
$this->setCollection($collection);
return parent::_prepareCollection();
}
开发者ID:samitrimal,项目名称:Blog-Extension-for-Magento-2,代码行数:12,代码来源:RelatedProducts.php
示例19: 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
示例20: 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
注:本文中的Magento\Catalog\Model\ResourceModel\Product\CollectionFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论