Skip to content

Commit

Permalink
MTA-3483: Create pull request and deliver extended functional tests t…
Browse files Browse the repository at this point in the history
…o mainline
  • Loading branch information
lanken committed Aug 11, 2016
2 parents 6149965 + d95d459 commit 3b0eb04
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"catalogAddToCart": {
"bindSubmit": false
}
"catalogAddToCart": {}
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ define([], function () {
*/
return function (addressData) {
var identifier = Date.now();
var regionId = null;

if (addressData.region && addressData.region.region_id) {
regionId = addressData.region.region_id;
} else if (addressData.country_id && addressData.country_id == window.checkoutConfig.defaultCountryId) {
regionId = window.checkoutConfig.defaultRegionId;
}

return {
email: addressData.email,
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
regionId: (addressData.region && addressData.region.region_id) ?
addressData.region.region_id
: window.checkoutConfig.defaultRegionId,
regionId: regionId,
regionCode: (addressData.region) ? addressData.region.region_code : null,
region: (addressData.region) ? addressData.region.region : null,
customerId: addressData.customer_id,
Expand Down
40 changes: 40 additions & 0 deletions app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product\Plugin;

class RemoveQuoteItems
{
/**
* @var \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
*/
private $quoteItemsCleaner;

/**
* @param \Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner
*/
public function __construct(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner)
{
$this->quoteItemsCleaner = $quoteItemsCleaner;
}

/**
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
* @param \Closure $proceed
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* TODO: reimplement with after plugin
*/
public function aroundDelete(
\Magento\Catalog\Model\ResourceModel\Product $subject,
\Closure $proceed,
\Magento\Catalog\Api\Data\ProductInterface $product
) {
$result = $proceed($product);
$this->quoteItemsCleaner->execute($product);
return $result;
}
}
33 changes: 33 additions & 0 deletions app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product;

class QuoteItemsCleaner implements \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
{
/**
* @var \Magento\Quote\Model\ResourceModel\Quote\Item
*/
private $itemResource;

/**
* @param \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource
*/
public function __construct(\Magento\Quote\Model\ResourceModel\Quote\Item $itemResource)
{
$this->itemResource = $itemResource;
}

/**
* {@inheritdoc}
*/
public function execute(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$this->itemResource->getConnection()->delete(
$this->itemResource->getMainTable(),
'product_id = ' . $product->getId()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;

interface QuoteItemsCleanerInterface
{
/**
* @param ProductInterface $product
* @return void
*/
public function execute(ProductInterface $product);
}
6 changes: 0 additions & 6 deletions app/code/Magento/Quote/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,12 +964,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer->getTable('quote_item'),
'item_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->addForeignKey(
$installer->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id'),
'product_id',
$installer->getTable('catalog_product_entity'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->addForeignKey(
$installer->getFkName('quote_item', 'quote_id', 'quote', 'entity_id'),
'quote_id',
Expand Down
73 changes: 0 additions & 73 deletions app/code/Magento/Quote/Setup/Recurring.php

This file was deleted.

10 changes: 9 additions & 1 deletion app/code/Magento/Quote/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
]
);
}

//drop foreign key for single DB case
if (version_compare($context->getVersion(), '2.0.3', '<')
&& $setup->tableExists($setup->getTable('quote_item'))
) {
$setup->getConnection()->dropForeignKey(
$setup->getTable('quote_item'),
$setup->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id')
);
}
$setup->endSetup();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Test\Unit\Model\Product\Plugin;

class RemoveQuoteItemsTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Product\QuoteItemsCleanerInterface
*/
private $quoteItemsCleanerMock;

protected function setUp()
{
$this->quoteItemsCleanerMock = $this->getMock(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface::class);
$this->model = new \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems($this->quoteItemsCleanerMock);
}

public function testAroundDelete()
{
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
$closure = function () use ($productResourceMock) {
return $productResourceMock;
};

$this->quoteItemsCleanerMock->expects($this->once())->method('execute')->with($productMock);
$result = $this->model->aroundDelete($productResourceMock, $closure, $productMock);
$this->assertEquals($result, $productResourceMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Test\Unit\Model\Product;

class QuoteItemsCleanerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Quote\Model\Product\QuoteItemsCleaner
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ResourceModel\Quote\Item
*/
private $itemResourceMock;

protected function setUp()
{
$this->itemResourceMock = $this->getMock(
\Magento\Quote\Model\ResourceModel\Quote\Item::class,
[],
[],
'',
false
);
$this->model = new \Magento\Quote\Model\Product\QuoteItemsCleaner($this->itemResourceMock);
}

public function testExecute()
{
$tableName = 'table_name';
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
$productMock->expects($this->once())->method('getId')->willReturn(1);

$connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
$this->itemResourceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
$this->itemResourceMock->expects($this->once())->method('getMainTable')->willReturn($tableName);

$connectionMock->expects($this->once())->method('delete')->with($tableName, 'product_id = 1');
$this->model->execute($productMock);
}
}
5 changes: 4 additions & 1 deletion app/code/Magento/Quote/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<preference for="Magento\Quote\Api\GuestCartTotalManagementInterface" type="\Magento\Quote\Model\GuestCart\GuestCartTotalManagement" />
<preference for="Magento\Quote\Api\Data\EstimateAddressInterface" type="Magento\Quote\Model\EstimateAddress" />
<preference for="Magento\Quote\Api\Data\ProductOptionInterface" type="\Magento\Quote\Model\Quote\ProductOption" />
<!--<preference for="Magento\Quote\Model\Quote\Address\Total\CollectorInterface" type="\Magento\Quote\Model\Quote\Address\Total\Composite" />-->
<type name="Magento\Webapi\Controller\Rest\ParamsOverrider">
<arguments>
<argument name="paramOverriders" xsi:type="array">
Expand Down Expand Up @@ -90,4 +89,8 @@
<preference for="Magento\Quote\Model\ShippingMethodManagementInterface" type="Magento\Quote\Model\ShippingMethodManagement" />
<preference for="Magento\Quote\Api\Data\ShippingInterface" type="Magento\Quote\Model\Shipping" />
<preference for="Magento\Quote\Api\Data\ShippingAssignmentInterface" type="Magento\Quote\Model\ShippingAssignment" />
<preference for="Magento\Quote\Model\Product\QuoteItemsCleanerInterface" type="Magento\Quote\Model\Product\QuoteItemsCleaner" />
<type name="Magento\Catalog\Model\ResourceModel\Product">
<plugin name="clean_quote_items_after_product_delete" type="Magento\Quote\Model\Product\Plugin\RemoveQuoteItems"/>
</type>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Quote" setup_version="2.0.2">
<module name="Magento_Quote" setup_version="2.0.3">
</module>
</config>
Loading

0 comments on commit 3b0eb04

Please sign in to comment.