Skip to content

Commit 530de69

Browse files
Merge remote-tracking branch 'remotes/github/2.3-develop' into MAGETWO-95803
2 parents f1d4457 + b8892f0 commit 530de69

File tree

88 files changed

+6309
-1258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+6309
-1258
lines changed

app/code/Magento/Braintree/Test/Mftf/Data/NewCustomerData.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<data key="City">Yerevan</data>
1919
<data key="Zip">9999</data>
2020
<data key="PhoneNumber">9999</data>
21+
<data key="Country">Armenia</data>
2122
</entity>
2223

2324
</entities>

app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
use Magento\CatalogInventory\Api\StockConfigurationInterface;
1111
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item;
12-
use Magento\CatalogInventory\Model\Stock;
1312
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
1413
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
1514
use Magento\Framework\App\ResourceConnection;
1615
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\DB\Query\Generator;
1717

1818
/**
1919
* Class for filter product price index.
@@ -40,22 +40,38 @@ class ProductPriceIndexFilter implements PriceModifierInterface
4040
*/
4141
private $connectionName;
4242

43+
/**
44+
* @var Generator
45+
*/
46+
private $batchQueryGenerator;
47+
48+
/**
49+
* @var int
50+
*/
51+
private $batchSize;
52+
4353
/**
4454
* @param StockConfigurationInterface $stockConfiguration
4555
* @param Item $stockItem
4656
* @param ResourceConnection $resourceConnection
4757
* @param string $connectionName
58+
* @param Generator $batchQueryGenerator
59+
* @param int $batchSize
4860
*/
4961
public function __construct(
5062
StockConfigurationInterface $stockConfiguration,
5163
Item $stockItem,
5264
ResourceConnection $resourceConnection = null,
53-
$connectionName = 'indexer'
65+
$connectionName = 'indexer',
66+
Generator $batchQueryGenerator = null,
67+
$batchSize = 100
5468
) {
5569
$this->stockConfiguration = $stockConfiguration;
5670
$this->stockItem = $stockItem;
5771
$this->resourceConnection = $resourceConnection ?: ObjectManager::getInstance()->get(ResourceConnection::class);
5872
$this->connectionName = $connectionName;
73+
$this->batchQueryGenerator = $batchQueryGenerator ?: ObjectManager::getInstance()->get(Generator::class);
74+
$this->batchSize = $batchSize;
5975
}
6076

6177
/**
@@ -76,32 +92,37 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
7692

7793
$connection = $this->resourceConnection->getConnection($this->connectionName);
7894
$select = $connection->select();
95+
7996
$select->from(
80-
['price_index' => $priceTable->getTableName()],
81-
[]
82-
);
83-
$select->joinInner(
8497
['stock_item' => $this->stockItem->getMainTable()],
85-
'stock_item.product_id = price_index.' . $priceTable->getEntityField()
86-
. ' AND stock_item.stock_id = ' . Stock::DEFAULT_STOCK_ID,
87-
[]
98+
['stock_item.product_id', 'MAX(stock_item.is_in_stock) as max_is_in_stock']
8899
);
100+
89101
if ($this->stockConfiguration->getManageStock()) {
90-
$stockStatus = $connection->getCheckSql(
91-
'use_config_manage_stock = 0 AND manage_stock = 0',
92-
Stock::STOCK_IN_STOCK,
93-
'is_in_stock'
94-
);
102+
$select->where('stock_item.use_config_manage_stock = 1 OR stock_item.manage_stock = 1');
95103
} else {
96-
$stockStatus = $connection->getCheckSql(
97-
'use_config_manage_stock = 0 AND manage_stock = 1',
98-
'is_in_stock',
99-
Stock::STOCK_IN_STOCK
100-
);
104+
$select->where('stock_item.use_config_manage_stock = 0 AND stock_item.manage_stock = 1');
101105
}
102-
$select->where($stockStatus . ' = ?', Stock::STOCK_OUT_OF_STOCK);
103106

104-
$query = $select->deleteFromSelect('price_index');
105-
$connection->query($query);
107+
$select->group('stock_item.product_id');
108+
$select->having('max_is_in_stock = 0');
109+
110+
$batchSelectIterator = $this->batchQueryGenerator->generate(
111+
'product_id',
112+
$select,
113+
$this->batchSize,
114+
\Magento\Framework\DB\Query\BatchIteratorInterface::UNIQUE_FIELD_ITERATOR
115+
);
116+
117+
foreach ($batchSelectIterator as $select) {
118+
$productIds = null;
119+
foreach ($connection->query($select)->fetchAll() as $row) {
120+
$productIds[] = $row['product_id'];
121+
}
122+
if ($productIds !== null) {
123+
$where = [$priceTable->getEntityField() .' IN (?)' => $productIds];
124+
$connection->delete($priceTable->getTableName(), $where);
125+
}
126+
}
106127
}
107128
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
11+
12+
/**
13+
* Class CancelButton
14+
*/
15+
class CancelButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @return array
21+
*/
22+
public function getButtonData()
23+
{
24+
return [
25+
'label' => __('Cancel'),
26+
'on_click' => '',
27+
'data_attribute' => [
28+
'mage-init' => [
29+
'Magento_Ui/js/form/button-adapter' => [
30+
'actions' => [
31+
[
32+
'targetName' => 'customer_form.areas.address.address.customer_address_update_modal',
33+
'actionName' => 'closeModal'
34+
],
35+
],
36+
],
37+
],
38+
],
39+
'sort_order' => 20
40+
];
41+
}
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Ui\Component\Listing\Address\Column\Actions;
11+
12+
/**
13+
* Delete button on edit customer address form
14+
*/
15+
class DeleteButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* Get delete button data.
19+
*
20+
* @return array
21+
* @throws \Magento\Framework\Exception\LocalizedException
22+
*/
23+
public function getButtonData()
24+
{
25+
$data = [];
26+
if ($this->getAddressId()) {
27+
$data = [
28+
'label' => __('Delete'),
29+
'on_click' => '',
30+
'data_attribute' => [
31+
'mage-init' => [
32+
'Magento_Ui/js/form/button-adapter' => [
33+
'actions' => [
34+
[
35+
'targetName' => 'customer_address_form.customer_address_form',
36+
'actionName' => 'deleteAddress',
37+
'params' => [
38+
$this->getDeleteUrl(),
39+
],
40+
41+
]
42+
],
43+
],
44+
],
45+
],
46+
'sort_order' => 20
47+
];
48+
}
49+
return $data;
50+
}
51+
52+
/**
53+
* Get delete button url.
54+
*
55+
* @return string
56+
* @throws \Magento\Framework\Exception\LocalizedException
57+
*/
58+
private function getDeleteUrl(): string
59+
{
60+
return $this->getUrl(
61+
Actions::CUSTOMER_ADDRESS_PATH_DELETE,
62+
['parent_id' => $this->getCustomerId(), 'id' => $this->getAddressId()]
63+
);
64+
}
65+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Customer\Model\AddressFactory;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\UrlInterface;
12+
use Magento\Customer\Model\ResourceModel\Address;
13+
use Magento\Customer\Model\ResourceModel\AddressRepository;
14+
15+
/**
16+
* Class for common code for buttons on the create/edit address form
17+
*/
18+
class GenericButton
19+
{
20+
/**
21+
* @var AddressFactory
22+
*/
23+
private $addressFactory;
24+
25+
/**
26+
* @var UrlInterface
27+
*/
28+
private $urlBuilder;
29+
30+
/**
31+
* @var Address
32+
*/
33+
private $addressResourceModel;
34+
35+
/**
36+
* @var RequestInterface
37+
*/
38+
private $request;
39+
40+
/**
41+
* @var AddressRepository
42+
*/
43+
private $addressRepository;
44+
45+
/**
46+
* @param AddressFactory $addressFactory
47+
* @param UrlInterface $urlBuilder
48+
* @param Address $addressResourceModel
49+
* @param RequestInterface $request
50+
* @param AddressRepository $addressRepository
51+
*/
52+
public function __construct(
53+
AddressFactory $addressFactory,
54+
UrlInterface $urlBuilder,
55+
Address $addressResourceModel,
56+
RequestInterface $request,
57+
AddressRepository $addressRepository
58+
) {
59+
$this->addressFactory = $addressFactory;
60+
$this->urlBuilder = $urlBuilder;
61+
$this->addressResourceModel = $addressResourceModel;
62+
$this->request = $request;
63+
$this->addressRepository = $addressRepository;
64+
}
65+
66+
/**
67+
* Return address Id.
68+
*
69+
* @return int|null
70+
*/
71+
public function getAddressId()
72+
{
73+
$address = $this->addressFactory->create();
74+
75+
$entityId = $this->request->getParam('entity_id');
76+
$this->addressResourceModel->load(
77+
$address,
78+
$entityId
79+
);
80+
81+
return $address->getEntityId() ?: null;
82+
}
83+
84+
/**
85+
* Get customer id.
86+
*
87+
* @return int|null
88+
* @throws \Magento\Framework\Exception\LocalizedException
89+
*/
90+
public function getCustomerId()
91+
{
92+
$addressId = $this->request->getParam('entity_id');
93+
94+
$address = $this->addressRepository->getById($addressId);
95+
96+
return $address->getCustomerId() ?: null;
97+
}
98+
99+
/**
100+
* Generate url by route and parameters
101+
*
102+
* @param string $route
103+
* @param array $params
104+
* @return string
105+
*/
106+
public function getUrl($route = '', array $params = []): string
107+
{
108+
return $this->urlBuilder->getUrl($route, $params);
109+
}
110+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
11+
12+
/**
13+
* Class SaveButton
14+
*/
15+
class SaveButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @return array
21+
*/
22+
public function getButtonData()
23+
{
24+
return [
25+
'label' => __('Save'),
26+
'class' => 'save primary',
27+
'data_attribute' => [
28+
'mage-init' => ['button' => ['event' => 'save']],
29+
'form-role' => 'save',
30+
],
31+
'sort_order' => 10
32+
];
33+
}
34+
}

0 commit comments

Comments
 (0)