當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::load方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\ResourceModel\Product\Collection::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::load方法的具體用法?PHP Collection::load怎麽用?PHP Collection::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\ResourceModel\Product\Collection的用法示例。


在下文中一共展示了Collection::load方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testAddLinkAttributeToFilterNoResults

 /**
  * @magentoDataFixture Magento/Catalog/_files/products_crosssell.php
  */
 public function testAddLinkAttributeToFilterNoResults()
 {
     $om = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $link = $om->get('Magento\\Catalog\\Model\\Product\\Link')->useCrossSellLinks();
     $this->collection->setLinkModel($link);
     $this->collection->addLinkAttributeToFilter('position', ['from' => 2, 'to' => 3]);
     $product = $om->get('Magento\\Catalog\\Model\\Product')->load(2);
     $this->collection->setProduct($product);
     $this->collection->load();
     $this->assertCount(0, $this->collection->getItems());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:CollectionTest.php

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

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

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

示例5: testAddPriceDataOnSave

 /**
  * @magentoDataFixture Magento/Catalog/_files/products.php
  * @magentoAppIsolation enabled
  */
 public function testAddPriceDataOnSave()
 {
     $this->processor->getIndexer()->setScheduled(false);
     $this->assertFalse($this->processor->getIndexer()->isScheduled());
     $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
     $product = $productRepository->get('simple');
     $this->assertNotEquals(15, $product->getPrice());
     $product->setPrice(15);
     $productRepository->save($product);
     $this->collection->addPriceData(0, 1);
     $this->collection->load();
     /** @var \Magento\Catalog\Api\Data\ProductInterface[] $product */
     $items = $this->collection->getItems();
     /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
     $product = reset($items);
     $this->assertCount(2, $items);
     $this->assertEquals(15, $product->getPrice());
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:23,代碼來源:CollectionTest.php

示例6: _prepareData

 /**
  * @return $this
  */
 protected function _prepareData()
 {
     $product = $this->_coreRegistry->registry('product');
     /* @var $product \Magento\Catalog\Model\Product */
     $this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter();
     if ($this->moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->load();
     /**
      * Updating collection with desired items
      */
     $this->_eventManager->dispatch('catalog_product_upsell', ['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]);
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
開發者ID:IlyaGluschenko,項目名稱:test001,代碼行數:22,代碼來源:Upsell.php


注:本文中的Magento\Catalog\Model\ResourceModel\Product\Collection::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。