Skip to content

Commit

Permalink
Merge pull request #4184 from magento-mpi/PR-2019-05-07
Browse files Browse the repository at this point in the history
[mpi] MAGETWO-98462: Shopping cart does not show all four digits of quantity
  • Loading branch information
dhorytskyi authored May 10, 2019
2 parents 0b2fcf1 + 935b45a commit 834f1af
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 45 deletions.
10 changes: 4 additions & 6 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public function getAddToCartUrl($product, $additional = [])
}

/**
* Get JSON encoded configuration array which can be used for JS dynamic
* price calculation depending on product options
* Get JSON encoded configuration which can be used for JS dynamic price calculation depending on product options
*
* @return string
*/
Expand Down Expand Up @@ -254,6 +253,7 @@ public function hasRequiredOptions()
* instantly.
*
* @return bool
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function isStartCustomization()
{
Expand All @@ -262,6 +262,7 @@ public function isStartCustomization()

/**
* Get default qty - either as preconfigured, or as 1.
*
* Also restricts it by minimal qty.
*
* @param null|\Magento\Catalog\Model\Product $product
Expand Down Expand Up @@ -323,10 +324,7 @@ public function getQuantityValidators()
public function getIdentities()
{
$identities = $this->getProduct()->getIdentities();
$category = $this->_coreRegistry->registry('current_category');
if ($category) {
$identities[] = Category::CACHE_TAG . '_' . $category->getId();
}

return $identities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,18 @@ public function testGetIdentities()
{
$productTags = ['cat_p_1'];
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
$category = $this->createMock(\Magento\Catalog\Model\Category::class);

$product->expects($this->once())
->method('getIdentities')
->will($this->returnValue($productTags));
$category->expects($this->once())
->method('getId')
->will($this->returnValue(1));
$this->registryMock->expects($this->any())
->method('registry')
->will($this->returnValueMap(
[
['product', $product],
['current_category', $category],
]
)
);
$this->assertEquals(['cat_p_1', 'cat_c_1'], $this->view->getIdentities());
$this->assertEquals($productTags, $this->view->getIdentities());
}
}
44 changes: 26 additions & 18 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private function getAuthentication()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resendConfirmation($email, $websiteId = null, $redirectUrl = '')
{
Expand All @@ -498,7 +498,7 @@ public function resendConfirmation($email, $websiteId = null, $redirectUrl = '')
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function activate($email, $confirmationKey)
{
Expand All @@ -507,7 +507,7 @@ public function activate($email, $confirmationKey)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function activateById($customerId, $confirmationKey)
{
Expand Down Expand Up @@ -547,7 +547,7 @@ private function activateCustomer($customer, $confirmationKey)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function authenticate($username, $password)
{
Expand Down Expand Up @@ -582,7 +582,7 @@ public function authenticate($username, $password)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkToken)
{
Expand All @@ -591,7 +591,7 @@ public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkTo
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function initiatePasswordReset($email, $template, $websiteId = null)
{
Expand Down Expand Up @@ -677,7 +677,7 @@ private function matchCustomerByRpToken(string $rpToken): CustomerInterface
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resetPassword($email, $resetToken, $newPassword)
{
Expand Down Expand Up @@ -706,7 +706,12 @@ public function resetPassword($email, $resetToken, $newPassword)
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
$this->getAuthentication()->unlock($customer->getId());
$this->destroyCustomerSessions($customer->getId());
$this->sessionManager->destroy();
if ($this->sessionManager->isSessionExists() && !headers_sent()) {
//delete old session and move data to the new session
//use this instead of $this->sessionManager->regenerateId because last one doesn't delete old session
// phpcs:ignore Magento2.Functions.DiscouragedFunction
session_regenerate_id(true);
}
$this->customerRepository->save($customer);

return true;
Expand Down Expand Up @@ -798,7 +803,7 @@ protected function getMinPasswordLength()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getConfirmationStatus($customerId)
{
Expand All @@ -814,7 +819,7 @@ public function getConfirmationStatus($customerId)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '', $extensions = [])
{
Expand All @@ -835,7 +840,7 @@ public function createAccount(CustomerInterface $customer, $password = null, $re
}

/**
* {@inheritdoc}
* @inheritdoc
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down Expand Up @@ -920,7 +925,7 @@ public function createAccountWithPasswordHash(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getDefaultBillingAddress($customerId)
{
Expand All @@ -929,7 +934,7 @@ public function getDefaultBillingAddress($customerId)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getDefaultShippingAddress($customerId)
{
Expand Down Expand Up @@ -974,7 +979,7 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function changePassword($email, $currentPassword, $newPassword)
{
Expand All @@ -987,7 +992,7 @@ public function changePassword($email, $currentPassword, $newPassword)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function changePasswordById($customerId, $currentPassword, $newPassword)
{
Expand Down Expand Up @@ -1046,6 +1051,8 @@ protected function createPasswordHash($password)
}

/**
* Get EAV validator
*
* @return Backend
*/
private function getEavValidator()
Expand All @@ -1057,7 +1064,7 @@ private function getEavValidator()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function validate(CustomerInterface $customer)
{
Expand All @@ -1082,7 +1089,7 @@ public function validate(CustomerInterface $customer)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function isEmailAvailable($customerEmail, $websiteId = null)
{
Expand All @@ -1098,7 +1105,7 @@ public function isEmailAvailable($customerEmail, $websiteId = null)
}

/**
* {@inheritDoc}
* @inheritdoc
*/
public function isCustomerInStore($customerWebsiteId, $storeId)
{
Expand Down Expand Up @@ -1549,6 +1556,7 @@ private function getEmailNotification()

/**
* Destroy all active customer sessions by customer id (current session will not be destroyed).
*
* Customer sessions which should be deleted are collecting from the "customer_visitor" table considering
* configured session lifetime.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if ($block->getIsShipping()):
require(["Magento_Sales/order/create/form"], function(){

order.shippingAddressContainer = '<?= /* @escapeNotVerified */ $_fieldsContainerId ?>';
order.setAddresses(<?= /* @escapeNotVerified */ $customerAddressFormatter->getAddressesJson($addressArray) ?>);
order.setAddresses(<?= /* @noEscape */ $block->getAddressCollectionJson() ?>);

});
</script>
Expand Down
16 changes: 12 additions & 4 deletions app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ define([
this.isOnlyVirtualProduct = false;
this.excludedPaymentMethods = [];
this.summarizePrice = true;
this.selectAddressEvent = false;
this.shippingTemplate = template(shippingTemplate, {
data: {
title: jQuery.mage.__('Shipping Method'),
Expand Down Expand Up @@ -169,17 +170,19 @@ define([
},

selectAddress : function(el, container){

id = el.value;
if (id.length == 0) {
id = '0';
}
if(this.addresses[id]){
this.fillAddressFields(container, this.addresses[id]);

}
else{
this.selectAddressEvent = true;
if (this.addresses[id]) {
this.fillAddressFields(container, this.addresses[id]);
} else {
this.fillAddressFields(container, {});
}
this.selectAddressEvent = false;

var data = this.serializeData(container);
data[el.name] = id;
Expand All @@ -190,6 +193,7 @@ define([
} else{
this.saveData(data);
}

},

/**
Expand Down Expand Up @@ -279,6 +283,10 @@ define([
$('order-' + type + '_address_customer_address_id').value;
}

if (name === 'country_id' && this.selectAddressEvent === false) {
$('order-' + type + '_address_customer_address_id').value = '';
}

this.resetPaymentMethod();

if (data['reset_shipping']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
height: 36px;
margin-top: -7px;
text-align: center;
width: 45px;
width: 60px;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
.item-qty {
margin-right: @indent__s;
text-align: center;
width: 45px;
width: 60px;
}

.update-cart-item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ public function toNestedArray(
}
$dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
//process custom attributes if present
$dataObjectArray = $this->processCustomAttributes($dataObjectArray, $skipAttributes);

if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
/** @var array $extensionAttributes */
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
if (!in_array($attributeKey, $skipAttributes)) {
$dataObjectArray[$attributeKey] = $attributeValue;
}
}
}
return $dataObjectArray;
}

/**
* Recursive process array to process customer attributes
*
* @param array $dataObjectArray
* @param array $skipAttributes
* @return array
*/
private function processCustomAttributes(array $dataObjectArray, array $skipAttributes): array
{
if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
/** @var AttributeValue[] $customAttributes */
$customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
Expand All @@ -56,16 +80,13 @@ public function toNestedArray(
}
}
}
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
/** @var array $extensionAttributes */
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
if (!in_array($attributeKey, $skipAttributes)) {
$dataObjectArray[$attributeKey] = $attributeValue;
}

foreach ($dataObjectArray as $key => $value) {
if (is_array($value)) {
$dataObjectArray[$key] = $this->processCustomAttributes($value, $skipAttributes);
}
}

return $dataObjectArray;
}

Expand Down
Loading

0 comments on commit 834f1af

Please sign in to comment.