Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3-develop' into recheck-129-re…
Browse files Browse the repository at this point in the history
…trive-customer-token
  • Loading branch information
Valeriy Nayda committed Sep 17, 2018
2 parents 277fe08 + ca42048 commit 5dce3bd
Show file tree
Hide file tree
Showing 170 changed files with 4,565 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Backend" >
<module name="Magento_Backend">
<sequence>
<module name="Magento_Directory"/>
</sequence>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function __construct(Config $config, ResolverInterface $resolver)
*/
public function getConfig()
{
$requireBillingAddressAll = \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;

return [
'payment' => [
self::PAYPAL_CODE => [
Expand All @@ -60,6 +62,8 @@ public function getConfig()
'vaultCode' => self::PAYPAL_VAULT_CODE,
'skipOrderReview' => $this->config->isSkipOrderReview(),
'paymentIcon' => $this->config->getPayPalIcon(),
'isRequiredBillingAddress' =>
(int)$this->config->isRequiredBillingAddress() === $requireBillingAddressAll
]
]
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function testGetConfig($expected)
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
]);

$this->config->method('isRequiredBillingAddress')
->willReturn(1);

self::assertEquals($expected, $this->configProvider->getConfig());
}

Expand All @@ -101,7 +104,8 @@ public function getConfigDataProvider()
'skipOrderReview' => false,
'paymentIcon' => [
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
]
],
'isRequiredBillingAddress' => true
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ define([
beforePlaceOrder: function (data) {
this.setPaymentMethodNonce(data.nonce);

if (quote.billingAddress() === null && typeof data.details.billingAddress !== 'undefined') {
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null) &&
typeof data.details.billingAddress !== 'undefined'
) {
this.setBillingAddress(data.details, data.details.billingAddress);
}

Expand Down Expand Up @@ -264,6 +266,14 @@ define([
return window.checkoutConfig.payment[this.getCode()].isAllowShippingAddressOverride;
},

/**
* Is billing address required from PayPal side
* @returns {Boolean}
*/
isRequiredBillingAddress: function () {
return window.checkoutConfig.payment[this.getCode()].isRequiredBillingAddress;
},

/**
* Get configuration for PayPal
* @returns {Object}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
*/
private $catalogRuleProcessor;

/**
* @var array
*/
private $optionsPosition = [];

/**
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
Expand Down Expand Up @@ -86,6 +91,8 @@ public function __construct(
}

/**
* Return catalog rule processor or creates processor if it does not exist
*
* @deprecated 100.2.0
* @return \Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor
*/
Expand All @@ -101,6 +108,7 @@ private function getCatalogRuleProcessor()

/**
* Returns the bundle product options
*
* Will return cached options data if the product options are already initialized
* In a case when $stripSelection parameter is true will reload stored bundle selections collection from DB
*
Expand Down Expand Up @@ -135,6 +143,8 @@ public function getOptions($stripSelection = false)
}

/**
* Return true if product has options
*
* @return bool
*/
public function hasOptions()
Expand All @@ -150,7 +160,6 @@ public function hasOptions()
* Returns JSON encoded config to be used in JS scripts
*
* @return string
*
*/
public function getJsonConfig()
{
Expand All @@ -172,6 +181,7 @@ public function getJsonConfig()
}
$optionId = $optionItem->getId();
$options[$optionId] = $this->getOptionItemData($optionItem, $currentProduct, $position);
$this->optionsPosition[$position] = $optionId;

// Add attribute default value (if set)
if ($preConfiguredFlag) {
Expand Down Expand Up @@ -370,6 +380,7 @@ private function getConfigData(Product $product, array $options)
$config = [
'options' => $options,
'selected' => $this->selectedOptions,
'positions' => $this->optionsPosition,
'bundleId' => $product->getId(),
'priceFormat' => $this->localeFormat->getPriceFormat(),
'prices' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public function testGetJsonConfigFixedPriceBundle()
$this->assertEquals(110, $jsonConfig['prices']['oldPrice']['amount']);
$this->assertEquals(100, $jsonConfig['prices']['basePrice']['amount']);
$this->assertEquals(100, $jsonConfig['prices']['finalPrice']['amount']);
$this->assertEquals([1], $jsonConfig['positions']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ define([

// Clear Summary box
this.element.html('');

$.each(this.cache.currentElement.selected, $.proxy(this._renderOption, this));
this.cache.currentElement.positions.forEach(function (optionId) {
this._renderOption(optionId, this.cache.currentElement.selected[optionId]);
}, this);
this.element
.parents(this.options.bundleSummaryContainer)
.toggleClass('empty', !this.cache.currentElementCount); // Zero elements equal '.empty' container
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Magento\Framework\Stdlib\ArrayUtils;

/**
* Product gallery block
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -139,7 +141,7 @@ public function getGalleryImagesJson()
'thumb' => $image->getData('small_image_url'),
'img' => $image->getData('medium_image_url'),
'full' => $image->getData('large_image_url'),
'caption' => $image->getData('label'),
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
'position' => $image->getData('position'),
'isMain' => $this->isMainImage($image),
'type' => str_replace('external-', '', $image->getMediaType()),
Expand Down Expand Up @@ -196,6 +198,8 @@ public function isMainImage($image)
}

/**
* Returns image attribute
*
* @param string $imageId
* @param string $attributeName
* @param string $default
Expand All @@ -222,6 +226,8 @@ private function getConfigView()
}

/**
* Returns image gallery config object
*
* @return Collection
*/
private function getGalleryImagesConfig()
Expand Down
39 changes: 27 additions & 12 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
*/
private $storeManager;

/**
* @var \Magento\Framework\Escaper|null
*/
private $escaper;

/**
* @var null|\Psr\Log\LoggerInterface
*/
private $logger;

/**
* Save constructor.
*
Expand All @@ -63,20 +73,26 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
* @param \Magento\Catalog\Model\Product\Copier $productCopier
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Framework\Escaper|null $escaper
* @param \Psr\Log\LoggerInterface|null $logger
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Product\Builder $productBuilder,
Initialization\Helper $initializationHelper,
\Magento\Catalog\Model\Product\Copier $productCopier,
\Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Framework\Escaper $escaper = null,
\Psr\Log\LoggerInterface $logger = null
) {
$this->initializationHelper = $initializationHelper;
$this->productCopier = $productCopier;
$this->productTypeManager = $productTypeManager;
$this->productRepository = $productRepository;
parent::__construct($context, $productBuilder);
$this->escaper = $escaper ?? $this->_objectManager->get(\Magento\Framework\Escaper::class);
$this->logger = $logger ?? $this->_objectManager->get(\Psr\Log\LoggerInterface::class);
}

/**
Expand All @@ -103,14 +119,14 @@ public function execute()
$this->productBuilder->build($this->getRequest())
);
$this->productTypeManager->processProduct($product);

if (isset($data['product'][$product->getIdFieldName()])) {
throw new \Magento\Framework\Exception\LocalizedException(
__('The product was unable to be saved. Please try again.')
);
}

$originalSku = $product->getSku();
$canSaveCustomOptions = $product->getCanSaveCustomOptions();
$product->save();
$this->handleImageRemoveError($data, $product->getId());
$this->getCategoryLinkManagement()->assignProductToCategories(
Expand All @@ -120,20 +136,17 @@ public function execute()
$productId = $product->getEntityId();
$productAttributeSetId = $product->getAttributeSetId();
$productTypeId = $product->getTypeId();

$this->copyToStores($data, $productId);
$extendedData = $data;
$extendedData['can_save_custom_options'] = $canSaveCustomOptions;
$this->copyToStores($extendedData, $productId);
$this->messageManager->addSuccessMessage(__('You saved the product.'));
$this->getDataPersistor()->clear('catalog_product');
if ($product->getSku() != $originalSku) {
$this->messageManager->addNoticeMessage(
__(
'SKU for product %1 has been changed to %2.',
$this->_objectManager->get(
\Magento\Framework\Escaper::class
)->escapeHtml($product->getName()),
$this->_objectManager->get(
\Magento\Framework\Escaper::class
)->escapeHtml($product->getSku())
$this->escaper->escapeHtml($product->getName()),
$this->escaper->escapeHtml($product->getSku())
)
);
}
Expand All @@ -143,17 +156,18 @@ public function execute()
);

if ($redirectBack === 'duplicate') {
$product->unsetData('quantity_and_stock_status');
$newProduct = $this->productCopier->copy($product);
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->logger->critical($e);
$this->messageManager->addExceptionMessage($e);
$data = isset($product) ? $this->persistMediaData($product, $data) : $data;
$this->getDataPersistor()->set('catalog_product', $data);
$redirectBack = $productId ? true : 'new';
} catch (\Exception $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->logger->critical($e);
$this->messageManager->addErrorMessage($e->getMessage());
$data = isset($product) ? $this->persistMediaData($product, $data) : $data;
$this->getDataPersistor()->set('catalog_product', $data);
Expand Down Expand Up @@ -242,6 +256,7 @@ protected function copyToStores($data, $productId)
->setStoreId($copyFrom)
->load($productId)
->setStoreId($copyTo)
->setCanSaveCustomOptions($data['can_save_custom_options'])
->setCopyFromView(true)
->save();
}
Expand Down
Loading

0 comments on commit 5dce3bd

Please sign in to comment.