Skip to content

Commit 3b0eb04

Browse files
committed
MTA-3483: Create pull request and deliver extended functional tests to mainline
2 parents 6149965 + d95d459 commit 3b0eb04

File tree

17 files changed

+275
-97
lines changed

17 files changed

+275
-97
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
<script type="text/x-magento-init">
5454
{
5555
"#product_addtocart_form": {
56-
"catalogAddToCart": {
57-
"bindSubmit": false
58-
}
56+
"catalogAddToCart": {}
5957
}
6058
}
6159
</script>

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ define([], function () {
1111
*/
1212
return function (addressData) {
1313
var identifier = Date.now();
14+
var regionId = null;
15+
16+
if (addressData.region && addressData.region.region_id) {
17+
regionId = addressData.region.region_id;
18+
} else if (addressData.country_id && addressData.country_id == window.checkoutConfig.defaultCountryId) {
19+
regionId = window.checkoutConfig.defaultRegionId;
20+
}
1421

1522
return {
1623
email: addressData.email,
1724
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
18-
regionId: (addressData.region && addressData.region.region_id) ?
19-
addressData.region.region_id
20-
: window.checkoutConfig.defaultRegionId,
25+
regionId: regionId,
2126
regionCode: (addressData.region) ? addressData.region.region_code : null,
2227
region: (addressData.region) ? addressData.region.region : null,
2328
customerId: addressData.customer_id,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Model\Product\Plugin;
7+
8+
class RemoveQuoteItems
9+
{
10+
/**
11+
* @var \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
12+
*/
13+
private $quoteItemsCleaner;
14+
15+
/**
16+
* @param \Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner
17+
*/
18+
public function __construct(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner)
19+
{
20+
$this->quoteItemsCleaner = $quoteItemsCleaner;
21+
}
22+
23+
/**
24+
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
25+
* @param \Closure $proceed
26+
* @param \Magento\Catalog\Api\Data\ProductInterface $product
27+
* @return mixed
28+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29+
* TODO: reimplement with after plugin
30+
*/
31+
public function aroundDelete(
32+
\Magento\Catalog\Model\ResourceModel\Product $subject,
33+
\Closure $proceed,
34+
\Magento\Catalog\Api\Data\ProductInterface $product
35+
) {
36+
$result = $proceed($product);
37+
$this->quoteItemsCleaner->execute($product);
38+
return $result;
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Model\Product;
7+
8+
class QuoteItemsCleaner implements \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
9+
{
10+
/**
11+
* @var \Magento\Quote\Model\ResourceModel\Quote\Item
12+
*/
13+
private $itemResource;
14+
15+
/**
16+
* @param \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource
17+
*/
18+
public function __construct(\Magento\Quote\Model\ResourceModel\Quote\Item $itemResource)
19+
{
20+
$this->itemResource = $itemResource;
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function execute(\Magento\Catalog\Api\Data\ProductInterface $product)
27+
{
28+
$this->itemResource->getConnection()->delete(
29+
$this->itemResource->getMainTable(),
30+
'product_id = ' . $product->getId()
31+
);
32+
}
33+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Model\Product;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
10+
interface QuoteItemsCleanerInterface
11+
{
12+
/**
13+
* @param ProductInterface $product
14+
* @return void
15+
*/
16+
public function execute(ProductInterface $product);
17+
}

app/code/Magento/Quote/Setup/InstallSchema.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
964964
$installer->getTable('quote_item'),
965965
'item_id',
966966
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
967-
)->addForeignKey(
968-
$installer->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id'),
969-
'product_id',
970-
$installer->getTable('catalog_product_entity'),
971-
'entity_id',
972-
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
973967
)->addForeignKey(
974968
$installer->getFkName('quote_item', 'quote_id', 'quote', 'entity_id'),
975969
'quote_id',

app/code/Magento/Quote/Setup/Recurring.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/code/Magento/Quote/Setup/UpgradeSchema.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
4141
]
4242
);
4343
}
44-
44+
//drop foreign key for single DB case
45+
if (version_compare($context->getVersion(), '2.0.3', '<')
46+
&& $setup->tableExists($setup->getTable('quote_item'))
47+
) {
48+
$setup->getConnection()->dropForeignKey(
49+
$setup->getTable('quote_item'),
50+
$setup->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id')
51+
);
52+
}
4553
$setup->endSetup();
4654
}
4755
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Test\Unit\Model\Product\Plugin;
7+
8+
class RemoveQuoteItemsTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems
12+
*/
13+
private $model;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Product\QuoteItemsCleanerInterface
17+
*/
18+
private $quoteItemsCleanerMock;
19+
20+
protected function setUp()
21+
{
22+
$this->quoteItemsCleanerMock = $this->getMock(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface::class);
23+
$this->model = new \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems($this->quoteItemsCleanerMock);
24+
}
25+
26+
public function testAroundDelete()
27+
{
28+
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
29+
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
30+
$closure = function () use ($productResourceMock) {
31+
return $productResourceMock;
32+
};
33+
34+
$this->quoteItemsCleanerMock->expects($this->once())->method('execute')->with($productMock);
35+
$result = $this->model->aroundDelete($productResourceMock, $closure, $productMock);
36+
$this->assertEquals($result, $productResourceMock);
37+
}
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Test\Unit\Model\Product;
7+
8+
class QuoteItemsCleanerTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Quote\Model\Product\QuoteItemsCleaner
12+
*/
13+
private $model;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ResourceModel\Quote\Item
17+
*/
18+
private $itemResourceMock;
19+
20+
protected function setUp()
21+
{
22+
$this->itemResourceMock = $this->getMock(
23+
\Magento\Quote\Model\ResourceModel\Quote\Item::class,
24+
[],
25+
[],
26+
'',
27+
false
28+
);
29+
$this->model = new \Magento\Quote\Model\Product\QuoteItemsCleaner($this->itemResourceMock);
30+
}
31+
32+
public function testExecute()
33+
{
34+
$tableName = 'table_name';
35+
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
36+
$productMock->expects($this->once())->method('getId')->willReturn(1);
37+
38+
$connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
39+
$this->itemResourceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
40+
$this->itemResourceMock->expects($this->once())->method('getMainTable')->willReturn($tableName);
41+
42+
$connectionMock->expects($this->once())->method('delete')->with($tableName, 'product_id = 1');
43+
$this->model->execute($productMock);
44+
}
45+
}

app/code/Magento/Quote/etc/di.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<preference for="Magento\Quote\Api\GuestCartTotalManagementInterface" type="\Magento\Quote\Model\GuestCart\GuestCartTotalManagement" />
4141
<preference for="Magento\Quote\Api\Data\EstimateAddressInterface" type="Magento\Quote\Model\EstimateAddress" />
4242
<preference for="Magento\Quote\Api\Data\ProductOptionInterface" type="\Magento\Quote\Model\Quote\ProductOption" />
43-
<!--<preference for="Magento\Quote\Model\Quote\Address\Total\CollectorInterface" type="\Magento\Quote\Model\Quote\Address\Total\Composite" />-->
4443
<type name="Magento\Webapi\Controller\Rest\ParamsOverrider">
4544
<arguments>
4645
<argument name="paramOverriders" xsi:type="array">
@@ -90,4 +89,8 @@
9089
<preference for="Magento\Quote\Model\ShippingMethodManagementInterface" type="Magento\Quote\Model\ShippingMethodManagement" />
9190
<preference for="Magento\Quote\Api\Data\ShippingInterface" type="Magento\Quote\Model\Shipping" />
9291
<preference for="Magento\Quote\Api\Data\ShippingAssignmentInterface" type="Magento\Quote\Model\ShippingAssignment" />
92+
<preference for="Magento\Quote\Model\Product\QuoteItemsCleanerInterface" type="Magento\Quote\Model\Product\QuoteItemsCleaner" />
93+
<type name="Magento\Catalog\Model\ResourceModel\Product">
94+
<plugin name="clean_quote_items_after_product_delete" type="Magento\Quote\Model\Product\Plugin\RemoveQuoteItems"/>
95+
</type>
9396
</config>

app/code/Magento/Quote/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Quote" setup_version="2.0.2">
9+
<module name="Magento_Quote" setup_version="2.0.3">
1010
</module>
1111
</config>

0 commit comments

Comments
 (0)