本文整理汇总了PHP中Magento\Catalog\Model\Product::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::save方法的具体用法?PHP Product::save怎么用?PHP Product::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
}
示例2: testProductUpdate
/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php
*/
public function testProductUpdate()
{
$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());
$this->_product->load(1);
$this->_product->setPrice(1);
$this->_product->save();
$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());
}
}
示例3: testReindexRowAfterEdit
/**
*
*/
public function testReindexRowAfterEdit()
{
$this->indexer->reindexAll();
$this->productApple->setData('name', 'Simple Product Cucumber');
$this->productApple->save();
$products = $this->search('Apple');
$this->assertCount(0, $products);
$products = $this->search('Cucumber');
$this->assertCount(1, $products);
$this->assertEquals($this->productApple->getId(), $products[0]->getId());
$products = $this->search('Simple Product');
$this->assertCount(5, $products);
}
示例4: testReindexRowAfterEdit
/**
* @depends testReindexAll
*/
public function testReindexRowAfterEdit()
{
$this->productFirst->setData('name', 'Simple Product Third');
$this->productFirst->save();
$products = $this->search('Simple Product First');
$this->assertCount(0, $products);
$products = $this->search('Simple Product Third');
$this->assertCount(1, $products);
$this->assertEquals($this->productFirst->getId(), $products[0]->getId());
$products = $this->search('Simple Product');
$this->assertCount(2, $products);
$this->assertEquals($this->productFirst->getId(), $products[0]->getId());
$this->assertEquals($this->productSecond->getId(), $products[1]->getId());
}
示例5: testReindexRowAfterEdit
/**
*
*/
public function testReindexRowAfterEdit()
{
$this->testReindexAll();
$this->productApple->setData('name', 'Simple Product Cucumber');
$this->productApple->save();
$products = $this->search('Apple');
$this->assertCount(0, $products);
$products = $this->search('Cucumber');
$this->assertCount(1, $products);
$this->assertEquals($this->productApple->getId(), $products[0]->getId());
$products = $this->search('Simple Product');
$this->assertCount(5, $products);
$this->assertEquals($this->productApple->getId(), $products[0]->getId());
$this->assertEquals($this->productBanana->getId(), $products[1]->getId());
$this->assertEquals($this->productOrange->getId(), $products[2]->getId());
$this->assertEquals($this->productPapaya->getId(), $products[3]->getId());
$this->assertEquals($this->productCherry->getId(), $products[4]->getId());
}
示例6: save
/**
* {@inheritdoc}
*/
public function save()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
if (!$pluginInfo) {
return parent::save();
} else {
return $this->___callPlugins('save', func_get_args(), $pluginInfo);
}
}
示例7: removeTierPrice
/**
* @param \Magento\Catalog\Model\Product $product
* @param int|string $customerGroupId
* @param int $qty
* @param int $websiteId
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @return void
*/
public function removeTierPrice(\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
{
$prices = $product->getData('tier_price');
// verify if price exist
if (is_null($prices)) {
throw new NoSuchEntityException("This product doesn't have tier price");
}
$tierPricesQty = count($prices);
foreach ($prices as $key => $tierPrice) {
if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
} elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
}
}
if ($tierPricesQty == count($prices)) {
throw new NoSuchEntityException("Product hasn't group price with such data: customerGroupId = '{$customerGroupId}'," . "website = {$websiteId}, qty = {$qty}");
}
$product->setData('tier_price', $prices);
try {
$product->save();
} catch (\Exception $exception) {
throw new CouldNotSaveException("Invalid data provided for tier_price");
}
}