Skip to content

Commit

Permalink
[EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored Apr 9, 2019
2 parents f6d4a77 + d81b399 commit c415bfd
Show file tree
Hide file tree
Showing 30 changed files with 1,530 additions and 397 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public function isMainImage($image)
*/
public function getImageAttribute($imageId, $attributeName, $default = null)
{
$attributes =
$this->getConfigView()->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
$attributes = $this->getConfigView()
->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
return $attributes[$attributeName] ?? $default;
}

Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Catalog image helper
Expand All @@ -14,7 +15,7 @@
* @SuppressWarnings(PHPMD.TooManyFields)
* @since 100.0.2
*/
class Image extends AbstractHelper
class Image extends AbstractHelper implements ArgumentInterface
{
/**
* Media config node
Expand Down Expand Up @@ -764,7 +765,7 @@ protected function getImageFile()
protected function parseSize($string)
{
$size = explode('x', strtolower($string));
if (sizeof($size) == 2) {
if (count($size) == 2) {
return ['width' => $size[0] > 0 ? $size[0] : null, 'height' => $size[1] > 0 ? $size[1] : null];
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="Magento_Catalog::product/view/gallery.phtml">
<arguments>
<argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument>
<argument name="imageHelper" xsi:type="object">Magento\Catalog\Helper\Image</argument>
</arguments>
</block>
<container name="skip_gallery_after.wrapper" htmlTag="div" htmlClass="action-skip-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
* @var $block \Magento\Catalog\Block\Product\View\Gallery
*/
?>

<?php
$images = $block->getGalleryImages()->getItems();
$mainImage = current(array_filter($images, function ($img) use ($block) {
return $block->isMainImage($img);
}));

if (!empty($images) && empty($mainImage)) {
$mainImage = $block->getGalleryImages()->getFirstItem();
}

$helper = $block->getData('imageHelper');
$mainImageData = $mainImage ?
$mainImage->getData('medium_image_url') :
$helper->getDefaultPlaceholderUrl('image');

?>

<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
<div data-role="loader" class="loading-mask">
<div class="loader">
<img src="<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
alt="<?= /* @escapeNotVerified */ __('Loading...') ?>">
</div>
</div>
<img
alt="main product photo"
class="gallery-placeholder__image"
src="<?= /* @noEscape */ $mainImageData ?>"
/>
</div>
<!--Fix for jumping content. Loader must be the same size as gallery.-->
<script>
var config = {
"width": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'width') ?>,
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
"navtype": "<?= /* @escapeNotVerified */ $block->getVar("gallery/navtype") ?>",
"height": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'height') ?>
},
thumbBarHeight = 0,
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];

if (config.navtype === 'horizontal') {
thumbBarHeight = config.thumbheight;
}

loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
</script>
<script type="text/x-magento-init">
{
"[data-gallery-role=gallery-placeholder]": {
Expand Down
20 changes: 19 additions & 1 deletion app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
use Magento\Quote\Model\Quote;
use Magento\Store\Model\StoreManagerInterface;

/**
* Get cart
Expand All @@ -29,16 +30,24 @@ class GetCartForUser
*/
private $cartRepository;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
* @param CartRepositoryInterface $cartRepository
* @param StoreManagerInterface $storeManager
*/
public function __construct(
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
CartRepositoryInterface $cartRepository
CartRepositoryInterface $cartRepository,
StoreManagerInterface $storeManager
) {
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
$this->cartRepository = $cartRepository;
$this->storeManager = $storeManager;
}

/**
Expand Down Expand Up @@ -75,6 +84,15 @@ public function execute(string $cartHash, ?int $customerId): Quote
);
}

if ((int)$cart->getStoreId() !== (int)$this->storeManager->getStore()->getId()) {
throw new GraphQlNoSuchEntityException(
__(
'Wrong store code specified for cart "%masked_cart_id"',
['masked_cart_id' => $cartHash]
)
);
}

$cartCustomerId = (int)$cart->getCustomerId();

/* Guest cart, allow operations */
Expand Down
19 changes: 18 additions & 1 deletion app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Customer\Helper\Address as AddressHelper;
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
Expand All @@ -30,28 +31,44 @@ class QuoteAddressFactory
*/
private $getCustomerAddress;

/**
* @var AddressHelper
*/
private $addressHelper;

/**
* @param BaseQuoteAddressFactory $quoteAddressFactory
* @param GetCustomerAddress $getCustomerAddress
* @param AddressHelper $addressHelper
*/
public function __construct(
BaseQuoteAddressFactory $quoteAddressFactory,
GetCustomerAddress $getCustomerAddress
GetCustomerAddress $getCustomerAddress,
AddressHelper $addressHelper
) {
$this->quoteAddressFactory = $quoteAddressFactory;
$this->getCustomerAddress = $getCustomerAddress;
$this->addressHelper = $addressHelper;
}

/**
* Create QuoteAddress based on input data
*
* @param array $addressInput
* @return QuoteAddress
* @throws GraphQlInputException
*/
public function createBasedOnInputData(array $addressInput): QuoteAddress
{
$addressInput['country_id'] = $addressInput['country_code'] ?? '';

$maxAllowedLineCount = $this->addressHelper->getStreetLines();
if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) {
throw new GraphQlInputException(
__('"Street Address" cannot contain more than %1 lines.', $maxAllowedLineCount)
);
}

$quoteAddress = $this->quoteAddressFactory->create();
$quoteAddress->addData($addressInput);
return $quoteAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Integration\Api\CustomerTokenServiceInterface;

/**
* Create customer address tests
*/
class CreateCustomerAddressTest extends GraphQlAbstract
{
/**
Expand Down Expand Up @@ -198,6 +201,72 @@ public function testCreateCustomerAddressWithMissingAttribute()
$this->graphQlQuery($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testCreateCustomerAddressWithRedundantStreetLine()
{
$newAddress = [
'region' => [
'region' => 'Arizona',
'region_id' => 4,
'region_code' => 'AZ'
],
'country_id' => 'US',
'street' => ['Line 1 Street', 'Line 2', 'Line 3'],
'company' => 'Company name',
'telephone' => '123456789',
'fax' => '123123123',
'postcode' => '7777',
'city' => 'City Name',
'firstname' => 'Adam',
'lastname' => 'Phillis',
'middlename' => 'A',
'prefix' => 'Mr.',
'suffix' => 'Jr.',
'vat_id' => '1',
'default_shipping' => true,
'default_billing' => false
];

$mutation
= <<<MUTATION
mutation {
createCustomerAddress(input: {
region: {
region: "{$newAddress['region']['region']}"
region_id: {$newAddress['region']['region_id']}
region_code: "{$newAddress['region']['region_code']}"
}
country_id: {$newAddress['country_id']}
street: ["{$newAddress['street'][0]}","{$newAddress['street'][1]}","{$newAddress['street'][2]}"]
company: "{$newAddress['company']}"
telephone: "{$newAddress['telephone']}"
fax: "{$newAddress['fax']}"
postcode: "{$newAddress['postcode']}"
city: "{$newAddress['city']}"
firstname: "{$newAddress['firstname']}"
lastname: "{$newAddress['lastname']}"
middlename: "{$newAddress['middlename']}"
prefix: "{$newAddress['prefix']}"
suffix: "{$newAddress['suffix']}"
vat_id: "{$newAddress['vat_id']}"
default_shipping: true
default_billing: false
}) {
id
}
}
MUTATION;

$userName = 'customer@example.com';
$password = 'password';

self::expectExceptionMessage('"Street Address" cannot contain more than 2 lines.');
$this->graphQlQuery($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
}

/**
* Verify the fields for Customer address
*
Expand Down
Loading

0 comments on commit c415bfd

Please sign in to comment.