From 216540f3f9577ad0d57785790c5160505e823f1a Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Thu, 17 Oct 2019 21:58:39 +0300 Subject: [PATCH 01/15] Replace multiple string concatenation by joining array of strings --- .../App/ObjectManager/ConfigLoader/Compiled.php | 2 +- .../Framework/View/Element/AbstractBlock.php | 14 ++++++++++++-- lib/internal/Magento/Framework/View/Layout.php | 14 ++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 01e5031461f85..1dec1666d526a 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -42,6 +42,6 @@ public function load($area) public static function getFilePath($area) { $diPath = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_METADATA][DirectoryList::PATH]; - return BP . '/' . $diPath . '/' . $area . '.php'; + return join('', [BP, '/', $diPath, '/', $area, '.php']); } } diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index f8e8d2fee264a..1788fba3386f4 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -517,9 +517,14 @@ public function getChildHtml($alias = '', $useCache = true) $out = $layout->renderElement($childName, $useCache); } } else { + $outParts = []; foreach ($layout->getChildNames($name) as $child) { - $out .= $layout->renderElement($child, $useCache); + $elementHtml = $layout->renderElement($child, $useCache); + if (!empty($elementHtml)) { + $outParts[] = $elementHtml; + } } + $out = join('', $outParts); } return $out; @@ -548,9 +553,14 @@ public function getChildChildHtml($alias, $childChildAlias = '', $useCache = tru $childChildName = $layout->getChildName($childName, $childChildAlias); $out = $layout->renderElement($childChildName, $useCache); } else { + $outParts = []; foreach ($layout->getChildNames($childName) as $childChild) { - $out .= $layout->renderElement($childChild, $useCache); + $elementHtml = $layout->renderElement($childChild, $useCache); + if (!empty($elementHtml)) { + $outParts[] = $elementHtml; + } } + $out = join('', $outParts); } return $out; } diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index a622006f32a1e..994a19b03695d 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -586,13 +586,16 @@ protected function _renderUiComponent($name) */ protected function _renderContainer($name, $useCache = true) { - $html = ''; + $htmlParts = []; $children = $this->getChildNames($name); foreach ($children as $child) { - $html .= $this->renderElement($child, $useCache); + $childHtml = $this->renderElement($child, $useCache); + if (!empty($childHtml)) { + $htmlParts[] = $childHtml; + } } - if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) { - return $html; + if (empty($htmlParts) || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) { + return join('', $htmlParts); } $htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID); @@ -606,8 +609,7 @@ protected function _renderContainer($name, $useCache = true) } $htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG); - - $html = sprintf('<%1$s%2$s%3$s>%4$s', $htmlTag, $htmlId, $htmlClass, $html); + $html = sprintf('<%1$s%2$s%3$s>%4$s', $htmlTag, $htmlId, $htmlClass, join('', $htmlParts)); return $html; } From e917b007ed8a233007c1a19d22776315eb7870d4 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Thu, 17 Oct 2019 21:59:32 +0300 Subject: [PATCH 02/15] Replace two calls to str_replace() by single strtr() I've tested: str_replace() is slower than strtr() in this case --- lib/internal/Magento/Framework/Phrase/Renderer/Translate.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php index c9329caf49370..e2c8a737c344b 100644 --- a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php +++ b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php @@ -50,8 +50,7 @@ public function render(array $source, array $arguments) { $text = end($source); /* If phrase contains escaped quotes then use translation for phrase with non-escaped quote */ - $text = str_replace('\"', '"', $text); - $text = str_replace("\\'", "'", $text); + $text = strtr($text, ['\"' => '"', "\\'" => "'"]); try { $data = $this->translator->getData(); From aa068f94560b90f40aa5392d426c53f76aa7a895 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Thu, 17 Oct 2019 22:00:34 +0300 Subject: [PATCH 03/15] Replace in_array() by isset() --- .../Model/ResourceModel/Eav/Attribute.php | 25 ++++++++++--------- .../Framework/DB/Select/SelectRenderer.php | 8 +++++- lib/internal/Magento/Framework/Module/Dir.php | 16 ++++++------ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php b/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php index 355561c5e384d..97f126e388730 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php @@ -38,6 +38,18 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements const KEY_IS_GLOBAL = 'is_global'; + private const ALLOWED_INPUT_TYPES = [ + 'boolean' => true, + 'date' => true, + 'datetime' => true, + 'multiselect' => true, + 'price' => true, + 'select' => true, + 'text' => true, + 'textarea' => true, + 'weight' => true, + ]; + /** * @var LockValidatorInterface */ @@ -403,18 +415,7 @@ public function getSourceModel() */ public function isAllowedForRuleCondition() { - $allowedInputTypes = [ - 'boolean', - 'date', - 'datetime', - 'multiselect', - 'price', - 'select', - 'text', - 'textarea', - 'weight', - ]; - return $this->getIsVisible() && in_array($this->getFrontendInput(), $allowedInputTypes); + return $this->getIsVisible() && isset(self::ALLOWED_INPUT_TYPES[$this->getFrontendInput()]); } /** diff --git a/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php b/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php index 11dbaeb82317a..ce53c07789bde 100644 --- a/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php +++ b/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php @@ -12,6 +12,11 @@ */ class SelectRenderer implements RendererInterface { + private const MANDATORY_SELECT_PARTS = [ + Select::COLUMNS => true, + Select::FROM => true + ]; + /** * @var RendererInterface[] */ @@ -67,7 +72,8 @@ public function render(Select $select, $sql = '') { $sql = Select::SQL_SELECT; foreach ($this->renderers as $renderer) { - if (in_array($renderer['part'], [Select::COLUMNS, Select::FROM]) || $select->getPart($renderer['part'])) { + $part = $renderer['part']; + if (isset(self::MANDATORY_SELECT_PARTS[$part]) || $select->getPart($part)) { $sql = $renderer['renderer']->render($select, $sql); } } diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index e6b60453b9577..4baf5f2f10ec6 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -22,6 +22,14 @@ class Dir const MODULE_SETUP_DIR = 'Setup'; /**#@-*/ + private const ALLOWED_DIR_TYPES = [ + self::MODULE_ETC_DIR => true, + self::MODULE_I18N_DIR => true, + self::MODULE_VIEW_DIR => true, + self::MODULE_CONTROLLER_DIR => true, + self::MODULE_SETUP_DIR => true + ]; + /**#@-*/ private $componentRegistrar; @@ -52,13 +60,7 @@ public function getDir($moduleName, $type = '') } if ($type) { - if (!in_array($type, [ - self::MODULE_ETC_DIR, - self::MODULE_I18N_DIR, - self::MODULE_VIEW_DIR, - self::MODULE_CONTROLLER_DIR, - self::MODULE_SETUP_DIR - ])) { + if (!isset(self::ALLOWED_DIR_TYPES[$type])) { throw new \InvalidArgumentException("Directory type '{$type}' is not recognized."); } $path .= '/' . $type; From c0ce7eac9a5f9f233b12b4e354b09664dbaf3d26 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Thu, 17 Oct 2019 22:01:17 +0300 Subject: [PATCH 04/15] Micro optimization: Replace != with !== --- .../Attribute/Backend/GroupPrice/AbstractGroupPrice.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php index e26717e47274c..d301cc7b63c52 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php @@ -97,17 +97,16 @@ protected function _getWebsiteCurrencyRates() ); foreach ($this->_storeManager->getWebsites() as $website) { /* @var $website \Magento\Store\Model\Website */ - if ($website->getBaseCurrencyCode() != $baseCurrency) { + $websiteBaseCurrency = $website->getBaseCurrencyCode(); + if ($websiteBaseCurrency !== $baseCurrency) { $rate = $this->_currencyFactory->create()->load( $baseCurrency - )->getRate( - $website->getBaseCurrencyCode() - ); + )->getRate($websiteBaseCurrency); if (!$rate) { $rate = 1; } $this->_rates[$website->getId()] = [ - 'code' => $website->getBaseCurrencyCode(), + 'code' => $websiteBaseCurrency, 'rate' => $rate, ]; } else { From 33c7de98bbc6f1baa6c9d1712b6a7e6d94a506ad Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Fri, 18 Oct 2019 19:52:53 +0300 Subject: [PATCH 05/15] Fixes for PHPCS --- .../Attribute/Backend/GroupPrice/AbstractGroupPrice.php | 4 ++++ .../Framework/App/ObjectManager/ConfigLoader/Compiled.php | 8 ++++---- lib/internal/Magento/Framework/Module/Dir.php | 3 +++ .../Magento/Framework/Phrase/Renderer/Translate.php | 3 +++ .../Magento/Framework/View/Element/AbstractBlock.php | 3 +++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php index d301cc7b63c52..68aeabfc70d34 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php @@ -186,6 +186,7 @@ public function validate($object) } $compare = implode( '-', + // phpcs:ignore Magento2.Performance.ForeachArrayMerge array_merge( [$priceRow['website_id'], $priceRow['cust_group']], $this->_getAdditionalUniqueFields($priceRow) @@ -209,6 +210,7 @@ public function validate($object) if ($price['website_id'] == 0) { $compare = implode( '-', + // phpcs:ignore Magento2.Performance.ForeachArrayMerge array_merge( [$price['website_id'], $price['cust_group']], $this->_getAdditionalUniqueFields($price) @@ -233,6 +235,7 @@ public function validate($object) $globalCompare = implode( '-', + // phpcs:ignore Magento2.Performance.ForeachArrayMerge array_merge([0, $priceRow['cust_group']], $this->_getAdditionalUniqueFields($priceRow)) ); $websiteCurrency = $rates[$priceRow['website_id']]['code']; @@ -278,6 +281,7 @@ public function preparePriceData(array $priceData, $productTypeId, $websiteId) if (!array_filter($v)) { continue; } + // phpcs:ignore Magento2.Performance.ForeachArrayMerge $key = implode('-', array_merge([$v['cust_group']], $this->_getAdditionalUniqueFields($v))); if ($v['website_id'] == $websiteId) { $data[$key] = $v; diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 1dec1666d526a..5fc668e2d9c5e 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -1,6 +1,5 @@ Date: Sun, 20 Oct 2019 17:25:46 +0300 Subject: [PATCH 06/15] Rollback some changes after benchmarking on PHP 7.2 --- .../Framework/App/ObjectManager/ConfigLoader/Compiled.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 5fc668e2d9c5e..7408e8b230bd9 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -42,6 +42,6 @@ public function load($area) public static function getFilePath($area) { $diPath = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_METADATA][DirectoryList::PATH]; - return join('', [BP, '/', $diPath, '/', $area, '.php']); + return BP . '/' . $diPath . '/' . $area . '.php'; } } From 156c689eedb3fd39b91d771c60e8d7eda611f4be Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Tue, 22 Oct 2019 13:49:18 +0300 Subject: [PATCH 07/15] Revert string concat optimizations - there is no real improvement I've run performance tests for string concat vs. array join: https://gist.github.com/andrey-legayev/24ed101a34d4775bf1b6f9879581f51a No real performance improvement (which surprised me). But anyway - I'm rolling back string concatenation improvements, because it doesn't make any sense. --- .../Framework/View/Element/AbstractBlock.php | 14 ++------------ lib/internal/Magento/Framework/View/Layout.php | 14 ++++++-------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index 57cf1f68efca6..0d7e3154440e9 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -520,14 +520,9 @@ public function getChildHtml($alias = '', $useCache = true) $out = $layout->renderElement($childName, $useCache); } } else { - $outParts = []; foreach ($layout->getChildNames($name) as $child) { - $elementHtml = $layout->renderElement($child, $useCache); - if (!empty($elementHtml)) { - $outParts[] = $elementHtml; - } + $out .= $layout->renderElement($child, $useCache); } - $out = join('', $outParts); } return $out; @@ -556,14 +551,9 @@ public function getChildChildHtml($alias, $childChildAlias = '', $useCache = tru $childChildName = $layout->getChildName($childName, $childChildAlias); $out = $layout->renderElement($childChildName, $useCache); } else { - $outParts = []; foreach ($layout->getChildNames($childName) as $childChild) { - $elementHtml = $layout->renderElement($childChild, $useCache); - if (!empty($elementHtml)) { - $outParts[] = $elementHtml; - } + $out .= $layout->renderElement($childChild, $useCache); } - $out = join('', $outParts); } return $out; } diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index 994a19b03695d..a622006f32a1e 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -586,16 +586,13 @@ protected function _renderUiComponent($name) */ protected function _renderContainer($name, $useCache = true) { - $htmlParts = []; + $html = ''; $children = $this->getChildNames($name); foreach ($children as $child) { - $childHtml = $this->renderElement($child, $useCache); - if (!empty($childHtml)) { - $htmlParts[] = $childHtml; - } + $html .= $this->renderElement($child, $useCache); } - if (empty($htmlParts) || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) { - return join('', $htmlParts); + if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) { + return $html; } $htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID); @@ -609,7 +606,8 @@ protected function _renderContainer($name, $useCache = true) } $htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG); - $html = sprintf('<%1$s%2$s%3$s>%4$s', $htmlTag, $htmlId, $htmlClass, join('', $htmlParts)); + + $html = sprintf('<%1$s%2$s%3$s>%4$s', $htmlTag, $htmlId, $htmlClass, $html); return $html; } From 79be5ed26493ef2ad801d3a06da44357b2459abf Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Fri, 1 Nov 2019 13:42:48 +0530 Subject: [PATCH 08/15] Fixed model save and ObjectManager usage --- .../Adminhtml/Email/Template/Save.php | 71 +++++++++++++++---- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php index 135506f4068a8..e61f45dd8be0f 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php @@ -1,15 +1,62 @@ dateTime = $dateTime; + $this->templateResource = $templateResource; + $this->backendSession = $backendSession; + parent::__construct($context, $coreRegistry); + } + /** * Save transactional email action * @@ -18,10 +65,10 @@ class Save extends \Magento\Email\Controller\Adminhtml\Email\Template public function execute() { $request = $this->getRequest(); - $id = $this->getRequest()->getParam('id'); + $templateId = $this->getRequest()->getParam('id'); $template = $this->_initTemplate('id'); - if (!$template->getId() && $id) { + if (!$template->getId() && $templateId) { $this->messageManager->addErrorMessage(__('This email template no longer exists.')); $this->_redirect('adminhtml/*/'); return; @@ -37,7 +84,7 @@ public function execute() )->setTemplateStyles( $request->getParam('template_styles') )->setModifiedAt( - $this->_objectManager->get(\Magento\Framework\Stdlib\DateTime\DateTime::class)->gmtDate() + $this->dateTime->gmtDate() )->setOrigTemplateCode( $request->getParam('orig_template_code') )->setOrigTemplateVariables( @@ -53,17 +100,13 @@ public function execute() $template->setTemplateStyles(''); } - $template->save(); - $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setFormData(false); + $this->templateResource->save($template); + + $this->backendSession->setFormData(false); $this->messageManager->addSuccessMessage(__('You saved the email template.')); $this->_redirect('adminhtml/*'); - } catch (\Exception $e) { - $this->_objectManager->get( - \Magento\Backend\Model\Session::class - )->setData( - 'email_template_form_data', - $request->getParams() - ); + } catch (Exception $e) { + $this->backendSession->setData('email_template_form_data', $request->getParams()); $this->messageManager->addErrorMessage($e->getMessage()); $this->_forward('new'); } From bde46816fb391793b2a8958dbcd85ef95ca793ec Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Fri, 8 Nov 2019 15:44:12 +0530 Subject: [PATCH 09/15] Added backward compatibility --- .../Adminhtml/Email/Template/Save.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php index e61f45dd8be0f..8e0b4d30ec511 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php @@ -11,6 +11,7 @@ use Magento\Email\Controller\Adminhtml\Email\Template; use Magento\Email\Model\ResourceModel\Template as TemplateResource; use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\TemplateTypesInterface; use Magento\Framework\Registry; use Magento\Framework\Stdlib\DateTime\DateTime; @@ -40,20 +41,20 @@ class Save extends Template implements HttpPostActionInterface * * @param Context $context * @param Registry $coreRegistry - * @param DateTime $dateTime - * @param TemplateResource $templateResource - * @param Session $backendSession + * @param DateTime|null $dateTime + * @param TemplateResource|null $templateResource + * @param Session|null $backendSession */ public function __construct( Context $context, Registry $coreRegistry, - DateTime $dateTime, - TemplateResource $templateResource, - Session $backendSession + DateTime $dateTime = null, + TemplateResource $templateResource = null, + Session $backendSession = null ) { - $this->dateTime = $dateTime; - $this->templateResource = $templateResource; - $this->backendSession = $backendSession; + $this->dateTime = $dateTime ?: ObjectManager::getInstance()->get(DateTime::class); + $this->templateResource = $templateResource ?: ObjectManager::getInstance()->get(TemplateResource::class); + $this->backendSession = $backendSession ?: ObjectManager::getInstance()->get(Session::class); parent::__construct($context, $coreRegistry); } From 45592e234b8ee700b02e82c28c9c7ee94ae13b51 Mon Sep 17 00:00:00 2001 From: Andrea Zambon Date: Mon, 2 Dec 2019 12:29:52 +0100 Subject: [PATCH 10/15] Sets the order to state processing also if the order is in state new or pending_payment --- .../RegisterCaptureNotificationCommand.php | 18 +++++++++++++++--- .../RegisterCaptureNotificationCommandTest.php | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php b/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php index d38e58d7341c1..d8afcc71cc6af 100644 --- a/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php +++ b/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php @@ -11,6 +11,11 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\StatusResolver; +/** + * Class RegisterCaptureNotificationCommand + * + * @package Magento\Sales\Model\Order\Payment\State + */ class RegisterCaptureNotificationCommand implements CommandInterface { /** @@ -23,11 +28,12 @@ class RegisterCaptureNotificationCommand implements CommandInterface */ public function __construct(StatusResolver $statusResolver = null) { - $this->statusResolver = $statusResolver - ? : ObjectManager::getInstance()->get(StatusResolver::class); + $this->statusResolver = $statusResolver ?: ObjectManager::getInstance()->get(StatusResolver::class); } /** + * Registers a capture event for this payment + * * @param OrderPaymentInterface $payment * @param string|float|int $amount * @param OrderInterface $order @@ -35,7 +41,11 @@ public function __construct(StatusResolver $statusResolver = null) */ public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order) { - $state = $order->getState() ?: Order::STATE_PROCESSING; + $state = $order->getState(); + if (!$state || $state === Order::STATE_NEW || $state === Order::STATE_PENDING_PAYMENT) { + $state = Order::STATE_PROCESSING; + } + $status = null; $message = 'Registered notification about captured amount of %1.'; @@ -61,6 +71,8 @@ public function execute(OrderPaymentInterface $payment, $amount, OrderInterface } /** + * Sets the state and status of the order + * * @deprecated 100.2.0 Replaced by a StatusResolver class call. * * @param Order $order diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/State/RegisterCaptureNotificationCommandTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/State/RegisterCaptureNotificationCommandTest.php index 1b762fafe0b71..c5c333e55a551 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/State/RegisterCaptureNotificationCommandTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/State/RegisterCaptureNotificationCommandTest.php @@ -80,6 +80,22 @@ public function commandResultDataProvider() $this->newOrderStatus, 'Registered notification about captured amount of %1.', ], + [ + false, + false, + Order::STATE_NEW, + Order::STATE_PROCESSING, + $this->newOrderStatus, + 'Registered notification about captured amount of %1.', + ], + [ + false, + false, + Order::STATE_PENDING_PAYMENT, + Order::STATE_PROCESSING, + $this->newOrderStatus, + 'Registered notification about captured amount of %1.', + ], [ true, false, From ff6365a275fda5a93fc591bad6fb11aeffc83225 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 10 Dec 2019 11:00:58 +0200 Subject: [PATCH 11/15] Static-test fix --- .../Framework/App/ObjectManager/ConfigLoader/Compiled.php | 2 +- lib/internal/Magento/Framework/DB/Select/SelectRenderer.php | 2 +- lib/internal/Magento/Framework/Module/Dir.php | 4 +--- lib/internal/Magento/Framework/Phrase/Renderer/Translate.php | 4 +--- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 7408e8b230bd9..50769e9e17774 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -9,7 +9,7 @@ use Magento\Framework\ObjectManager\ConfigLoaderInterface; /** - * Class Compiled + * Load configuration files */ class Compiled implements ConfigLoaderInterface { diff --git a/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php b/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php index ce53c07789bde..7c239913987a7 100644 --- a/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php +++ b/lib/internal/Magento/Framework/DB/Select/SelectRenderer.php @@ -8,7 +8,7 @@ use Magento\Framework\DB\Select; /** - * Class SelectRenderer + * Phrase renderer interface */ class SelectRenderer implements RendererInterface { diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 99570b97e7251..4a03d0edc49fd 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -1,7 +1,5 @@ Date: Tue, 24 Dec 2019 18:12:20 +0530 Subject: [PATCH 12/15] Added Fix for 26164 --- .../luma/Magento_Checkout/web/css/source/module/_cart.less | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_cart.less b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_cart.less index cbf1d185a5a08..87990c3e48280 100644 --- a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_cart.less +++ b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_cart.less @@ -267,6 +267,10 @@ .lib-icon-font-symbol( @_icon-font-content: @icon-trash ); + + &:hover { + .lib-css(text-decoration, @link__text-decoration); + } } } From 666d4c0ff2b3a498d97acd101ae1ec86592bee70 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Tue, 24 Dec 2019 18:29:37 +0530 Subject: [PATCH 13/15] Fixed Special Price class not added in configurable product page --- app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js index 894a4518f4de8..c80962a44d0dc 100644 --- a/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js @@ -952,6 +952,8 @@ define([ isShow = typeof result != 'undefined' && result.oldPrice.amount !== result.finalPrice.amount; + $productPrice.find('span:first').toggleClass('special-price',isShow); + $product.find(this.options.slyOldPriceSelector)[isShow ? 'show' : 'hide'](); if (typeof result != 'undefined' && result.tierPrices && result.tierPrices.length) { From e037d514215f9e662b5585a5ab967ca4edcde3af Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 26 Dec 2019 14:05:28 +0200 Subject: [PATCH 14/15] Fix static test, civer with jasmine test --- .../view/base/web/js/swatch-renderer.js | 2 +- .../frontend/web/js/swatch-renderer.test.js | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js index c80962a44d0dc..ee55beb440f59 100644 --- a/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js @@ -952,7 +952,7 @@ define([ isShow = typeof result != 'undefined' && result.oldPrice.amount !== result.finalPrice.amount; - $productPrice.find('span:first').toggleClass('special-price',isShow); + $productPrice.find('span:first').toggleClass('special-price', isShow); $product.find(this.options.slyOldPriceSelector)[isShow ? 'show' : 'hide'](); diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js index bf0ff3466c529..f486123ba0bd3 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js @@ -28,6 +28,7 @@ define([ id: optionId }] }; + widget.options = { classes: { optionClass: 'swatch-option' @@ -50,6 +51,7 @@ define([ } } }; + optionConfig = widget.options.jsonSwatchConfig[attribute.id]; html = $(widget._RenderSwatchOptions(attribute, 'option-label-control-id-1'))[0]; }); @@ -76,5 +78,25 @@ define([ expect(html.style.height).toEqual(swathImageHeight + 'px'); expect(html.style.width).toEqual(swathImageWidth + 'px'); }); + + it('check udate price method', function () { + var productPriceMock = { + find: jasmine.createSpy().and.returnValue({ + hide: jasmine.createSpy(), + priceBox: jasmine.createSpy().and.returnValue(''), + trigger: jasmine.createSpy(), + find: jasmine.createSpy().and.returnValue({ + toggleClass: jasmine.createSpy() + }) + }) + }; + + widget.element = { + parents: jasmine.createSpy().and.returnValue(productPriceMock) + }; + widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined); + widget._UpdatePrice(); + expect(productPriceMock.find().find.calls.count()).toBe(1); + }); }); }); From 0fb43446d90346f94c7e04ef52c7eecdcb597d1b Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Sun, 29 Dec 2019 12:49:14 -0600 Subject: [PATCH 15/15] Fix static --- .../Order/Payment/State/RegisterCaptureNotificationCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php b/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php index d8afcc71cc6af..2551092a64e9a 100644 --- a/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php +++ b/app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php @@ -14,7 +14,7 @@ /** * Class RegisterCaptureNotificationCommand * - * @package Magento\Sales\Model\Order\Payment\State + * Command that Register Capture Notification */ class RegisterCaptureNotificationCommand implements CommandInterface {