Skip to content

Commit a298eec

Browse files
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - #14479: [Backport 2.1] Configurable product price options by store (by @simpleadm) - #14348: [Backport 2.1] Add json and xml support to the post method in socket client (by @simpleadm)
2 parents 8941974 + fee221f commit a298eec

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Framework\App\ObjectManager;
1214

1315
/**
1416
* Retrieve list of products where each product contains lower price than others at least for one possible price type
@@ -31,7 +33,12 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
3133
private $collectionFactory;
3234

3335
/**
34-
* Key is product id. Value is prepared product collection
36+
* @var StoreManagerInterface
37+
*/
38+
private $storeManager;
39+
40+
/**
41+
* Key is product id and store id. Value is array of prepared linked products
3542
*
3643
* @var array
3744
*/
@@ -41,34 +48,39 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
4148
* @param ResourceConnection $resourceConnection
4249
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
4350
* @param CollectionFactory $collectionFactory
51+
* @param StoreManagerInterface $storeManager
4452
*/
4553
public function __construct(
4654
ResourceConnection $resourceConnection,
4755
LinkedProductSelectBuilderInterface $linkedProductSelectBuilder,
48-
CollectionFactory $collectionFactory
56+
CollectionFactory $collectionFactory,
57+
StoreManagerInterface $storeManager = null
4958
) {
5059
$this->resource = $resourceConnection;
5160
$this->linkedProductSelectBuilder = $linkedProductSelectBuilder;
5261
$this->collectionFactory = $collectionFactory;
62+
$this->storeManager = $storeManager
63+
?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
5364
}
5465

5566
/**
5667
* {@inheritdoc}
5768
*/
5869
public function getProducts(ProductInterface $product)
5970
{
60-
if (!isset($this->productsMap[$product->getId()])) {
71+
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
72+
if (!isset($this->productsMap[$key])) {
6173
$productIds = $this->resource->getConnection()->fetchCol(
6274
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
6375
);
6476

65-
$this->productsMap[$product->getId()] = $this->collectionFactory->create()
77+
$this->productsMap[$key] = $this->collectionFactory->create()
6678
->addAttributeToSelect(
6779
['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
6880
)
6981
->addIdFilter($productIds)
7082
->getItems();
7183
}
72-
return $this->productsMap[$product->getId()];
84+
return $this->productsMap[$key];
7385
}
7486
}

lib/internal/Magento/Framework/HTTP/Client/Socket.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ protected function parseUrl($uri)
273273
* Make POST request
274274
*
275275
* @param string $uri
276-
* @param array $params
276+
* @param array|string $params use string in case of JSON or XML POST request
277277
* @return void
278278
*/
279279
public function post($uri, $params)
@@ -455,10 +455,12 @@ public function getStatus()
455455

456456
/**
457457
* Make request
458+
*
458459
* @param string $method
459460
* @param string $uri
460-
* @param array $params
461+
* @param array|string $params use string in case of JSON or XML POST request
461462
* @return void
463+
* @throws \Exception
462464
*/
463465
protected function makeRequest($method, $uri, $params = [])
464466
{
@@ -473,8 +475,8 @@ protected function makeRequest($method, $uri, $params = [])
473475

474476
$appendHeaders = [];
475477
$paramsStr = false;
476-
if ($isPost && count($params)) {
477-
$paramsStr = http_build_query($params);
478+
if ($isPost && $params) {
479+
$paramsStr = is_array($params) ? http_build_query($params) : $params;
478480
$appendHeaders['Content-type'] = 'application/x-www-form-urlencoded';
479481
$appendHeaders['Content-length'] = strlen($paramsStr);
480482
}

0 commit comments

Comments
 (0)