Skip to content

Commit f34651e

Browse files
authored
Merge pull request #7419 from magento-l3/PR1-21-01-2022
PR1-CE-21-01-2022
2 parents c901f76 + 4bcdab0 commit f34651e

File tree

16 files changed

+735
-101
lines changed

16 files changed

+735
-101
lines changed

app/code/Magento/Catalog/Model/ResourceModel/ProductFrontendAction/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function addFilterByUserIdentities($customerId, $visitorId)
3636
$this->addFieldToFilter('customer_id', $customerId);
3737
} elseif ($visitorId) {
3838
$this->addFieldToFilter('visitor_id', $visitorId);
39+
} else {
40+
$this->_totalRecords = 0;
41+
$this->_setIsLoaded(true);
3942
}
4043

4144
return $this;

app/code/Magento/Checkout/Model/Layout/DepersonalizePlugin.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class DepersonalizePlugin
2828
*/
2929
private $checkoutSession;
3030

31+
/**
32+
* @var int
33+
*/
34+
private $quoteId;
35+
3136
/**
3237
* @param DepersonalizeChecker $depersonalizeChecker
3338
* @param CheckoutSession $checkoutSession
@@ -41,6 +46,19 @@ public function __construct(
4146
$this->checkoutSession = $checkoutSession;
4247
}
4348

49+
/**
50+
* Resolve quote data if the depersonalization is needed.
51+
*
52+
* @param LayoutInterface $subject
53+
* @return void
54+
*/
55+
public function beforeGenerateXml(LayoutInterface $subject)
56+
{
57+
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
58+
$this->quoteId = $this->checkoutSession->getQuoteId();
59+
}
60+
}
61+
4462
/**
4563
* Change sensitive customer data if the depersonalization is needed.
4664
*
@@ -51,6 +69,7 @@ public function afterGenerateElements(LayoutInterface $subject)
5169
{
5270
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
5371
$this->checkoutSession->clearStorage();
72+
$this->checkoutSession->setQuoteId($this->quoteId);
5473
}
5574
}
5675
}

app/code/Magento/Checkout/Test/Unit/Model/Layout/DepersonalizePluginTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class DepersonalizePluginTest extends TestCase
4646
protected function setUp(): void
4747
{
4848
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
49-
$this->checkoutSessionMock = $this->createPartialMock(CheckoutSession::class, ['clearStorage']);
49+
$this->checkoutSessionMock = $this->createPartialMock(
50+
CheckoutSession::class,
51+
['clearStorage', 'setQuoteId', 'getQuoteId']
52+
);
5053
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);
5154

5255
$this->plugin = (new ObjectManagerHelper($this))->getObject(
@@ -70,6 +73,10 @@ public function testAfterGenerateElements(): void
7073
->expects($this->once())
7174
->method('clearStorage')
7275
->willReturnSelf();
76+
$this->checkoutSessionMock
77+
->expects($this->once())
78+
->method('setQuoteId')
79+
->willReturn(1);
7380

7481
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
7582
}
@@ -86,7 +93,43 @@ public function testAfterGenerateElementsNoDepersonalize(): void
8693
->expects($this->never())
8794
->method('clearStorage')
8895
->willReturnSelf();
96+
$this->checkoutSessionMock
97+
->expects($this->never())
98+
->method('setQuoteId')
99+
->willReturn(1);
89100

90101
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
91102
}
103+
104+
/**
105+
* Test beforeGenerateElements method when depersonalization is needed.
106+
*
107+
* @return void
108+
*/
109+
public function testBeforeGenerateXml(): void
110+
{
111+
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
112+
$this->checkoutSessionMock
113+
->expects($this->once())
114+
->method('getQuoteId')
115+
->willReturn(1);
116+
117+
$this->assertEmpty($this->plugin->beforeGenerateXml($this->layoutMock));
118+
}
119+
120+
/**
121+
* Test beforeGenerateElements method when depersonalization is not needed.
122+
*
123+
* @return void
124+
*/
125+
public function testBeforeGenerateXmlNoDepersonalize(): void
126+
{
127+
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
128+
$this->checkoutSessionMock
129+
->expects($this->never())
130+
->method('getQuoteId')
131+
->willReturn(1);
132+
133+
$this->assertEmpty($this->plugin->beforeGenerateXml($this->layoutMock));
134+
}
92135
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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\ConfigurableProduct\Test\Unit\Ui\DataProvider;
9+
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection;
12+
use Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler;
13+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
14+
use Magento\ConfigurableProduct\Ui\DataProvider\Attributes;
15+
use Magento\Framework\DataObject;
16+
use Magento\Framework\DB\Select;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class AttributesTest extends TestCase
20+
{
21+
/**
22+
* @var Collection
23+
*/
24+
private Collection $collectionMock;
25+
26+
/**
27+
* @var Select
28+
*/
29+
private Select $selectMock;
30+
31+
/**
32+
* @var Attributes
33+
*/
34+
private Attributes $attributes;
35+
36+
/**
37+
* @return void
38+
*/
39+
protected function setUp(): void
40+
{
41+
$this->collectionMock = $this->getMockBuilder(Collection::class)
42+
->disableOriginalConstructor()
43+
->getMock();
44+
$this->selectMock = $this->getMockBuilder(Select::class)
45+
->disableOriginalConstructor()
46+
->onlyMethods(['where'])
47+
->getMock();
48+
$collectionAttributeHandlerMock = $this->getMockBuilder(ConfigurableAttributeHandler::class)
49+
->disableOriginalConstructor()
50+
->onlyMethods(['getApplicableAttributes'])
51+
->getMock();
52+
$collectionAttributeHandlerMock->expects($this->once())
53+
->method('getApplicableAttributes')
54+
->willReturn($this->collectionMock);
55+
$this->attributes = new Attributes(
56+
'myName',
57+
'myPrimaryFieldName',
58+
'myRequestFieldName',
59+
$collectionAttributeHandlerMock
60+
);
61+
}
62+
63+
/**
64+
* @return void
65+
*/
66+
public function testGetData()
67+
{
68+
$expectedResult = [
69+
'totalRecords' => 1,
70+
'items' => [
71+
0 => ['attribute' => 'color']
72+
]
73+
];
74+
$this->collectionMock->expects($this->once())
75+
->method('getSelect')
76+
->willReturn($this->selectMock);
77+
$this->selectMock->expects($this->once())
78+
->method('where')
79+
->with('(`apply_to` IS NULL) OR
80+
(
81+
FIND_IN_SET(' .
82+
sprintf("'%s'", Type::TYPE_SIMPLE) . ',
83+
`apply_to`
84+
) AND
85+
FIND_IN_SET(' .
86+
sprintf("'%s'", Type::TYPE_VIRTUAL) . ',
87+
`apply_to`
88+
) AND
89+
FIND_IN_SET(' .
90+
sprintf("'%s'", Configurable::TYPE_CODE) . ',
91+
`apply_to`
92+
)
93+
)')
94+
->willReturnSelf();
95+
$this->collectionMock->expects($this->once())
96+
->method('getItems')
97+
->willReturn([new DataObject(['attribute' => 'color'])]);
98+
$this->collectionMock->expects($this->once())
99+
->method('getSize')
100+
->willReturn(1);
101+
$this->assertEquals($expectedResult, $this->attributes->getData());
102+
}
103+
}

app/code/Magento/ConfigurableProduct/Ui/DataProvider/Attributes.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66

77
namespace Magento\ConfigurableProduct\Ui\DataProvider;
88

9+
use Magento\Catalog\Model\Product\Type;
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
912
class Attributes extends \Magento\Ui\DataProvider\AbstractDataProvider
1013
{
1114
/**
1215
* @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
1316
*/
1417
protected $collection;
1518

16-
/**
17-
* @var \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler
18-
*/
19-
private $configurableAttributeHandler;
20-
2119
/**
2220
* @param string $name
2321
* @param string $primaryFieldName
@@ -35,11 +33,12 @@ public function __construct(
3533
array $data = []
3634
) {
3735
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
38-
$this->configurableAttributeHandler = $configurableAttributeHandler;
3936
$this->collection = $configurableAttributeHandler->getApplicableAttributes();
4037
}
4138

4239
/**
40+
* Getting the product attribute collection.
41+
*
4342
* @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
4443
*/
4544
public function getCollection()
@@ -48,21 +47,33 @@ public function getCollection()
4847
}
4948

5049
/**
51-
* {@inheritdoc}
50+
* @inheritdoc
5251
*/
5352
public function getData()
5453
{
5554
$items = [];
56-
$skippedItems = 0;
55+
$this->getCollection()->getSelect()->where(
56+
'(`apply_to` IS NULL) OR
57+
(
58+
FIND_IN_SET(' .
59+
sprintf("'%s'", Type::TYPE_SIMPLE) . ',
60+
`apply_to`
61+
) AND
62+
FIND_IN_SET(' .
63+
sprintf("'%s'", Type::TYPE_VIRTUAL) . ',
64+
`apply_to`
65+
) AND
66+
FIND_IN_SET(' .
67+
sprintf("'%s'", Configurable::TYPE_CODE) . ',
68+
`apply_to`
69+
)
70+
)'
71+
);
5772
foreach ($this->getCollection()->getItems() as $attribute) {
58-
if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
59-
$items[] = $attribute->toArray();
60-
} else {
61-
$skippedItems++;
62-
}
73+
$items[] = $attribute->toArray();
6374
}
6475
return [
65-
'totalRecords' => $this->collection->getSize() - $skippedItems,
76+
'totalRecords' => $this->collection->getSize(),
6677
'items' => $items
6778
];
6879
}

app/code/Magento/Paypal/Controller/Transparent/Response.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidator;
1919
use Magento\Paypal\Model\Payflow\Transparent;
2020
use Magento\Sales\Api\PaymentFailuresInterface;
21-
use Magento\Checkout\Model\Session;
21+
use Magento\Framework\Session\SessionManager as Session;
2222
use Magento\Framework\App\Action\HttpPostActionInterface;
2323

2424
/**
@@ -28,8 +28,6 @@
2828
class Response extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface, HttpPostActionInterface
2929
{
3030
/**
31-
* Core registry
32-
*
3331
* @var Registry
3432
*/
3533
private $coreRegistry;

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ class Checkout
3030
*
3131
* @var string
3232
*/
33-
const PAL_CACHE_ID = 'paypal_express_checkout_pal';
33+
public const PAL_CACHE_ID = 'paypal_express_checkout_pal';
3434

3535
/**
3636
* Keys for passthrough variables in sales/quote_payment and sales/order_payment
3737
* Uses additional_information as storage
3838
*/
39-
const PAYMENT_INFO_TRANSPORT_TOKEN = 'paypal_express_checkout_token';
40-
const PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN = 'paypal_express_checkout_shipping_overridden';
41-
const PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD = 'paypal_express_checkout_shipping_method';
42-
const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id';
43-
const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required';
44-
const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba';
39+
public const PAYMENT_INFO_TRANSPORT_TOKEN = 'paypal_express_checkout_token';
40+
public const PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN = 'paypal_express_checkout_shipping_overridden';
41+
public const PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD = 'paypal_express_checkout_shipping_method';
42+
public const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id';
43+
public const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required';
44+
public const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba';
4545

4646
/**
4747
* Flag which says that was used PayPal Express Checkout button for checkout
4848
* Uses additional_information as storage
4949
* @var string
5050
*/
51-
const PAYMENT_INFO_BUTTON = 'button';
51+
public const PAYMENT_INFO_BUTTON = 'button';
5252

5353
/**
5454
* @var \Magento\Quote\Model\Quote
@@ -131,8 +131,6 @@ class Checkout
131131
protected $_isBml = false;
132132

133133
/**
134-
* Customer ID
135-
*
136134
* @var int
137135
*/
138136
protected $_customerId;
@@ -145,8 +143,6 @@ class Checkout
145143
protected $_billingAgreement;
146144

147145
/**
148-
* Order
149-
*
150146
* @var \Magento\Sales\Model\Order
151147
*/
152148
protected $_order;
@@ -157,15 +153,11 @@ class Checkout
157153
protected $_configCacheType;
158154

159155
/**
160-
* Checkout data
161-
*
162156
* @var \Magento\Checkout\Helper\Data
163157
*/
164158
protected $_checkoutData;
165159

166160
/**
167-
* Tax data
168-
*
169161
* @var \Magento\Tax\Helper\Data
170162
*/
171163
protected $_taxData;
@@ -1167,6 +1159,8 @@ protected function prepareGuestQuote()
11671159

11681160
$quote->setCustomerId(null)
11691161
->setCustomerEmail($email)
1162+
->setCustomerFirstname($billingAddress->getFirstname())
1163+
->setCustomerLastname($billingAddress->getLastname())
11701164
->setCustomerIsGuest(true)
11711165
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
11721166
return $this;

0 commit comments

Comments
 (0)