Skip to content

Commit

Permalink
Merge pull request #1 from magento/2.2-develop
Browse files Browse the repository at this point in the history
Update 2.2 develop branch
  • Loading branch information
ansari-ziyaurrahman authored Nov 29, 2018
2 parents 32a7c4b + 899e950 commit 99dbb54
Show file tree
Hide file tree
Showing 59 changed files with 910 additions and 142 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ atlassian*
/.php_cs
/.php_cs.cache
/grunt-config.json
/dev/tools/grunt/configs/local-themes.js

/pub/media/*.*
!/pub/media/.htaccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
define([
'jquery',
'underscore',
'mage/utils/wrapper',
'Magento_Checkout/js/view/payment/default',
'Magento_Braintree/js/view/payment/adapter',
'Magento_Checkout/js/model/quote',
Expand All @@ -19,7 +18,6 @@ define([
], function (
$,
_,
wrapper,
Component,
Braintree,
quote,
Expand Down Expand Up @@ -105,6 +103,12 @@ define([
}
});

quote.shippingAddress.subscribe(function () {
if (self.isActive()) {
self.reInitPayPal();
}
});

// for each component initialization need update property
this.isReviewRequired(false);
this.initClientConfig();
Expand Down Expand Up @@ -222,9 +226,8 @@ define([

/**
* Re-init PayPal Auth Flow
* @param {Function} callback - Optional callback
*/
reInitPayPal: function (callback) {
reInitPayPal: function () {
if (Braintree.checkout) {
Braintree.checkout.teardown(function () {
Braintree.checkout = null;
Expand All @@ -235,17 +238,6 @@ define([
this.clientConfig.paypal.amount = this.grandTotalAmount;
this.clientConfig.paypal.shippingAddressOverride = this.getShippingAddress();

if (callback) {
this.clientConfig.onReady = wrapper.wrap(
this.clientConfig.onReady,
function (original, checkout) {
this.clientConfig.onReady = original;
original(checkout);
callback();
}.bind(this)
);
}

Braintree.setConfig(this.clientConfig);
Braintree.setup();
},
Expand Down Expand Up @@ -429,19 +421,17 @@ define([
* Triggers when customer click "Continue to PayPal" button
*/
payWithPayPal: function () {
this.reInitPayPal(function () {
if (!additionalValidators.validate()) {
return;
}
if (!additionalValidators.validate()) {
return;
}

try {
Braintree.checkout.paypal.initAuthFlow();
} catch (e) {
this.messageContainer.addErrorMessage({
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
});
}
}.bind(this));
try {
Braintree.checkout.paypal.initAuthFlow();
} catch (e) {
this.messageContainer.addErrorMessage({
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
});
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Crosssell extends \Magento\Catalog\Block\Product\AbstractProduct
*/
protected function _prepareData()
{
$product = $this->_coreRegistry->registry('product');
$product = $this->getProduct();
/* @var $product \Magento\Catalog\Model\Product */

$this->_itemCollection = $product->getCrossSellProductCollection()->addAttributeToSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
*/
protected function _prepareData()
{
$product = $this->_coreRegistry->registry('product');
$product = $this->getProduct();
/* @var $product \Magento\Catalog\Model\Product */

$this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __construct(
*/
protected function _prepareData()
{
$product = $this->_coreRegistry->registry('product');
$product = $this->getProduct();
/* @var $product \Magento\Catalog\Model\Product */
$this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter();
if ($this->moduleManager->isEnabled('Magento_Checkout')) {
Expand Down
8 changes: 8 additions & 0 deletions app/code/Magento/Catalog/Controller/Product/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,12 @@ public function setCustomerId($customerId)
$this->_customerId = $customerId;
return $this;
}

/**
* @inheritdoc
*/
public function execute()
{
return $this->resultRedirectFactory->create()->setPath('catalog/product_compare');
}
}
39 changes: 34 additions & 5 deletions app/code/Magento/Catalog/Model/Product/Gallery/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
namespace Magento\Catalog\Model\Product\Gallery;

use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\App\ObjectManager;

/**
* Catalog product Media Gallery attribute processor.
Expand Down Expand Up @@ -55,28 +56,39 @@ class Processor
*/
protected $resourceModel;

/**
* @var \Magento\Framework\File\Mime
*/
private $mime;

/**
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
* @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel
* @param \Magento\Framework\File\Mime|null $mime
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function __construct(
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository,
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb,
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
\Magento\Framework\Filesystem $filesystem,
\Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel
\Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel,
\Magento\Framework\File\Mime $mime = null
) {
$this->attributeRepository = $attributeRepository;
$this->fileStorageDb = $fileStorageDb;
$this->mediaConfig = $mediaConfig;
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->resourceModel = $resourceModel;
$this->mime = $mime ?: ObjectManager::getInstance()->get(\Magento\Framework\File\Mime::class);
}

/**
* Return media_gallery attribute
*
* @return \Magento\Catalog\Api\Data\ProductAttributeInterface
* @since 101.0.0
*/
Expand Down Expand Up @@ -178,6 +190,13 @@ public function addImage(
$attrCode = $this->getAttribute()->getAttributeCode();
$mediaGalleryData = $product->getData($attrCode);
$position = 0;

$absoluteFilePath = $this->mediaDirectory->getAbsolutePath($file);
$imageMimeType = $this->mime->getMimeType($absoluteFilePath);
$imageContent = $this->mediaDirectory->readFile($absoluteFilePath);
$imageBase64 = base64_encode($imageContent);
$imageName = $pathinfo['filename'];

if (!is_array($mediaGalleryData)) {
$mediaGalleryData = ['images' => []];
}
Expand All @@ -192,9 +211,17 @@ public function addImage(
$mediaGalleryData['images'][] = [
'file' => $fileName,
'position' => $position,
'media_type' => 'image',
'label' => '',
'disabled' => (int)$exclude,
'media_type' => 'image',
'types' => $mediaAttribute,
'content' => [
'data' => [
ImageContentInterface::NAME => $imageName,
ImageContentInterface::BASE64_ENCODED_DATA => $imageBase64,
ImageContentInterface::TYPE => $imageMimeType,
]
]
];

$product->setData($attrCode, $mediaGalleryData);
Expand Down Expand Up @@ -353,7 +380,8 @@ public function setMediaAttribute(\Magento\Catalog\Model\Product $product, $medi
}

/**
* get media attribute codes
* Get media attribute codes
*
* @return array
* @since 101.0.0
*/
Expand All @@ -363,6 +391,8 @@ public function getMediaAttributeCodes()
}

/**
* Trim .tmp ending from filename
*
* @param string $file
* @return string
* @since 101.0.0
Expand Down Expand Up @@ -484,7 +514,6 @@ public function getAffectedFields($object)
/**
* Attribute value is not to be saved in a conventional way, separate table is used to store the complex value
*
* {@inheritdoc}
* @since 101.0.0
*/
public function isScalar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
</section>
<section name="AdminModifyAttributesSection">
<!-- Parameter is the attribute name -->
<element name="dropDownAttributeByName" type="select" selector="//*[text()='{{attributeName}}']/../..//select" parameterized="true"/>
<element name="dropDownAttributeByName" type="select" selector="//*[text()='{{attributeName}}']/../../..//select" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<element name="useDefaultOptionTitle" type="text" selector="[data-index='options'] tr.data-row [data-index='title'] [name^='options_use_default']"/>
<element name="useDefaultOptionValueTitleByIndex" type="text" selector="[data-index='options'] [data-index='values'] tr[data-repeat-index='{{var1}}'] [name^='options_use_default']" parameterized="true"/>
<element name="addOptionBtn" type="button" selector="button[data-index='button_add']"/>
<element name="fillOptionTitle" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//label[text()='Option Title']/parent::span/parent::div//input[@class='admin__control-text']" parameterized="true"/>
<element name="checkSelect" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//label[text()='Option Type']/parent::span/parent::div//div[@data-role='selected-option']" parameterized="true"/>
<element name="checkDropDown" type="select" selector="//span[text()='{{var1}}']/ancestor::div[@class='fieldset-wrapper-title']/following-sibling::div[@data-role='collapsible-content']//div[@data-index='type']//div[contains(@class, 'action-menu')]//li[@class='admin__action-multiselect-menu-inner-item']//label[text()='Drop-down']" parameterized="true"/>
<element name="fillOptionTitle" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//span[text()='Option Title']/parent::label/parent::div/parent::div//input[@class='admin__control-text']" parameterized="true"/>
<element name="checkSelect" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//span[text()='Option Type']/parent::label/parent::div/parent::div//div[@data-role='selected-option']" parameterized="true"/>
<element name="checkDropDown" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//parent::label/parent::div/parent::div//li[@class='admin__action-multiselect-menu-inner-item']//label[text()='Drop-down']" parameterized="true"/>
<element name="clickAddValue" type="button" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tfoot//button" parameterized="true"/>
<element name="fillOptionValueTitle" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody/tr[@data-repeat-index='{{var2}}']//label[text()='Title']/parent::span/parent::div//div[@class='admin__field-control']/input" parameterized="true"/>
<element name="fillOptionValueTitle" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody/tr[@data-repeat-index='{{var2}}']//span[text()='Title']/parent::label/parent::div/parent::div//div[@class='admin__field-control']/input" parameterized="true"/>
<element name="fillOptionValuePrice" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody/tr[@data-repeat-index='{{var2}}']//span[text()='Price']/parent::label/parent::div//div[@class='admin__control-addon']/input" parameterized="true"/>
<element name="clickSelectPriceType" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody//tr[@data-repeat-index='{{var2}}']//label[text()='Price Type']/parent::span/parent::div//select" parameterized="true"/>
<element name="clickSelectPriceType" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody//tr[@data-repeat-index='{{var2}}']//span[text()='Price Type']/parent::label/parent::div/parent::div//select" parameterized="true"/>
<!-- Elements that make it easier to select the most recently added element -->
<element name="lastOptionTitle" type="input" selector="//*[@data-index='custom_options']//*[@data-index='options']/tbody/tr[last()]//*[contains(@class, '_required')]//input" />
<element name="lastOptionTypeParent" type="block" selector="//*[@data-index='custom_options']//*[@data-index='options']/tbody/tr[last()]//*[contains(@class, 'admin__action-multiselect-text')]" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
<element name="enableProductAttributeLabel" type="text" selector="[data-index='status'] .admin__field-label label"/>
<element name="enableProductAttributeLabelWrapper" type="text" selector="[data-index='status'] .admin__field-label"/>
<element name="enableProductAttributeLabel" type="text" selector="//span[text()='Enable Product']/parent::label"/>
<element name="enableProductAttributeLabelWrapper" type="text" selector="//span[text()='Enable Product']/parent::label/parent::div"/>
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
Expand All @@ -33,7 +33,7 @@
<element name="visibilityUseDefault" type="checkbox" selector="//input[@name='use_default[visibility]']"/>
<element name="divByDataIndex" type="input" selector="div[data-index='{{var}}']" parameterized="true"/>
<element name="attributeSetSearchCount" type="text" selector="div[data-index='attribute_set_id'] .admin__action-multiselect-search-count"/>
<element name="attributeLabelByText" type="text" selector="//*[@class='admin__field']//label[text()='{{attributeLabel}}']" parameterized="true"/>
<element name="attributeLabelByText" type="text" selector="//*[@class='admin__field']//span[text()='{{attributeLabel}}']" parameterized="true"/>
<element name="addAttributeBtn" type="button" selector="#addAttribute"/>
<element name="attributeSetFilterResultByName" type="text" selector="//label/span[text() = '{{var}}']" timeout="30" parameterized="true"/>
<element name="attributeSetDropDown" type="select" selector="div[data-index='attribute_set_id'] .action-select.admin__action-multiselect"/>
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Catalog/view/base/web/js/price-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ define([
pricesCode = [],
priceValue, origin, finalPrice;

this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
if (typeof newPrices !== 'undefined' && newPrices.hasOwnProperty('prices')) {
this.cache.additionalPriceObject = {};
} else {
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
}

if (newPrices) {
$.extend(this.cache.additionalPriceObject, newPrices);
Expand Down
31 changes: 28 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
*/
const COL_NAME = 'name';

/**
* Column new_from_date.
*/
const COL_NEW_FROM_DATE = 'new_from_date';

/**
* Column new_to_date.
*/
const COL_NEW_TO_DATE = 'new_to_date';

/**
* Column product website.
*/
Expand Down Expand Up @@ -292,7 +302,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually'
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually',
ValidatorInterface::ERROR_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
];

/**
Expand All @@ -313,8 +324,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
Product::COL_TYPE => 'product_type',
Product::COL_PRODUCT_WEBSITES => 'product_websites',
'status' => 'product_online',
'news_from_date' => 'new_from_date',
'news_to_date' => 'new_to_date',
'news_from_date' => self::COL_NEW_FROM_DATE,
'news_to_date' => self::COL_NEW_TO_DATE,
'options_container' => 'display_product_options_in',
'minimal_price' => 'map_price',
'msrp' => 'msrp_price',
Expand Down Expand Up @@ -2477,6 +2488,20 @@ public function validateRow(array $rowData, $rowNum)
}
}
}

if (!empty($rowData[self::COL_NEW_FROM_DATE]) && !empty($rowData[self::COL_NEW_TO_DATE])
) {
$newFromTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_FROM_DATE], false));
$newToTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_TO_DATE], false));
if ($newFromTimestamp > $newToTimestamp) {
$this->addRowError(
ValidatorInterface::ERROR_NEW_TO_DATE,
$rowNum,
$rowData[self::COL_NEW_TO_DATE]
);
}
}

return !$this->getErrorAggregator()->isRowInvalid($rowNum);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn

const ERROR_DUPLICATE_URL_KEY = 'duplicatedUrlKey';

const ERROR_NEW_TO_DATE = 'invalidNewToDateValue';

/**
* Value that means all entities (e.g. websites, groups etc.)
*/
Expand Down
Loading

0 comments on commit 99dbb54

Please sign in to comment.