Skip to content

Commit e6bb20c

Browse files
[Magento Community Engineering] Community Contributions - 2.2-develop
- merged latest code from mainline branch
2 parents 1392062 + 7ba965a commit e6bb20c

File tree

10 files changed

+302
-416
lines changed

10 files changed

+302
-416
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Category;
9+
10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Model\Category;
12+
use Magento\Store\Api\GroupRepositoryInterface;
13+
14+
/**
15+
* Fetcher for associated with store group categories.
16+
*/
17+
class StoreCategories
18+
{
19+
/**
20+
* @var CategoryRepositoryInterface
21+
*/
22+
private $categoryRepository;
23+
24+
/**
25+
* @var GroupRepositoryInterface
26+
*/
27+
private $groupRepository;
28+
29+
/**
30+
* @param CategoryRepositoryInterface $categoryRepository
31+
* @param GroupRepositoryInterface $groupRepository
32+
*/
33+
public function __construct(
34+
CategoryRepositoryInterface $categoryRepository,
35+
GroupRepositoryInterface $groupRepository
36+
) {
37+
$this->categoryRepository = $categoryRepository;
38+
$this->groupRepository = $groupRepository;
39+
}
40+
41+
/**
42+
* Get all category ids for store.
43+
*
44+
* @param int|null $storeGroupId
45+
* @return array
46+
* @throws \Magento\Framework\Exception\NoSuchEntityException
47+
*/
48+
public function getCategoryIds($storeGroupId = null): array
49+
{
50+
$rootCategoryId = $storeGroupId
51+
? $this->groupRepository->get($storeGroupId)->getRootCategoryId()
52+
: Category::TREE_ROOT_ID;
53+
/** @var Category $rootCategory */
54+
$rootCategory = $this->categoryRepository->get($rootCategoryId);
55+
$categoriesIds = $rootCategory->getAllChildren(true);
56+
57+
return (array) $categoriesIds;
58+
}
59+
}

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<a href="#"
2121
onclick="tree.collapseTree(); return false;"><?= $block->escapeHtml(__('Collapse All')) ?></a>
2222
<span class="separator">|</span> <a href="#"
23-
onclick="tree.expandTree(); return false;"><?= $block->escapeHtml(_('Expand All')) ?></a>
23+
onclick="tree.expandTree(); return false;"><?= $block->escapeHtml(__('Expand All')) ?></a>
2424
<?php endif; ?>
2525
</div>
2626
<?php if ($block->getRoot()) :?>

app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ public function process($path, $value, $scope, $scopeCode)
9191

9292
try {
9393
$config = $this->configFactory->create([
94-
'scope' => $scope,
95-
'scope_code' => $scopeCode,
94+
'data' => [
95+
'scope' => $scope,
96+
'scope_code' => $scopeCode,
97+
],
9698
]);
9799
$config->setDataByPath($path, $value);
98100
$config->save();

app/code/Magento/Config/Model/Config.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ public function setDataByPath($path, $value)
535535
}
536536

537537
$section = array_shift($pathParts);
538+
$this->setData('section', $section);
539+
538540
$data = [
539541
'fields' => [
540542
array_pop($pathParts) => ['value' => $value],
@@ -547,8 +549,8 @@ public function setDataByPath($path, $value)
547549
],
548550
];
549551
}
550-
$data['section'] = $section;
551-
$this->addData($data);
552+
$groups = array_replace_recursive((array) $this->getData('groups'), $data['groups']);
553+
$this->setData('groups', $groups);
552554
}
553555

554556
/**

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ protected function setUp()
9999
public function testProcess($path, $value, $scope, $scopeCode)
100100
{
101101
$this->configMockForProcessTest($path, $scope, $scopeCode);
102+
$scopeData = ['scope' => $scope, 'scope_code' => $scopeCode];
102103

103104
$config = $this->createMock(Config::class);
104105
$this->configFactory->method('create')
105-
->with(['scope' => $scope, 'scope_code' => $scopeCode])
106+
->with(['data' => $scopeData])
106107
->willReturn($config);
107108
$config->method('setDataByPath')
108109
->with($path, $value);

app/code/Magento/Paypal/Model/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function _applyDiscountTaxCompensationWorkaround(
177177
) {
178178
$dataContainer = $salesEntity->getTaxContainer();
179179
$this->addTax((double)$dataContainer->getBaseDiscountTaxCompensationAmount());
180-
$this->addTax((double)$dataContainer->getBaseShippingDiscountTaxCompensationAmount());
180+
$this->addTax((double)$dataContainer->getBaseShippingDiscountTaxCompensationAmnt());
181181
}
182182

183183
/**

app/code/Magento/Paypal/Model/Payflow/Transparent.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class Transparent extends Payflowpro implements TransparentInterface
6161
*/
6262
private $paymentExtensionFactory;
6363

64+
/**
65+
* @var \Magento\Paypal\Model\CartFactory
66+
*/
67+
private $payPalCartFactory;
68+
6469
/**
6570
* @param \Magento\Framework\Model\Context $context
6671
* @param \Magento\Framework\Registry $registry
@@ -78,6 +83,7 @@ class Transparent extends Payflowpro implements TransparentInterface
7883
* @param ResponseValidator $responseValidator
7984
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
8085
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
86+
* @param \Magento\Paypal\Model\CartFactory $payPalCartFactory
8187
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
8288
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
8389
* @param array $data
@@ -100,6 +106,7 @@ public function __construct(
100106
ResponseValidator $responseValidator,
101107
PaymentTokenInterfaceFactory $paymentTokenFactory,
102108
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
109+
\Magento\Paypal\Model\CartFactory $payPalCartFactory,
103110
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
104111
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
105112
array $data = []
@@ -125,6 +132,7 @@ public function __construct(
125132
$this->responseValidator = $responseValidator;
126133
$this->paymentTokenFactory = $paymentTokenFactory;
127134
$this->paymentExtensionFactory = $paymentExtensionFactory;
135+
$this->payPalCartFactory = $payPalCartFactory;
128136
}
129137

130138
/**
@@ -166,15 +174,18 @@ public function authorize(InfoInterface $payment, $amount)
166174
$this->addRequestOrderInfo($request, $order);
167175
$request = $this->fillCustomerContacts($order, $request);
168176

177+
$payPalCart = $this->payPalCartFactory->create(['salesModel' => $order]);
178+
$payPalCart->getAmounts();
179+
169180
$token = $payment->getAdditionalInformation(self::PNREF);
170181
$request->setData('trxtype', self::TRXTYPE_AUTH_ONLY);
171182
$request->setData('origid', $token);
172183
$request->setData('amt', $this->formatPrice($amount));
173184
$request->setData('currency', $order->getBaseCurrencyCode());
174-
$request->setData('itemamt', $this->formatPrice($order->getBaseSubtotal()));
175-
$request->setData('taxamt', $this->calculateTaxAmount($order));
176-
$request->setData('freightamt', $this->formatPrice($order->getBaseShippingAmount()));
177-
$request->setData('discount', $this->formatPrice(abs($order->getBaseDiscountAmount())));
185+
$request->setData('itemamt', $this->formatPrice($payPalCart->getSubtotal()));
186+
$request->setData('taxamt', $this->formatPrice($payPalCart->getTax()));
187+
$request->setData('freightamt', $this->formatPrice($payPalCart->getShipping()));
188+
$request->setData('discount', $this->formatPrice($payPalCart->getDiscount()));
178189

179190
$response = $this->postRequest($request, $this->getConfig());
180191
$this->processErrors($response);
@@ -291,20 +302,4 @@ public function capture(InfoInterface $payment, $amount)
291302

292303
return $this;
293304
}
294-
295-
/**
296-
* Calculates tax amount including discount compensation for product/shipping price included tax.
297-
*
298-
* @param OrderInterface $order
299-
* @return string
300-
*/
301-
private function calculateTaxAmount(
302-
OrderInterface $order
303-
): string {
304-
return $this->formatPrice(
305-
$order->getBaseTaxAmount()
306-
+ $order->getBaseDiscountTaxCompensationAmount()
307-
+ $order->getBaseShippingDiscountTaxCompensationAmnt()
308-
);
309-
}
310305
}

app/code/Magento/Paypal/Test/Unit/Model/CartTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function setUp()
7070
public function testInvalidGetAllItems($items)
7171
{
7272
$taxContainer = new \Magento\Framework\DataObject(
73-
['base_discount_tax_compensation_amount' => 0.2, 'base_shipping_discount_tax_compensation_amount' => 0.1]
73+
['base_discount_tax_compensation_amount' => 0.2, 'base_shipping_discount_tax_compensation_amnt' => 0.1]
7474
);
7575
$this->_salesModel->expects($this->once())->method('getTaxContainer')->will($this->returnValue($taxContainer));
7676
$this->_salesModel->expects($this->once())->method('getAllItems')->will($this->returnValue($items));
@@ -146,7 +146,7 @@ public function testInvalidTotalsGetAllItems($values, $transferDiscount)
146146
$this->assertEquals(
147147
$values['base_tax_amount'] +
148148
$values['base_discount_tax_compensation_amount'] +
149-
$values['base_shipping_discount_tax_compensation_amount'],
149+
$values['base_shipping_discount_tax_compensation_amnt'],
150150
$this->_model->getTax()
151151
);
152152
$this->assertEquals($values['base_shipping_amount'], $this->_model->getShipping());
@@ -162,7 +162,7 @@ public function invalidTotalsGetAllItemsDataProvider()
162162
[
163163
[
164164
'base_discount_tax_compensation_amount' => 0,
165-
'base_shipping_discount_tax_compensation_amount' => 0,
165+
'base_shipping_discount_tax_compensation_amnt' => 0,
166166
'base_subtotal' => 0,
167167
'base_tax_amount' => 0,
168168
'base_shipping_amount' => 0,
@@ -174,7 +174,7 @@ public function invalidTotalsGetAllItemsDataProvider()
174174
[
175175
[
176176
'base_discount_tax_compensation_amount' => 1,
177-
'base_shipping_discount_tax_compensation_amount' => 2,
177+
'base_shipping_discount_tax_compensation_amnt' => 2,
178178
'base_subtotal' => 3,
179179
'base_tax_amount' => 4,
180180
'base_shipping_amount' => 5,
@@ -255,8 +255,8 @@ protected function _prepareInvalidModelData($values, $transferDiscount)
255255
[
256256
'base_discount_tax_compensation_amount' =>
257257
$values['base_discount_tax_compensation_amount'],
258-
'base_shipping_discount_tax_compensation_amount' =>
259-
$values['base_shipping_discount_tax_compensation_amount'],
258+
'base_shipping_discount_tax_compensation_amnt' =>
259+
$values['base_shipping_discount_tax_compensation_amnt'],
260260
]
261261
);
262262
$expectedSubtotal = $values['base_subtotal'];

0 commit comments

Comments
 (0)