Skip to content

Commit

Permalink
Merge remote-tracking branch 'pub/develop' into MAGETWO-66799
Browse files Browse the repository at this point in the history
  • Loading branch information
vkorotun committed Apr 1, 2017
2 parents 70502d6 + 26fd5fb commit f892baf
Show file tree
Hide file tree
Showing 27 changed files with 573 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,10 @@ private function updateAddressData(Address $address, array $addressData)
$address->setRegionCode($addressData['region']);
$address->setCountryId($addressData['countryCodeAlpha2']);
$address->setPostcode($addressData['postalCode']);

// PayPal's address supposes not saving against customer account
$address->setSaveInAddressBook(false);
$address->setSameAsBilling(false);
$address->setCustomerAddressId(null);
}
}
8 changes: 5 additions & 3 deletions app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct,

foreach ($selectionPriceList as $selectionPrice) {
++$i;
$amountList[$i]['amount'] = $selectionPrice->getAmount();
// always honor the quantity given
$amountList[$i]['quantity'] = $selectionPrice->getQuantity();
if ($selectionPrice) {
$amountList[$i]['amount'] = $selectionPrice->getAmount();
// always honor the quantity given
$amountList[$i]['quantity'] = $selectionPrice->getQuantity();
}
}

/** @var Store $store */
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function getDuplicateUrl()
}

/**
* @deprecated
* @return string
*/
public function getHeader()
Expand Down
25 changes: 0 additions & 25 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function execute()
$productTypeId = $this->getRequest()->getParam('type');
if ($data) {
try {
$this->unserializeProductData($data);
$product = $this->initializationHelper->initialize(
$this->productBuilder->build($this->getRequest())
);
Expand Down Expand Up @@ -181,30 +180,6 @@ public function execute()
return $resultRedirect;
}

/**
* Unserialize product data for configurable products
*
* @param array $postData
* @return void
*/
private function unserializeProductData($postData)
{
if (isset($postData["configurable-matrix-serialized"])) {
$configurableMatrixSerialized = $postData["configurable-matrix-serialized"];
if ($configurableMatrixSerialized != null && !empty($configurableMatrixSerialized)) {
$postData["configurable-matrix"] = json_decode($configurableMatrixSerialized, true);
unset($postData["configurable-matrix-serialized"]);
}
}
if (isset($postData["associated_product_ids_serialized"])) {
$associatedProductIdsSerialized = $postData["associated_product_ids_serialized"];
if ($associatedProductIdsSerialized != null && !empty($associatedProductIdsSerialized)) {
$postData["associated_product_ids"] = json_decode($associatedProductIdsSerialized, true);
unset($postData["associated_product_ids_serialized"]);
}
}
}

/**
* Notify customer when image was not deleted in specific case.
* TODO: temporary workaround must be eliminated in MAGETWO-45306
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,10 @@ public function getIsActiveAttributeId()
*/
public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
{
// @codingStandardsIgnoreStart
$serializeData = $this->serializer->serialize($entityIdsFilter);
$entityIdsFilterHash = md5($serializeData);
// @codingStandardsIgnoreEnd

if (!isset($this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue])) {
$linkField = $this->getLinkField();
Expand Down Expand Up @@ -767,7 +769,6 @@ public function getChildren($category, $recursive = true)
$backendTable = $this->getTable([$this->getEntityTablePrefix(), 'int']);
$connection = $this->getConnection();
$checkSql = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
$linkField = $this->getLinkField();
$bind = [
'attribute_id' => $attributeId,
'store_id' => $category->getStoreId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,7 @@ define([
* Chose action for the form save button
*/
saveFormHandler: function () {
this.source.data['configurable-matrix-serialized'] =
JSON.stringify(this.source.data['configurable-matrix']);
delete this.source.data['configurable-matrix'];
this.source.data['associated_product_ids_serialized'] =
JSON.stringify(this.source.data['associated_product_ids']);
delete this.source.data['associated_product_ids'];
this.serializeData();

if (this.checkForNewAttributes()) {
this.formSaveParams = arguments;
Expand All @@ -398,6 +393,31 @@ define([
}
},

/**
* Serialize data for specific form fields
*
* Get data from outdated fields, serialize it and produce new form fields.
*
* Outdated fields:
* - configurable-matrix;
* - associated_product_ids.
*
* New fields:
* - configurable-matrix-serialized;
* - associated_product_ids_serialized.
*/
serializeData: function () {
this.source.data['configurable-matrix-serialized'] =
JSON.stringify(this.source.data['configurable-matrix']);

delete this.source.data['configurable-matrix'];

this.source.data['associated_product_ids_serialized'] =
JSON.stringify(this.source.data['associated_product_ids']);

delete this.source.data['associated_product_ids'];
},

/**
* Check for newly added attributes
* @returns {Boolean}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,36 @@
*/
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;

use Magento\Framework\App\ObjectManager;
use Magento\SalesRule\Model\CouponGenerator;

class Generate extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
{
/**
* @var CouponGenerator
*/
private $couponGenerator;

/**
* Generate constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param CouponGenerator|null $couponGenerator
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
CouponGenerator $couponGenerator = null
) {
parent::__construct($context, $coreRegistry, $fileFactory, $dateFilter);
$this->couponGenerator = $couponGenerator ?:
$this->_objectManager->get(CouponGenerator::class);
}

/**
* Generate Coupons action
*
Expand All @@ -22,7 +50,6 @@ public function execute()
$result = [];
$this->_initRule();

/** @var $rule \Magento\SalesRule\Model\Rule */
$rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE);

if (!$rule->getId()) {
Expand All @@ -35,18 +62,13 @@ public function execute()
$data = $inputFilter->getUnescaped();
}

/** @var $generator \Magento\SalesRule\Model\Coupon\Massgenerator */
$generator = $this->_objectManager->get(\Magento\SalesRule\Model\Coupon\Massgenerator::class);
if (!$generator->validateData($data)) {
$result['error'] = __('Invalid data provided');
} else {
$generator->setData($data);
$generator->generatePool();
$generated = $generator->getGeneratedCount();
$this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated));
$this->_view->getLayout()->initMessages();
$result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml();
}
$couponCodes = $this->couponGenerator->generateCodes($data);
$generated = count($couponCodes);
$this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated));
$this->_view->getLayout()->initMessages();
$result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml();
} catch (\Magento\Framework\Exception\InputException $inputException) {
$result['error'] = __('Invalid data provided');
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$result['error'] = $e->getMessage();
} catch (\Exception $e) {
Expand Down
90 changes: 90 additions & 0 deletions app/code/Magento/SalesRule/Model/CouponGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\SalesRule\Model;

/**
* Allows to generate a pool of coupon codes.
*
* Generated coupon code - auto generated string, which is used on checkout in order to get
* discount (fixed or in percents) on whole customer shopping cart or on items in this shopping cart.
* Class was added due to Backward Compatibility and is used as proxy to:
* @see \Magento\SalesRule\Model\Service\CouponManagementService
*/
class CouponGenerator
{
/**
* Map keys in old and new services
*
* Controller was used as old service
* @see \Magento\SalesRule\Controller\Adminhtml\Promo\Quote\Generate
* - key = key in new service
* - value = key in old service
*
* @var array
*/
private $keyMap = [
'quantity' => 'qty'
];

/**
* @var Service\CouponManagementService
*/
private $couponManagementService;

/**
* @var \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory
*/
private $generationSpecFactory;

/**
* All objects should be injected through constructor, because we need to have working service already
* after it initializing
*
* @param Service\CouponManagementService $couponManagementService
* @param \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory
*/
public function __construct(
\Magento\SalesRule\Model\Service\CouponManagementService $couponManagementService,
\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory
) {
$this->couponManagementService = $couponManagementService;
$this->generationSpecFactory = $generationSpecFactory;
}

/**
* Generate a pool of generated coupon codes
*
* This method is used as proxy, due to high coupling in constructor
* @see \Magento\SalesRule\Controller\Adminhtml\Promo\Quote\Generate
* In order to generate valid coupon codes, we need to initialize DTO object and run service.
* @see \Magento\SalesRule\Api\Data\CouponGenerationSpecInterface -> DTO object
*
* @param array $parameters
* @return string[]
*/
public function generateCodes(array $parameters)
{
$couponSpecData = $this->convertCouponSpecData($parameters);
$couponSpec = $this->generationSpecFactory->create(['data' => $couponSpecData]);
return $this->couponManagementService->generate($couponSpec);
}

/**
* We should map old values to new one
* We need to do this, as new service with another key names was added
*
* @param array $data
* @return array
*/
private function convertCouponSpecData(array $data)
{
foreach ($this->keyMap as $mapKey => $mapValue) {
$data[$mapKey] = isset($data[$mapValue]) ? $data[$mapValue] : null;
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
namespace Magento\SalesRule\Model\Service;

use Magento\SalesRule\Model\Coupon;

/**
* Coupon management service class
*
Expand Down
Loading

0 comments on commit f892baf

Please sign in to comment.