Skip to content

Commit

Permalink
MAGETWO-87064: [EngCom Team] Batch 3. Forwardports to 2.3-develop #1284
Browse files Browse the repository at this point in the history
 - Merge Pull Request magento-engcom/magento2ce#1284 from magento-engcom-team/magento2:batch-3-forwardport-2.3-develop
 - Merged commits:
   1. 97e48a7
   2. 88096d1
   3. 4c5c952
   4. 56f7708
   5. 93cba75
   6. d6da9b6
   7. 3914fda
   8. b836052
   9. 5130f54
   10. 4e965fa
   11. 1ad5260
   12. 7b99d4f
   13. 3f27734
   14. 153aa0c
   15. fe598ef
   16. f3db727
   17. 184aab1
   18. 0d8ccee
   19. 217a451
   20. 8463fa4
   21. 97a4786
   22. b28dcdc
  • Loading branch information
Oleksii Korshenko committed Jan 23, 2018
2 parents 8e77e2f + b28dcdc commit af8a93e
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ switch ($type = $block->getType()) {
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
<?php endif; ?>

<?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
<?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<div class="field choice related">
<input type="checkbox" class="checkbox related" id="related-checkbox<?= /* @escapeNotVerified */ $_item->getId() ?>" name="related_products[]" value="<?= /* @escapeNotVerified */ $_item->getId() ?>" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ define([
quoteId: quoteId
} : {},
urls = {
'guest': '/guest-carts/' + quoteId + '/coupons/' + couponCode,
'customer': '/carts/mine/coupons/' + couponCode
'guest': '/guest-carts/' + quoteId + '/coupons/' + encodeURIComponent(couponCode),
'customer': '/carts/mine/coupons/' + encodeURIComponent(couponCode)
};

return this.getUrl(urls, params);
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function collectRates(RateRequest $request)

// Free shipping by qty
$freeQty = 0;
$freePackageValue = 0;

if ($request->getAllItems()) {
$freePackageValue = 0;
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,8 @@ public function validateMinimumAmount()
*/
public function getAppliedTaxes()
{
return $this->serializer->unserialize($this->getData('applied_taxes'));
$taxes = $this->getData('applied_taxes');
return $taxes ? $this->serializer->unserialize($taxes) : [];
}

/**
Expand Down
28 changes: 13 additions & 15 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Magento\Quote\Test\Unit\Model\Quote;

use Magento\Directory\Model\Currency;
use \Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address\Rate;
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory as RateCollectionFactory;
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection as RatesCollection;
Expand All @@ -26,6 +26,7 @@
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Test class for sales quote address model
Expand Down Expand Up @@ -121,7 +122,7 @@ protected function setUp()
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config::class);
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
$this->serializer = new Json();

$this->requestFactory = $this->getMockBuilder(RateRequestFactory::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -283,20 +284,17 @@ public function testValidateMinimumAmountNegative()
public function testSetAndGetAppliedTaxes()
{
$data = ['data'];
$result = json_encode($data);

$this->serializer->expects($this->once())
->method('serialize')
->with($data)
->willReturn($result);

$this->serializer->expects($this->once())
->method('unserialize')
->with($result)
->willReturn($data);
self::assertInstanceOf(Address::class, $this->address->setAppliedTaxes($data));
self::assertEquals($data, $this->address->getAppliedTaxes());
}

$this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data));
$this->assertEquals($data, $this->address->getAppliedTaxes());
/**
* Checks a case, when applied taxes are not provided.
*/
public function testGetAppliedTaxesWithEmptyValue()
{
$this->address->setData('applied_taxes', null);
self::assertEquals([], $this->address->getAppliedTaxes());
}

/**
Expand Down
57 changes: 32 additions & 25 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Model\Metadata\Form as CustomerForm;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Item;

/**
Expand Down Expand Up @@ -321,7 +323,7 @@ public function __construct(
$this->dataObjectHelper = $dataObjectHelper;
$this->orderManagement = $orderManagement;
$this->quoteFactory = $quoteFactory;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct($data);
}
Expand Down Expand Up @@ -1454,32 +1456,36 @@ public function getBillingAddress()
*/
public function setBillingAddress($address)
{
if (is_array($address)) {
$billingAddress = $this->_objectManager->create(
\Magento\Quote\Model\Quote\Address::class
)->setData(
$address
)->setAddressType(
\Magento\Quote\Model\Quote\Address::TYPE_BILLING
);
$this->_setQuoteAddress($billingAddress, $address);
/**
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
* that is why it should be added after _setQuoteAddress call
*/
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
$billingAddress->setData('save_in_address_book', $saveInAddressBook);

if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
$shippingAddress = clone $billingAddress;
$shippingAddress->setSameAsBilling(true);
$shippingAddress->setSaveInAddressBook(false);
$address['save_in_address_book'] = 0;
$this->setShippingAddress($address);
}
if (!is_array($address)) {
return $this;
}

$billingAddress = $this->_objectManager->create(Address::class)
->setData($address)
->setAddressType(Address::TYPE_BILLING);

$this->_setQuoteAddress($billingAddress, $address);

/**
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
* that is why it should be added after _setQuoteAddress call
*/
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
$billingAddress->setData('save_in_address_book', $saveInAddressBook);

$quote = $this->getQuote();
if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
$address['save_in_address_book'] = 0;
$this->setShippingAddress($address);
}

$this->getQuote()->setBillingAddress($billingAddress);
// not assigned billing address should be saved as new
// but if quote already has the billing address it won't be overridden
if (empty($billingAddress->getCustomerAddressId())) {
$billingAddress->setCustomerAddressId(null);
$quote->getBillingAddress()->setCustomerAddressId(null);
}
$quote->setBillingAddress($billingAddress);

return $this;
}
Expand Down Expand Up @@ -1782,6 +1788,7 @@ public function _prepareCustomer()
$address = $this->getShippingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId());
$this->setShippingAddress($address);
}
$this->getBillingAddress()->setCustomerId($customer->getId());
$this->getQuote()->updateCustomerData($this->getQuote()->getCustomer());

$customer = $this->getQuote()->getCustomer();
Expand Down
47 changes: 29 additions & 18 deletions app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ define([
}
if(this.addresses[id]){
this.fillAddressFields(container, this.addresses[id]);

}
else{
this.fillAddressFields(container, {});
Expand Down Expand Up @@ -190,43 +191,53 @@ define([
}
},

changeAddressField : function(event){
var field = Event.element(event);
var re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/;
var matchRes = field.name.match(re);
/**
* Triggers on each form's element changes.
*
* @param {Object} event
*/
changeAddressField: function (event) {
var field = Event.element(event),
re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/,
matchRes = field.name.match(re),
type,
name,
data;

if (!matchRes) {
return;
}

var type = matchRes[1];
var name = matchRes[2];
var data;
type = matchRes[1];
name = matchRes[2];

if(this.isBillingField(field.id)){
data = this.serializeData(this.billingAddressContainer)
}
else{
data = this.serializeData(this.shippingAddressContainer)
if (this.isBillingField(field.id)) {
data = this.serializeData(this.billingAddressContainer);
} else {
data = this.serializeData(this.shippingAddressContainer);
}
data = data.toObject();

if( (type == 'billing' && this.shippingAsBilling)
|| (type == 'shipping' && !this.shippingAsBilling) ) {
if (type === 'billing' && this.shippingAsBilling || type === 'shipping' && !this.shippingAsBilling) {
data['reset_shipping'] = true;
}

data['order['+type+'_address][customer_address_id]'] = $('order-'+type+'_address_customer_address_id').value;
data['order[' + type + '_address][customer_address_id]'] = null;
data['shipping_as_billing'] = jQuery('[name="shipping_same_as_billing"]').is(':checked') ? 1 : 0;

if (name === 'customer_address_id') {
data['order[' + type + '_address][customer_address_id]'] =
$('order-' + type + '_address_customer_address_id').value;
}

if (data['reset_shipping']) {
this.resetShippingMethod(data);
} else {
this.saveData(data);
if (name == 'country_id' || name == 'customer_address_id') {

if (name === 'country_id' || name === 'customer_address_id') {
this.loadArea(['shipping_method', 'billing_method', 'totals', 'items'], true, data);
}
// added for reloading of default sender and default recipient for giftmessages
//this.loadArea(['giftmessage'], true, data);
}
},

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/form/element/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ define([

this._super();

scope = this.dataScope;
name = scope.split('.').slice(1);
scope = this.dataScope.split('.');
name = scope.length > 1 ? scope.slice(1) : scope;

valueUpdate = this.showFallbackReset ? 'afterkeydown' : this.valueUpdate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ define([
],
'pattern': [
function (value, param) {
return param.test(value);
return new RegExp(param).test(value);
},
$.mage.__('Invalid format.')
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public function run()
/**
* {@inheritdoc}
*/
public function install()
public function install($cleanup)
{
if ($cleanup) {
$this->cleanup();
}

$installOptions = $this->getInstallConfig();

/* Install application */
Expand Down
6 changes: 2 additions & 4 deletions dev/tests/api-functional/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@
);

if (defined('TESTS_MAGENTO_INSTALLATION') && TESTS_MAGENTO_INSTALLATION === 'enabled') {
if (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled') {
$application->cleanup();
}
$application->install();
$cleanup = (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled');
$application->install($cleanup);
}

$bootstrap = new \Magento\TestFramework\Bootstrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,11 @@ public function cleanup()
/**
* Install an application
*
* @param bool $cleanup
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function install()
public function install($cleanup)
{
$dirs = \Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
$this->_ensureDirExists($this->installDir);
Expand All @@ -459,8 +460,9 @@ public function install()
$installParams = $this->getInstallCliParams();

// performance optimization: restore DB from last good dump to make installation on top of it (much faster)
// do not restore from the database if the cleanup option is set to ensure we have a clean DB to test on
$db = $this->getDbInstance();
if ($db->isDbDumpExists()) {
if ($db->isDbDumpExists() && !$cleanup) {
$db->restoreFromDbDump();
}

Expand Down
2 changes: 1 addition & 1 deletion dev/tests/integration/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
$application->cleanup();
}
if (!$application->isInstalled()) {
$application->install();
$application->install($settings->getAsBoolean('TESTS_CLEANUP'));
}
$application->initialize([]);

Expand Down
Loading

0 comments on commit af8a93e

Please sign in to comment.