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


PHP Product\Collection类代码示例

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


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

示例1: install

 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     $this->configWriter->save('sales/msrp/enabled', 1);
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             $productId = $this->getProductIdBySku($row['sku']);
             if (!$productId) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $product */
             $product = $this->productCollection->getItemById($productId);
             $product->setMsrpDisplayActualPriceType(Type::TYPE_ON_GESTURE);
             if (!empty($row['msrp'])) {
                 $price = $row['msrp'];
             } else {
                 $price = $product->getPrice() * 1.1;
             }
             $product->setMsrp($price);
             $product->save();
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:36,代码来源:Msrp.php

示例2: testGetCollection

 public function testGetCollection()
 {
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter');
     $this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1);
     $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:7,代码来源:AbstractDataProviderTest.php

示例3: setUp

 /**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:36,代码来源:RowCustomizerTest.php

示例4: addExcludeProductFilter

 /**
  * Make collection not to load products that are in specified quote
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param int $quoteId
  * @return $this
  */
 public function addExcludeProductFilter($collection, $quoteId)
 {
     $connection = $this->getConnection();
     $exclusionSelect = $connection->select()->from($this->getTable('quote_item'), ['product_id'])->where('quote_id = ?', $quoteId);
     $condition = $connection->prepareSqlCondition('e.entity_id', ['nin' => $exclusionSelect]);
     $collection->getSelect()->where($condition);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Cart.php

示例5: collectValidatedAttributes

 /**
  * Collect validated attributes for Product Collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
  * @return $this
  */
 public function collectValidatedAttributes($productCollection)
 {
     $alias = array_keys($productCollection->getSelect()->getPart('from'))[0];
     foreach ($this->getConditions() as $condition) {
         $condition->setData('attribute', $alias . '.' . $condition->getData('attribute'));
         $condition->addToCollection($productCollection);
     }
     return $this;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:15,代码来源:Combine.php

示例6: addFilterByAttributes

 /**
  * {@inheritDoc}
  */
 protected function addFilterByAttributes(ProductCollection $productCollection, array $attributes)
 {
     foreach ($attributes as $code => $option) {
         if (!is_array($option)) {
             $option = [$option];
         }
         $productCollection->addAttributeToFilter($code, ['in' => $option]);
     }
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:12,代码来源:Swatches.php

示例7: tearDown

 /**
  * Execute per test cleanup
  */
 public function tearDown()
 {
     /** @var \Magento\Framework\Registry $registry */
     $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Registry');
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', true);
     $this->productCollection->addFieldToFilter('entity_id', ['in' => [10, 11, 12]])->delete();
     unset($this->productCollection);
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', false);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:14,代码来源:StockItemTest.php

示例8: aroundAddFilter

 /**
  * Replace WHERE-filtering by HAVING-filtering.
  *
  * @param \Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject
  * @param \Closure $proceed
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param $field
  * @param null $condition
  */
 public function aroundAddFilter(\Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject, \Closure $proceed, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, $field, $condition = null)
 {
     /* skip identical conditions () */
     $regKey = print_r($condition, true);
     if (!isset($this->_regCond[$regKey])) {
         $conn = $collection->getConnection();
         $select = $collection->getSelect();
         $equation = $this->_repoModifierProductGFrid->getEquationQty();
         $prepared = $conn->prepareSqlCondition($equation, $condition);
         $select->having($prepared);
         $this->_regCond[$regKey] = true;
     }
     return;
 }
开发者ID:praxigento,项目名称:mobi_mod_mage2_warehouse,代码行数:23,代码来源:AddQuantityFilterToCollection.php

示例9: afterAddStockDataToCollection

 /**
  * Replace default stock id in the where clause by stock id corresponded with store id.
  *
  * @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Status $subject
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $result
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function afterAddStockDataToCollection(\Magento\CatalogInventory\Model\ResourceModel\Stock\Status $subject, \Magento\Catalog\Model\ResourceModel\Product\Collection $result)
 {
     /** @var \Magento\Framework\Db\Select $select */
     $select = $result->getSelect();
     $from = $select->getPart('from');
     $join = $from['stock_status_index'];
     $cond = $join['joinCondition'];
     $stockId = $this->_manStock->getCurrentStockId();
     $fixed = str_replace('.stock_id = 1', '.stock_id = ' . $stockId, $cond);
     $join['joinCondition'] = $fixed;
     $from['stock_status_index'] = $join;
     $select->setPart('from', $from);
     return $result;
 }
开发者ID:praxigento,项目名称:mobi_mod_mage2_warehouse,代码行数:21,代码来源:Status.php

示例10: _prepareData

 /**
  * @return $this
  */
 protected function _prepareData()
 {
     $product = $this->_coreRegistry->registry('product');
     /* @var $product \Magento\Catalog\Model\Product */
     $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect('required_options')->setPositionOrder()->addStoreFilter();
     if ($this->moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Related.php

示例11: testFindAttributeIdsByProductIds

 public function testFindAttributeIdsByProductIds()
 {
     $productIds = [1, 2, 3];
     $attributeSetIds = [3, 4, 6];
     $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
     $select->expects($this->once())->method('reset')->with(Select::COLUMNS)->willReturnSelf();
     $select->expects($this->once())->method('columns')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $select->expects($this->once())->method('where')->with('entity_id IN (?)', $productIds)->willReturnSelf();
     $select->expects($this->once())->method('group')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $connection = $this->getMock(AdapterInterface::class);
     $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($attributeSetIds);
     $this->productCollection->expects($this->once())->method('getSelect')->willReturn($select);
     $this->productCollection->expects($this->once())->method('getConnection')->willReturn($connection);
     $this->assertEquals($attributeSetIds, $this->attributeSetFinder->findAttributeSetIdsByProductIds($productIds));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:AttributeSetFinderTest.php

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

示例13: _prepareCollection

 /**
  * Premare block data
  * @return $this
  */
 protected function _prepareCollection()
 {
     $post = $this->getPost();
     $this->_itemCollection = $post->getRelatedProducts()->addAttributeToSelect('required_options');
     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->getSelect()->order('rl.position', 'ASC');
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
开发者ID:magefan,项目名称:module-blog,代码行数:20,代码来源:RelatedProducts.php

示例14: addAttributeToSort

 /**
  * Add attribute to sort
  *
  * @param string $attribute
  * @param string $dir
  * @return $this|\Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
 {
     if (in_array($attribute, ['review_cnt', 'last_created', 'avg_rating', 'avg_rating_approved'])) {
         $this->getSelect()->order($attribute . ' ' . $dir);
         return $this;
     }
     return parent::addAttributeToSort($attribute, $dir);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:15,代码来源:Collection.php

示例15: addfilterByParent

 protected function addfilterByParent()
 {
     $this->productCollectionMock->method('getTable')->with('catalog_product_relation')->willReturn('catalog_product_relation');
     $zendDbSelectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->productCollectionMock->method('getSelect')->willReturn($zendDbSelectMock);
     $zendDbSelectMock->method('join')->willReturn($zendDbSelectMock);
     $zendDbSelectMock->method('where')->willReturn($zendDbSelectMock);
 }
开发者ID:vv-team,项目名称:foodo,代码行数:8,代码来源:DataTest.php


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