Skip to content

Commit

Permalink
MC-17147: Integrity constraint violation: 1452 Cannot add or update a…
Browse files Browse the repository at this point in the history
… child row: a foreign key constraint fails
  • Loading branch information
rganin committed Jul 25, 2019
1 parent aab079d commit a242f2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function addProduct($product)
$this->_addVisitorToItem($item);
$item->loadByProduct($product);

if (!$item->getId()) {
if (!$item->getId() && $item->getProductId()) {
$item->addProductData($product);
$item->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ protected function tearDown()
$this->_session->setCustomerId(null);
}

/**
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
*/
public function testAddProductWithSession()
{
$this->_session->setCustomerId(1);
/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Catalog\Model\Product::class)
->load(1);
$this->_model->addProduct($product);
/** @var $product2 \Magento\Catalog\Model\Product */
$product2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Catalog\Model\Product::class)
->load(6);
$this->_model->addProducts([$product->getId(), $product2->getId(), 'none', 99]);
$this->assertTrue($this->_model->hasItems(1, $this->_visitor->getId()));
$this->assertTrue($this->_model->hasItems(6, $this->_visitor->getId()));
$this->assertFalse($this->_model->hasItems('none', $this->_visitor->getId()));
$this->assertFalse($this->_model->hasItems(99, $this->_visitor->getId()));
}

public function testAddProductWithoutSession()
Expand Down

0 comments on commit a242f2d

Please sign in to comment.