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


PHP Product::load方法代碼示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\ConfigurableProduct\\Block\\Product\\View\\Type\\Configurable');
     $this->_block->setProduct($this->_product);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:7,代碼來源:ConfigurableTest.php

示例2: testProductUpdate

 /**
  * @magentoDataFixture Magento/Catalog/_files/row_fixture.php
  * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
  * @magentoAppArea frontend
  */
 public function testProductUpdate()
 {
     $this->markTestSkipped('Incomplete due to MAGETWO-21369');
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Block\\Product\\ListProduct');
     $this->_processor->getIndexer()->setScheduled(false);
     $this->assertFalse($this->_processor->getIndexer()->isScheduled(), 'Indexer is in scheduled mode when turned to update on save mode');
     $this->_processor->reindexAll();
     $this->_product->load(1);
     $this->_product->setName('Updated Product');
     $this->_product->save();
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */
     $productCollection = $layer->getProductCollection();
     $this->assertTrue($productCollection->isEnabledFlat(), 'Product collection is not using flat resource when flat is on');
     $this->assertEquals(2, $productCollection->count(), 'Product collection items count must be exactly 2');
     foreach ($productCollection as $product) {
         /** @var $product \Magento\Catalog\Model\Product */
         if ($product->getId() == 1) {
             $this->assertEquals('Updated Product', $product->getName(), 'Product name from flat does not match with updated name');
         }
     }
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:30,代碼來源:RowTest.php

示例3: prepareProducts

 protected function prepareProducts()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->productSecond = clone $this->product;
     $this->productSecond->setId(null)->setUrlKey('product-second')->save();
     $this->productThird = clone $this->product;
     $this->productThird->setId(null)->setUrlKey('product-third')->setData('test_attribute', 'NO_test_attribute_value')->save();
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:8,代碼來源:IndexerBuilderTest.php

示例4: setUp

 protected function setUp()
 {
     $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
     $this->product = Bootstrap::getObjectManager()->create(Product::class);
     $this->product->load(1);
     $this->model = Bootstrap::getObjectManager()->create(Configurable::class);
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->product->setTypeInstance($this->model);
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:9,代碼來源:ConfigurableTest.php

示例5: setUp

 protected function setUp()
 {
     $this->_product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_model = Bootstrap::getObjectManager()->create('Magento\\ConfigurableProduct\\Model\\Product\\VariationHandler');
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->_product->setTypeInstance($this->_model);
     $this->stockRegistry = Bootstrap::getObjectManager()->get('Magento\\CatalogInventory\\Api\\StockRegistryInterface');
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:9,代碼來源:VariationHandlerTest.php

示例6: testGetAttributes

 public function testGetAttributes()
 {
     // fixture required
     $this->_model->load(1);
     $attributes = $this->_model->getAttributes();
     $this->assertArrayHasKey('name', $attributes);
     $this->assertArrayHasKey('sku', $attributes);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attributes['sku']);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:9,代碼來源:ProductGettersTest.php

示例7: setUp

 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     // fixture
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\ConfigurableProduct\\Model\\Product\\VariationHandler');
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->_product->setTypeInstance($this->_model);
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:9,代碼來源:VariationHandlerTest.php

示例8: testReindexAfterRuleCreation

 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testReindexAfterRuleCreation()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
     $this->saveRule();
     // apply all rules
     $this->indexBuilder->reindexFull();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:13,代碼來源:RuleProductTest.php

示例9: setUp

 protected function setUp()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_block = $objectManager->create('Magento\\Catalog\\Block\\Product\\View');
     $this->_product = $objectManager->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $objectManager->get('Magento\\Framework\\Registry')->unregister('product');
     $objectManager->get('Magento\\Framework\\Registry')->register('product', $this->_product);
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:9,代碼來源:ViewTest.php

示例10: setUp

 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $objectManager->get('Magento\\Framework\\Registry')->unregister('current_product');
     $objectManager->get('Magento\\Framework\\Registry')->register('current_product', $this->_product);
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Catalog\\Block\\Product\\View\\Options');
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:10,代碼來源:OptionsTest.php

示例11: prepareProducts

 /**
  * @return array
  */
 protected function prepareProducts($price)
 {
     $this->product->load(1);
     $productSecond = clone $this->product;
     $productSecond->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1]);
     $productSecond->save();
     $productSecond->setPrice($price)->save();
     $productThird = clone $this->product;
     $productThird->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1])->save();
     $productThird->setPrice($price)->save();
     return [$productSecond->getId(), $productThird->getId()];
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:BatchIndexTest.php

示例12: testGetItems

 /**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  */
 public function testGetItems()
 {
     $this->product = $this->objectManager->get('Magento\\Catalog\\Model\\Product');
     $this->product->load(3);
     /**
      * @var \Magento\Bundle\Model\Product\OptionList $optionList
      */
     $optionList = $this->objectManager->create('\\Magento\\Bundle\\Model\\Product\\OptionList');
     $options = $optionList->getItems($this->product);
     $this->assertEquals(1, count($options));
     $this->assertEquals('Bundle Product Items', $options[0]->getTitle());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:OptionListTest.php

示例13: setUp

 protected function setUp()
 {
     if (!self::$_isStubClass) {
         $this->getMockForAbstractClass('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], self::STUB_CLASS, false);
         self::$_isStubClass = true;
     }
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode('frontend');
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface')->setDefaultDesignTheme();
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock(self::STUB_CLASS);
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_product->addData(['image' => '/m/a/magento_image.jpg', 'small_image' => '/m/a/magento_image.jpg', 'thumbnail' => '/m/a/magento_image.jpg']);
     $this->_block->setProduct($this->_product);
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:14,代碼來源:AbstractTest.php

示例14: testProductsUpdate

 /**
  * @magentoDbIsolation disabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php
  */
 public function testProductsUpdate()
 {
     $this->_product->load(1);
     $this->_processor->reindexList([$this->_product->getId()]);
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     $productCollection = $layer->getProductCollection();
     $this->assertEquals(1, $productCollection->count());
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($productCollection as $product) {
         $this->assertEquals($this->_product->getId(), $product->getId());
         $this->assertEquals($this->_product->getPrice(), $product->getPrice());
     }
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:22,代碼來源:RowsTest.php

示例15: testSaveProductRelationsNoChildren

 public function testSaveProductRelationsNoChildren()
 {
     $childrenIds = $this->_product->getTypeInstance()->getChildrenIds(1);
     $this->assertNotEmpty(reset($childrenIds));
     $this->_product->setAssociatedProductIds([]);
     $this->_model->save($this->_product);
     $this->_product->load(1);
     $this->assertEquals([[]], $this->_product->getTypeInstance()->getChildrenIds(1));
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:9,代碼來源:ConfigurableTest.php


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