Skip to content

Commit 2a99cb6

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into 2.2.4-PR-part-1
2 parents a4cfa03 + 143ca44 commit 2a99cb6

File tree

16 files changed

+178
-38
lines changed

16 files changed

+178
-38
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
467467
if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
468468
$productLinks = $product->getProductLinks();
469469
}
470-
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
470+
if (!isset($productDataArray['store_id'])) {
471+
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
472+
}
471473
$product = $this->initializeProductData($productDataArray, empty($existingProduct));
472474

473475
$this->processLinks($product, $productLinks);

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ define([
9797
success: function (res) {
9898
var eventData, parameters;
9999

100-
$(document).trigger('ajax:addToCart', form.data().productSku, form, res);
100+
$(document).trigger('ajax:addToCart', {
101+
'sku': form.data().productSku,
102+
'form': form,
103+
'response': res
104+
});
101105

102106
if (self.isLoaderEnabled()) {
103107
$('body').trigger(self.options.processStop);

app/code/Magento/CatalogInventory/Model/Source/Stock.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,23 @@ public function getAllOptions()
2626
['value' => \Magento\CatalogInventory\Model\Stock::STOCK_OUT_OF_STOCK, 'label' => __('Out of Stock')]
2727
];
2828
}
29+
30+
/**
31+
* Add Value Sort To Collection Select.
32+
*
33+
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
34+
* @param string $dir
35+
*
36+
* @return $this
37+
*/
38+
public function addValueSortToCollection($collection, $dir = \Magento\Framework\Data\Collection::SORT_ORDER_DESC)
39+
{
40+
$collection->getSelect()->joinLeft(
41+
['stock_item_table' => 'cataloginventory_stock_item'],
42+
"e.entity_id=stock_item_table.product_id",
43+
[]
44+
);
45+
$collection->getSelect()->order("stock_item_table.qty $dir");
46+
return $this;
47+
}
2948
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogInventory\Test\Unit\Model\Source;
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
class StockTest extends TestCase
12+
{
13+
/**
14+
* @var \Magento\CatalogInventory\Model\Source\Stock
15+
*/
16+
private $model;
17+
18+
protected function setUp()
19+
{
20+
$this->model = new \Magento\CatalogInventory\Model\Source\Stock();
21+
}
22+
23+
public function testAddValueSortToCollection()
24+
{
25+
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
26+
$collectionMock = $this->createMock(\Magento\Eav\Model\Entity\Collection\AbstractCollection::class);
27+
$collectionMock->expects($this->atLeastOnce())->method('getSelect')->willReturn($selectMock);
28+
29+
$selectMock->expects($this->once())
30+
->method('joinLeft')
31+
->with(
32+
['stock_item_table' => 'cataloginventory_stock_item'],
33+
"e.entity_id=stock_item_table.product_id",
34+
[]
35+
)
36+
->willReturnSelf();
37+
$selectMock->expects($this->once())
38+
->method('order')
39+
->with("stock_item_table.qty DESC")
40+
->willReturnSelf();
41+
42+
$this->model->addValueSortToCollection($collectionMock);
43+
}
44+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
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_Config" setup_version="2.0.0"/>
9+
<module name="Magento_Config" setup_version="2.0.0">
10+
<sequence>
11+
<module name="Magento_Store"/>
12+
</sequence>
13+
</module>
1014
</config>

app/code/Magento/Quote/Observer/Webapi/SubmitObserver.php renamed to app/code/Magento/Quote/Observer/SubmitObserver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Quote\Observer\Webapi;
6+
namespace Magento\Quote\Observer;
77

88
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
99
use Magento\Framework\Event\ObserverInterface;
@@ -13,12 +13,12 @@ class SubmitObserver implements ObserverInterface
1313
/**
1414
* @var \Psr\Log\LoggerInterface
1515
*/
16-
protected $logger;
16+
private $logger;
1717

1818
/**
1919
* @var OrderSender
2020
*/
21-
protected $orderSender;
21+
private $orderSender;
2222

2323
/**
2424
* @param \Psr\Log\LoggerInterface $logger

app/code/Magento/Quote/Test/Unit/Observer/Webapi/SubmitObserverTest.php renamed to app/code/Magento/Quote/Test/Unit/Observer/SubmitObserverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Quote\Test\Unit\Observer\Webapi;
6+
namespace Magento\Quote\Test\Unit\Observer;
77

88
class SubmitObserverTest extends \PHPUnit\Framework\TestCase
99
{
1010
/**
11-
* @var \Magento\Quote\Observer\Webapi\SubmitObserver
11+
* @var \Magento\Quote\Observer\SubmitObserver
1212
*/
1313
protected $model;
1414

@@ -59,7 +59,7 @@ protected function setUp()
5959
$eventMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock);
6060
$eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
6161
$this->quoteMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock);
62-
$this->model = new \Magento\Quote\Observer\Webapi\SubmitObserver(
62+
$this->model = new \Magento\Quote\Observer\SubmitObserver(
6363
$this->loggerMock,
6464
$this->orderSenderMock
6565
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
9+
<event name="sales_model_service_quote_submit_success">
10+
<observer name="sendEmail" instance="Magento\Quote\Observer\SubmitObserver" />
11+
</event>
12+
</config>

app/code/Magento/Quote/etc/webapi_rest/events.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
99
<event name="sales_model_service_quote_submit_success">
10-
<observer name="sendEmail" instance="Magento\Quote\Observer\Webapi\SubmitObserver" />
10+
<observer name="sendEmail" instance="Magento\Quote\Observer\SubmitObserver" />
1111
</event>
1212
</config>

app/code/Magento/Quote/etc/webapi_soap/events.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
99
<event name="sales_model_service_quote_submit_success">
10-
<observer name="sendEmail" instance="Magento\Quote\Observer\Webapi\SubmitObserver" />
10+
<observer name="sendEmail" instance="Magento\Quote\Observer\SubmitObserver" />
1111
</event>
1212
</config>

0 commit comments

Comments
 (0)