本文整理汇总了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);
}
示例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');
}
}
}
示例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();
}
示例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);
}
示例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');
}
示例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']);
}
示例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);
}
示例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));
}
示例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);
}
示例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');
}
示例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()];
}
示例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());
}
示例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);
}
示例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());
}
}
示例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));
}