Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-devel…
Browse files Browse the repository at this point in the history
…op daily delivery

Accepted Community Pull Requests:
 - #26378: 26375 braintree payment address issue (by @chris-pook)
 - #25641: M2C-21768 Validate product quantity on Wishlist update (by @ptylek)
 - #25285: Add lib wrapper for UUID validation. (by @nikolaevas)


Fixed GitHub Issues:
 - #26375: Switching billing address causes Javascript function text to render in front-end checkout payment section (reported by @chris-pook) has been fixed in #26378 by @chris-pook in 2.4-develop branch
   Related commits:
     1. 4ea41d0
     2. ee3f8e3
     3. 5427099

 - #25032: Display some error "We can't update your Wish List right now." at wish list (reported by @renard123) has been fixed in #25641 by @ptylek in 2.4-develop branch
   Related commits:
     1. a5a2cbc
     2. 5415e99
     3. b2fc304
     4. b398206
  • Loading branch information
slavvka authored Feb 9, 2020
2 parents c61a2c6 + 5877e54 commit 6df825a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ define(
'Magento_Vault/js/view/payment/vault-enabler',
'Magento_Braintree/js/view/payment/kount',
'mage/translate',
'prototype',
'domReady!'
],
function (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ define([
groupedInfo: '#super-product-table input',
downloadableInfo: '#downloadable-links-list input',
customOptionsInfo: '.product-custom-option',
qtyInfo: '#qty'
qtyInfo: '#qty',
actionElement: '[data-action="add-to-wishlist"]'
},

/** @inheritdoc */
Expand All @@ -30,8 +31,10 @@ define([
_bind: function () {
var options = this.options,
dataUpdateFunc = '_updateWishlistData',
validateProductQty = '_validateWishlistQty',
changeCustomOption = 'change ' + options.customOptionsInfo,
changeQty = 'change ' + options.qtyInfo,
updateWishlist = 'click ' + options.actionElement,
events = {},
key;

Expand All @@ -45,6 +48,7 @@ define([

events[changeCustomOption] = dataUpdateFunc;
events[changeQty] = dataUpdateFunc;
events[updateWishlist] = validateProductQty;

for (key in options.productType) {
if (options.productType.hasOwnProperty(key) && options.productType[key] + 'Info' in options) {
Expand Down Expand Up @@ -220,6 +224,23 @@ define([

$(form).attr('action', action).submit();
});
},

/**
* Validate product quantity before updating Wish List
*
* @param {jQuery.Event} event
* @private
*/
_validateWishlistQty: function (event) {
var element = $(this.options.qtyInfo);

if (!(element.validation() && element.validation('isValid'))) {
event.preventDefault();
event.stopPropagation();

return;
}
}
});

Expand Down
1 change: 1 addition & 0 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<preference for="Magento\Framework\EntityManager\MapperInterface" type="Magento\Framework\EntityManager\CompositeMapper"/>
<preference for="Magento\Framework\Console\CommandListInterface" type="Magento\Framework\Console\CommandList"/>
<preference for="Magento\Framework\DataObject\IdentityGeneratorInterface" type="Magento\Framework\DataObject\IdentityService" />
<preference for="Magento\Framework\DataObject\IdentityValidatorInterface" type="Magento\Framework\DataObject\IdentityValidator" />
<preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Serializer\Json" />
<preference for="Magento\Framework\App\Scope\ValidatorInterface" type="Magento\Framework\App\Scope\Validator"/>
<preference for="Magento\Framework\App\ScopeResolverInterface" type="Magento\Framework\App\ScopeResolver" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\DataObject;

class IdentityValidatorTest extends \PHPUnit\Framework\TestCase
{
const VALID_UUID = 'fe563e12-cf9d-4faf-82cd-96e011b557b7';
const INVALID_UUID = 'abcdef';

/**
* @var IdentityValidator
*/
protected $identityValidator;

protected function setUp()
{
$this->identityValidator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(IdentityValidator::class);
}

public function testIsValid()
{
$isValid = $this->identityValidator->isValid(self::VALID_UUID);
$this->assertEquals(true, $isValid);
}

public function testIsNotValid()
{
$isValid = $this->identityValidator->isValid(self::INVALID_UUID);
$this->assertEquals(false, $isValid);
}

public function testEmptyValue()
{
$isValid = $this->identityValidator->isValid('');
$this->assertEquals(false, $isValid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
define([
'jquery',
'Magento_Wishlist/js/add-to-wishlist'
], function ($) {
], function ($, Widget) {
'use strict';

describe('Testing addToWishlist widget', function () {
var wdContainer;
var wdContainer,
wishlistWidget,
eventMock = {
preventDefault: jasmine.createSpy(),
stopPropagation: jasmine.createSpy()
};

beforeEach(function () {
wdContainer = $('<input type="hidden" class="bundle-option-11 product bundle option" \n' +
'name="bundle_option[11]" value="15" aria-required="true"/>');
wishlistWidget = new Widget();
$.fn.validation = {};
});

afterEach(function () {
Expand All @@ -31,5 +38,15 @@ define([
});
expect(wdContainer.addToWishlist('option', 'bundleInfo')).toBe('test');
});

it('verify update wichlist with validate product qty, valid qty', function () {
var validation = spyOn($.fn, 'validation').and.returnValue(false);

wishlistWidget._validateWishlistQty(eventMock);
expect(validation).toHaveBeenCalled();
expect(eventMock.preventDefault).toHaveBeenCalled();
expect(eventMock.stopPropagation).toHaveBeenCalled();
});

});
});
27 changes: 27 additions & 0 deletions lib/internal/Magento/Framework/DataObject/IdentityValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\DataObject;

use Ramsey\Uuid\Uuid;

/**
* Class IdentityValidator
*
* Class for validating Uuid's
*/
class IdentityValidator implements IdentityValidatorInterface
{
/**
* @inheritDoc
*/
public function isValid(string $value): bool
{
$isValid = Uuid::isValid($value);
return $isValid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\DataObject;

/**
* Interface IdentityValidatorInterface
*/
interface IdentityValidatorInterface
{
/**
* Checks if uuid is valid
*
* @param string $value
*
* @return bool
*/
public function isValid(string $value): bool;
}
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"zendframework/zend-validator": "^2.6.0",
"zendframework/zend-mail": "^2.9.0",
"zendframework/zend-mime": "^2.5.0",
"guzzlehttp/guzzle": "^6.3.3"
"guzzlehttp/guzzle": "^6.3.3",
"ramsey/uuid": "~3.8.0"
},
"archive": {
"exclude": [
Expand Down

0 comments on commit 6df825a

Please sign in to comment.