Skip to content

Commit c415bfd

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents f6d4a77 + d81b399 commit c415bfd

30 files changed

+1530
-397
lines changed

app/code/Magento/Catalog/Block/Product/View/Gallery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ public function isMainImage($image)
207207
*/
208208
public function getImageAttribute($imageId, $attributeName, $default = null)
209209
{
210-
$attributes =
211-
$this->getConfigView()->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
210+
$attributes = $this->getConfigView()
211+
->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
212212
return $attributes[$attributeName] ?? $default;
213213
}
214214

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Helper;
77

88
use Magento\Framework\App\Helper\AbstractHelper;
9+
use Magento\Framework\View\Element\Block\ArgumentInterface;
910

1011
/**
1112
* Catalog image helper
@@ -14,7 +15,7 @@
1415
* @SuppressWarnings(PHPMD.TooManyFields)
1516
* @since 100.0.2
1617
*/
17-
class Image extends AbstractHelper
18+
class Image extends AbstractHelper implements ArgumentInterface
1819
{
1920
/**
2021
* Media config node
@@ -764,7 +765,7 @@ protected function getImageFile()
764765
protected function parseSize($string)
765766
{
766767
$size = explode('x', strtolower($string));
767-
if (sizeof($size) == 2) {
768+
if (count($size) == 2) {
768769
return ['width' => $size[0] > 0 ? $size[0] : null, 'height' => $size[1] > 0 ? $size[1] : null];
769770
}
770771
return false;

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="Magento_Catalog::product/view/gallery.phtml">
125125
<arguments>
126126
<argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument>
127+
<argument name="imageHelper" xsi:type="object">Magento\Catalog\Helper\Image</argument>
127128
</arguments>
128129
</block>
129130
<container name="skip_gallery_after.wrapper" htmlTag="div" htmlClass="action-skip-wrapper">

app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@
1212
* @var $block \Magento\Catalog\Block\Product\View\Gallery
1313
*/
1414
?>
15+
16+
<?php
17+
$images = $block->getGalleryImages()->getItems();
18+
$mainImage = current(array_filter($images, function ($img) use ($block) {
19+
return $block->isMainImage($img);
20+
}));
21+
22+
if (!empty($images) && empty($mainImage)) {
23+
$mainImage = $block->getGalleryImages()->getFirstItem();
24+
}
25+
26+
$helper = $block->getData('imageHelper');
27+
$mainImageData = $mainImage ?
28+
$mainImage->getData('medium_image_url') :
29+
$helper->getDefaultPlaceholderUrl('image');
30+
31+
?>
32+
1533
<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
16-
<div data-role="loader" class="loading-mask">
17-
<div class="loader">
18-
<img src="<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
19-
alt="<?= /* @escapeNotVerified */ __('Loading...') ?>">
20-
</div>
21-
</div>
34+
<img
35+
alt="main product photo"
36+
class="gallery-placeholder__image"
37+
src="<?= /* @noEscape */ $mainImageData ?>"
38+
/>
2239
</div>
23-
<!--Fix for jumping content. Loader must be the same size as gallery.-->
24-
<script>
25-
var config = {
26-
"width": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'width') ?>,
27-
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
28-
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
29-
"navtype": "<?= /* @escapeNotVerified */ $block->getVar("gallery/navtype") ?>",
30-
"height": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'height') ?>
31-
},
32-
thumbBarHeight = 0,
33-
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];
34-
35-
if (config.navtype === 'horizontal') {
36-
thumbBarHeight = config.thumbheight;
37-
}
3840

39-
loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
40-
</script>
4141
<script type="text/x-magento-init">
4242
{
4343
"[data-gallery-role=gallery-placeholder]": {

app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Quote\Api\CartRepositoryInterface;
1414
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
1515
use Magento\Quote\Model\Quote;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
1819
* Get cart
@@ -29,16 +30,24 @@ class GetCartForUser
2930
*/
3031
private $cartRepository;
3132

33+
/**
34+
* @var StoreManagerInterface
35+
*/
36+
private $storeManager;
37+
3238
/**
3339
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
3440
* @param CartRepositoryInterface $cartRepository
41+
* @param StoreManagerInterface $storeManager
3542
*/
3643
public function __construct(
3744
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
38-
CartRepositoryInterface $cartRepository
45+
CartRepositoryInterface $cartRepository,
46+
StoreManagerInterface $storeManager
3947
) {
4048
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
4149
$this->cartRepository = $cartRepository;
50+
$this->storeManager = $storeManager;
4251
}
4352

4453
/**
@@ -75,6 +84,15 @@ public function execute(string $cartHash, ?int $customerId): Quote
7584
);
7685
}
7786

87+
if ((int)$cart->getStoreId() !== (int)$this->storeManager->getStore()->getId()) {
88+
throw new GraphQlNoSuchEntityException(
89+
__(
90+
'Wrong store code specified for cart "%masked_cart_id"',
91+
['masked_cart_id' => $cartHash]
92+
)
93+
);
94+
}
95+
7896
$cartCustomerId = (int)$cart->getCustomerId();
7997

8098
/* Guest cart, allow operations */

app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Customer\Helper\Address as AddressHelper;
1011
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
@@ -30,28 +31,44 @@ class QuoteAddressFactory
3031
*/
3132
private $getCustomerAddress;
3233

34+
/**
35+
* @var AddressHelper
36+
*/
37+
private $addressHelper;
38+
3339
/**
3440
* @param BaseQuoteAddressFactory $quoteAddressFactory
3541
* @param GetCustomerAddress $getCustomerAddress
42+
* @param AddressHelper $addressHelper
3643
*/
3744
public function __construct(
3845
BaseQuoteAddressFactory $quoteAddressFactory,
39-
GetCustomerAddress $getCustomerAddress
46+
GetCustomerAddress $getCustomerAddress,
47+
AddressHelper $addressHelper
4048
) {
4149
$this->quoteAddressFactory = $quoteAddressFactory;
4250
$this->getCustomerAddress = $getCustomerAddress;
51+
$this->addressHelper = $addressHelper;
4352
}
4453

4554
/**
4655
* Create QuoteAddress based on input data
4756
*
4857
* @param array $addressInput
4958
* @return QuoteAddress
59+
* @throws GraphQlInputException
5060
*/
5161
public function createBasedOnInputData(array $addressInput): QuoteAddress
5262
{
5363
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
5464

65+
$maxAllowedLineCount = $this->addressHelper->getStreetLines();
66+
if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) {
67+
throw new GraphQlInputException(
68+
__('"Street Address" cannot contain more than %1 lines.', $maxAllowedLineCount)
69+
);
70+
}
71+
5572
$quoteAddress = $this->quoteAddressFactory->create();
5673
$quoteAddress->addData($addressInput);
5774
return $quoteAddress;

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Magento\TestFramework\TestCase\GraphQlAbstract;
1414
use Magento\Integration\Api\CustomerTokenServiceInterface;
1515

16+
/**
17+
* Create customer address tests
18+
*/
1619
class CreateCustomerAddressTest extends GraphQlAbstract
1720
{
1821
/**
@@ -198,6 +201,72 @@ public function testCreateCustomerAddressWithMissingAttribute()
198201
$this->graphQlQuery($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
199202
}
200203

204+
/**
205+
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
206+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
207+
*/
208+
public function testCreateCustomerAddressWithRedundantStreetLine()
209+
{
210+
$newAddress = [
211+
'region' => [
212+
'region' => 'Arizona',
213+
'region_id' => 4,
214+
'region_code' => 'AZ'
215+
],
216+
'country_id' => 'US',
217+
'street' => ['Line 1 Street', 'Line 2', 'Line 3'],
218+
'company' => 'Company name',
219+
'telephone' => '123456789',
220+
'fax' => '123123123',
221+
'postcode' => '7777',
222+
'city' => 'City Name',
223+
'firstname' => 'Adam',
224+
'lastname' => 'Phillis',
225+
'middlename' => 'A',
226+
'prefix' => 'Mr.',
227+
'suffix' => 'Jr.',
228+
'vat_id' => '1',
229+
'default_shipping' => true,
230+
'default_billing' => false
231+
];
232+
233+
$mutation
234+
= <<<MUTATION
235+
mutation {
236+
createCustomerAddress(input: {
237+
region: {
238+
region: "{$newAddress['region']['region']}"
239+
region_id: {$newAddress['region']['region_id']}
240+
region_code: "{$newAddress['region']['region_code']}"
241+
}
242+
country_id: {$newAddress['country_id']}
243+
street: ["{$newAddress['street'][0]}","{$newAddress['street'][1]}","{$newAddress['street'][2]}"]
244+
company: "{$newAddress['company']}"
245+
telephone: "{$newAddress['telephone']}"
246+
fax: "{$newAddress['fax']}"
247+
postcode: "{$newAddress['postcode']}"
248+
city: "{$newAddress['city']}"
249+
firstname: "{$newAddress['firstname']}"
250+
lastname: "{$newAddress['lastname']}"
251+
middlename: "{$newAddress['middlename']}"
252+
prefix: "{$newAddress['prefix']}"
253+
suffix: "{$newAddress['suffix']}"
254+
vat_id: "{$newAddress['vat_id']}"
255+
default_shipping: true
256+
default_billing: false
257+
}) {
258+
id
259+
}
260+
}
261+
MUTATION;
262+
263+
$userName = 'customer@example.com';
264+
$password = 'password';
265+
266+
self::expectExceptionMessage('"Street Address" cannot contain more than 2 lines.');
267+
$this->graphQlQuery($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
268+
}
269+
201270
/**
202271
* Verify the fields for Customer address
203272
*

0 commit comments

Comments
 (0)