diff --git a/app/code/Magento/Backend/Block/System/Store/Edit/Form/Website.php b/app/code/Magento/Backend/Block/System/Store/Edit/Form/Website.php index a29e62fc1c81e73b2f084486a111ccbd8da130fa..7ecd92e26ce6901aa246671deca1a325799c05f2 100644 --- a/app/code/Magento/Backend/Block/System/Store/Edit/Form/Website.php +++ b/app/code/Magento/Backend/Block/System/Store/Edit/Form/Website.php @@ -108,7 +108,9 @@ class Website extends \Magento\Backend\Block\System\Store\Edit\AbstractForm ); } - if (!$websiteModel->getIsDefault() && $websiteModel->getStoresCount()) { + $hasOnlyDefaultStore = $websiteModel->getStoresCount() == 1 && + array_key_exists(\Magento\Store\Model\Store::DEFAULT_STORE_ID, $websiteModel->getStoreIds()); + if (!$websiteModel->getIsDefault() && $websiteModel->getStoresCount() && !$hasOnlyDefaultStore) { $fieldset->addField( 'is_default', 'checkbox', diff --git a/app/code/Magento/Backend/Helper/Dashboard/Order.php b/app/code/Magento/Backend/Helper/Dashboard/Order.php index ec6a5d3aeeabd37cf23d8a3b523276f8059ae84c..d8ece48d182e409baaed64ffe98bca31ce71360c 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Order.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Order.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Helper\Dashboard; +use Magento\Framework\App\ObjectManager; + /** * Adminhtml dashboard helper for orders */ @@ -15,6 +17,11 @@ class Order extends \Magento\Backend\Helper\Dashboard\AbstractDashboard */ protected $_orderCollection; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Reports\Model\ResourceModel\Order\Collection $orderCollection @@ -24,9 +31,18 @@ class Order extends \Magento\Backend\Helper\Dashboard\AbstractDashboard \Magento\Reports\Model\ResourceModel\Order\Collection $orderCollection ) { $this->_orderCollection = $orderCollection; - parent::__construct( - $context - ); + parent::__construct($context); + } + + /** + * @return \Magento\SalesRule\Model\RuleFactory + * @deprecated + */ + public function getStoreManager() + { + if ($this->_storeManager instanceof \Magento\Store\Model\StoreManagerInterface) { + $this->_storeManager = ObjectManager::getInstance()->get('\Magento\Store\Model\StoreManagerInterface'); + } } /** diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php index ffeed2a2d25f15ce6907d4816771fa3236c1d4ca..d25285265394847ca85fe04f58b02737a28ab166 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php @@ -43,6 +43,7 @@ class Websites extends \Magento\Ui\Component\Listing\Columns\Column /** * {@inheritdoc} + * @deprecated */ public function prepareDataSource(array $dataSource) { @@ -63,15 +64,16 @@ class Websites extends \Magento\Ui\Component\Listing\Columns\Column return $dataSource; } - + /** * Prepare component configuration * @return void */ public function prepare() { - if (!$this->storeManager->isSingleStoreMode()) { - parent::prepare(); + parent::prepare(); + if ($this->storeManager->isSingleStoreMode()) { + $this->_data['config']['componentDisabled'] = true; } } } diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml index 346b96024c8b245f2e6ae1cb6bb3404e4008044e..8f6792b862d2ce93c9e14e0086977ff83a3dd16f 100644 --- a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml +++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml @@ -230,7 +230,7 @@ </item> </argument> </column> - <column name="websites"> + <column name="websites" class="Magento\Catalog\Ui\Component\Listing\Columns\Websites"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\Store\Model\ResourceModel\Website\Collection</item> <item name="config" xsi:type="array"> diff --git a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Conditions.php b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Conditions.php index 3953bb9d6b79eb1432cb8fcda76f2f03059d41d1..50b60a5434aaf0bc3874aca6ba555ec86e589e91 100644 --- a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Conditions.php +++ b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Conditions.php @@ -153,7 +153,7 @@ class Conditions extends Generic implements TabInterface $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml') ->setNewChildUrl($newChildUrl) - ->setConditionsFieldSetId($model->getConditionsFieldSetId($formName)); + ->setFieldSetId($model->getConditionsFieldSetId($formName)); $fieldset = $form->addFieldset( $fieldsetId, diff --git a/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/fieldset.phtml b/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/fieldset.phtml index 714f80fd47e8acef6476318fa150a1228bd8bebb..3cd22ae688f37ad1e5f39e683688240ca5f75b9f 100644 --- a/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/fieldset.phtml +++ b/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/fieldset.phtml @@ -9,7 +9,7 @@ /**@var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $block */ ?> <?php $_element = $block->getElement() ?> -<?php $_jsObjectName = $block->getConditionsFieldSetId() != null ? $block->getConditionsFieldSetId() : $_element->getHtmlId() ?> +<?php $_jsObjectName = $block->getFieldSetId() != null ? $block->getFieldSetId() : $_element->getHtmlId() ?> <div class="rule-tree"> <fieldset id="<?php /* @escapeNotVerified */ echo $_jsObjectName ?>" <?php /* @escapeNotVerified */ echo $_element->serialize(['class']) ?> class="fieldset"> <legend class="legend"><span><?php /* @escapeNotVerified */ echo $_element->getLegend() ?></span></legend> diff --git a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml index 9d5a35b0cc3318bf9fceaccc594e2fb35079bc53..46973ff5cfcc743a36f1a43f4d838f148d4d2e15 100644 --- a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml +++ b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml @@ -171,7 +171,7 @@ </argument> </field> </fieldset> - <fieldset name="websites"> + <fieldset name="websites" class="Magento\Store\Ui\Component\Form\Fieldset\Websites"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="collapsible" xsi:type="boolean">true</item> diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Column/Websites.php b/app/code/Magento/Customer/Ui/Component/Listing/Column/Websites.php new file mode 100644 index 0000000000000000000000000000000000000000..fcd55c590dc50602320154a5cec79784463792b7 --- /dev/null +++ b/app/code/Magento/Customer/Ui/Component/Listing/Column/Websites.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Customer\Ui\Component\Listing\Column; + +use Magento\Framework\View\Element\UiComponent\ContextInterface; +use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Ui\Component\Listing\Columns\Column; +use Magento\Store\Model\StoreManagerInterface as StoreManager; + +/** + * Class Websites + */ +class Websites extends Column +{ + /** + * Store manager + * + * @var StoreManager + */ + protected $storeManager; + + /** + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory + * @param StoreManager $storeManager + * @param array $components + * @param array $data + */ + public function __construct( + ContextInterface $context, + UiComponentFactory $uiComponentFactory, + StoreManager $storeManager, + array $components = [], + array $data = [] + ) { + $this->storeManager = $storeManager; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare component configuration + * @return void + */ + public function prepare() + { + parent::prepare(); + if ($this->storeManager->isSingleStoreMode()) { + $this->_data['config']['componentDisabled'] = true; + } + } +} diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml index c6aa8a420e34216be37a3a5af03c67cdf42ce4cd..67bab36c9ccde0e3ec470b51523859b352d76239 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml @@ -245,7 +245,7 @@ </item> </argument> </column> - <column name="website_id"> + <column name="website_id" class="Magento\Customer\Ui\Component\Listing\Column\Websites"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="filter" xsi:type="string">select</item> diff --git a/app/code/Magento/OfflineShipping/view/adminhtml/ui_component/salesrulestaging_update_form.xml b/app/code/Magento/OfflineShipping/view/adminhtml/ui_component/salesrulestaging_update_form.xml new file mode 100644 index 0000000000000000000000000000000000000000..b568252e3cc32328769d074ac555a679f2f1b05f --- /dev/null +++ b/app/code/Magento/OfflineShipping/view/adminhtml/ui_component/salesrulestaging_update_form.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> + <fieldset name="actions"> + <field name="simple_free_shipping"> + <argument name="data" xsi:type="array"> + <item name="options" xsi:type="object">Magento\OfflineShipping\Model\Source\SalesRule\FreeShippingOptions</item> + <item name="config" xsi:type="array"> + <item name="dataType" xsi:type="string">text</item> + <item name="label" xsi:type="string" translate="true">Free Shipping</item> + <item name="formElement" xsi:type="string">select</item> + <item name="dataScope" xsi:type="string">simple_free_shipping</item> + <item name="caption" xsi:type="string" translate="true">-- Please Select --</item> + <item name="sortOrder" xsi:type="number">80</item> + </item> + </argument> + </field> + </fieldset> +</form> diff --git a/app/code/Magento/Sales/Setup/InstallSchema.php b/app/code/Magento/Sales/Setup/InstallSchema.php index 8e44a50adf15560144cd21fbad180e603a4f6a89..44ae3ff08b94f513264800e4344ceabd09a17a8b 100644 --- a/app/code/Magento/Sales/Setup/InstallSchema.php +++ b/app/code/Magento/Sales/Setup/InstallSchema.php @@ -3216,6 +3216,12 @@ class InstallSchema implements InstallSchemaInterface '12,4', [], 'Grand Total' + )->addColumn( + 'base_grand_total', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Base Grand Total' )->addColumn( 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, @@ -3234,6 +3240,9 @@ class InstallSchema implements InstallSchemaInterface )->addIndex( $installer->getIdxName('sales_invoice_grid', ['grand_total']), ['grand_total'] + )->addIndex( + $installer->getIdxName('sales_invoice_grid', ['base_grand_total']), + ['base_grand_total'] )->addIndex( $installer->getIdxName('sales_invoice_grid', ['order_id']), ['order_id'] diff --git a/app/code/Magento/Sales/etc/adminhtml/system.xml b/app/code/Magento/Sales/etc/adminhtml/system.xml index 2d242a4f2dc111a2440ec25a0a13c5daf16f908e..71436080a4f0ab5fd502a458deb660846730d2e5 100644 --- a/app/code/Magento/Sales/etc/adminhtml/system.xml +++ b/app/code/Magento/Sales/etc/adminhtml/system.xml @@ -109,7 +109,7 @@ <group id="dashboard" translate="label,comment" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Dashboard</label> <field id="use_aggregated_data" translate="label" sortOrder="10" type="select" showInDefault="1" showInWebsite="0" showInStore="0"> - <label>Use Aggregated Data (beta)</label> + <label>Use Aggregated Data</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <comment>Improves dashboard performance but provides non-realtime data.</comment> </field> diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 8d292379e56cf3a1c4d1d6e149db7e5d412320ca..ba75289a3e56cc8db058ac4ff3c3034fa7ca67b8 100644 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -634,6 +634,7 @@ <item name="shipping_information" xsi:type="string">sales_order.shipping_description</item> <item name="subtotal" xsi:type="string">sales_order.base_subtotal</item> <item name="shipping_and_handling" xsi:type="string">sales_order.base_shipping_amount</item> + <item name="base_grand_total" xsi:type="string">sales_invoice.base_grand_total</item> <item name="grand_total" xsi:type="string">sales_invoice.grand_total</item> <item name="created_at" xsi:type="string">sales_invoice.created_at</item> <item name="updated_at" xsi:type="string">sales_invoice.updated_at</item> diff --git a/app/code/Magento/Sales/i18n/en_US.csv b/app/code/Magento/Sales/i18n/en_US.csv index 7b3d38e9717b036a8e4e60051b57fad25f962f14..6b1649aa33f3e4722dd58753f5d217d0d101d243 100644 --- a/app/code/Magento/Sales/i18n/en_US.csv +++ b/app/code/Magento/Sales/i18n/en_US.csv @@ -615,7 +615,7 @@ Comma-separated,Comma-separated "We'll use the default description above if you leave this empty.","We'll use the default description above if you leave this empty." "Multi-address Error to Show in Shopping Cart","Multi-address Error to Show in Shopping Cart" "We'll use the default error above if you leave this empty.","We'll use the default error above if you leave this empty." -"Use Aggregated Data (beta)","Use Aggregated Data (beta)" +"Use Aggregated Data","Use Aggregated Data" "Sales Emails","Sales Emails" "New Order Confirmation Email Sender","New Order Confirmation Email Sender" "New Order Confirmation Template","New Order Confirmation Template" diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml index b2e8253437495a49bd9871617e87c94ab17ff72a..f5e5b9067caf2ac8a995de41cd2b26f0e2da5285 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml @@ -141,11 +141,19 @@ </item> </argument> </column> - <column name="grand_total" class="Magento\Sales\Ui\Component\Listing\Column\Price"> + <column name="base_grand_total" class="Magento\Sales\Ui\Component\Listing\Column\Price"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="filter" xsi:type="string">textRange</item> - <item name="label" xsi:type="string" translate="true">Amount</item> + <item name="label" xsi:type="string" translate="true">Grand Total (Base)</item> + </item> + </argument> + </column> + <column name="grand_total" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice"> + <argument name="data" xsi:type="array"> + <item name="config" xsi:type="array"> + <item name="filter" xsi:type="string">textRange</item> + <item name="label" xsi:type="string" translate="true">Grand Total (Purchased)</item> </item> </argument> </column> diff --git a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.php b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.php index 52716b88e8ab602c1848ee3afe2b4a05c889bc2d..f0e265f203ca6c19d35fbe6445a9bf717123c539 100644 --- a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.php +++ b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.php @@ -5,6 +5,8 @@ */ namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab; +use Magento\Framework\App\ObjectManager; + class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Ui\Component\Layout\Tabs\TabInterface { @@ -22,6 +24,7 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements /** * @var \Magento\Config\Model\Config\Source\Yesno + * @deprecated */ protected $_sourceYesno; @@ -31,6 +34,13 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements protected $_nameInLayout = 'actions_apply_to'; /** + * @var \Magento\SalesRule\Model\RuleFactory + */ + private $ruleFactory; + + /** + * Initialize dependencies. + * * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Data\FormFactory $formFactory @@ -54,6 +64,17 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements parent::__construct($context, $registry, $formFactory, $data); } + /** + * @return \Magento\SalesRule\Model\RuleFactory + * @deprecated + */ + public function getRuleFactory() + { + if ($this->ruleFactory instanceof \Magento\SalesRule\Model\RuleFactory) { + $this->ruleFactory = ObjectManager::getInstance()->get('\Magento\SalesRule\Model\RuleFactory'); + } + } + /** * {@inheritdoc} * @codeCoverageIgnore @@ -121,24 +142,53 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements * Prepare form before rendering HTML * * @return $this - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareForm() { $model = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); + $form = $this->addTabToForm($model); + $this->setForm($form); + + return parent::_prepareForm(); + } + + /** + * Handles addition of actions tab to supplied form. + * + * @param \Magento\SalesRule\Model\Rule $model + * @param string $fieldsetId + * @param string $formName + * @return \Magento\Framework\Data\Form + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formName = 'sales_rule_form') + { + if (!$model) { + $id = $this->getRequest()->getParam('id'); + $model = $this->ruleFactory->create(); + $model->load($id); + } + + $actionsFieldSetId = $model->getActionsFieldSetId($formName); + + $newChildUrl = $this->getUrl( + 'sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset_' . $actionsFieldSetId, + ['form_namespace' => $formName] + ); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); - $renderer = $this->_rendererFieldset->setTemplate( 'Magento_CatalogRule::promo/fieldset.phtml' )->setNewChildUrl( - $this->getUrl('sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset') + $newChildUrl + )->setFieldSetId( + $actionsFieldSetId ); $fieldset = $form->addFieldset( - 'actions_fieldset', + $fieldsetId, [ 'legend' => __( 'Apply the rule only to cart items matching the following conditions ' . @@ -157,7 +207,7 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true, - 'data-form-part' => 'sales_rule_form' + 'data-form-part' => $formName ] )->setRule( $model @@ -168,6 +218,7 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements $this->_eventManager->dispatch('adminhtml_block_salesrule_actions_prepareform', ['form' => $form]); $form->setValues($model->getData()); + $this->setActionFormName($model->getActions(), $formName); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { @@ -175,7 +226,23 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements } } - $this->setForm($form); - return parent::_prepareForm(); + return $form; + } + + /** + * Handles addition of form name to action and its actions. + * + * @param \Magento\Rule\Model\Condition\AbstractCondition $actions + * @param string $formName + * @return void + */ + private function setActionFormName(\Magento\Rule\Model\Condition\AbstractCondition $actions, $formName) + { + $actions->setFormName($formName); + if ($actions->getActions() && is_array($actions->getActions())) { + foreach ($actions->getActions() as $condition) { + $this->setActionFormName($condition, $formName); + } + } } } diff --git a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php index 0e1d292b2958310977a029f17f0da63df6e0ea5c..7aed719f41b329f6bbf5d327ae44edb949a5d9b0 100644 --- a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php +++ b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php @@ -5,6 +5,8 @@ */ namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab; +use Magento\Framework\App\ObjectManager; + class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Ui\Component\Layout\Tabs\TabInterface { @@ -26,6 +28,13 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements protected $_nameInLayout = 'conditions_apply_to'; /** + * @var \Magento\SalesRule\Model\RuleFactory + */ + private $ruleFactory; + + /** + * Initialize dependencies. + * * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Data\FormFactory $formFactory @@ -46,6 +55,17 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements parent::__construct($context, $registry, $formFactory, $data); } + /** + * @return \Magento\SalesRule\Model\RuleFactory + * @deprecated + */ + public function getRuleFactory() + { + if ($this->ruleFactory instanceof \Magento\SalesRule\Model\RuleFactory) { + $this->ruleFactory = ObjectManager::getInstance()->get('\Magento\SalesRule\Model\RuleFactory'); + } + } + /** * {@inheritdoc} * @codeCoverageIgnore @@ -117,19 +137,47 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements protected function _prepareForm() { $model = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); + $form = $this->addTabToForm($model); + $this->setForm($form); + + return parent::_prepareForm(); + } + + /** + * Handles addition of conditions tab to supplied form. + * + * @param \Magento\SalesRule\Model\Rule $model + * @param string $fieldsetId + * @param string $formName + * @return \Magento\Framework\Data\Form + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form') + { + if (!$model) { + $id = $this->getRequest()->getParam('id'); + $model = $this->ruleFactory->create(); + $model->load($id); + } + $conditionsFieldSetId = $model->getConditionsFieldSetId($formName); + $newChildUrl = $this->getUrl( + 'sales_rule/promo_quote/newConditionHtml/form/' . $conditionsFieldSetId, + ['form_namespace' => $formName] + ); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); - $renderer = $this->_rendererFieldset->setTemplate( 'Magento_CatalogRule::promo/fieldset.phtml' )->setNewChildUrl( - $this->getUrl('sales_rule/promo_quote/newConditionHtml/form/rule_conditions_fieldset') + $newChildUrl + )->setFieldSetId( + $conditionsFieldSetId ); $fieldset = $form->addFieldset( - 'conditions_fieldset', + $fieldsetId, [ 'legend' => __( 'Apply the rule only if the following conditions are met (leave blank for all products).' @@ -138,16 +186,15 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements )->setRenderer( $renderer ); - $fieldset->addField( 'conditions', 'text', [ - 'name' => 'conditions', - 'label' => __('Conditions'), - 'title' => __('Conditions'), - 'required' => true, - 'data-form-part' => 'sales_rule_form' + 'name' => 'conditions', + 'label' => __('Conditions'), + 'title' => __('Conditions'), + 'required' => true, + 'data-form-part' => $formName ] )->setRule( $model @@ -156,8 +203,24 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements ); $form->setValues($model->getData()); - $this->setForm($form); + $this->setConditionFormName($model->getConditions(), $formName); + return $form; + } - return parent::_prepareForm(); + /** + * Handles addition of form name to condition and its conditions. + * + * @param \Magento\Rule\Model\Condition\AbstractCondition $conditions + * @param string $formName + * @return void + */ + private function setConditionFormName(\Magento\Rule\Model\Condition\AbstractCondition $conditions, $formName) + { + $conditions->setFormName($formName); + if ($conditions->getConditions() && is_array($conditions->getConditions())) { + foreach ($conditions->getConditions() as $condition) { + $this->setConditionFormName($condition, $formName); + } + } } } diff --git a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php index 1e9ae7645d574b8c9b3a396bab0821179a8d27b2..213db3a3c98e56c65eb9aa560c571b1424a260b0 100644 --- a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php +++ b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php @@ -8,6 +8,31 @@ namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab; class Labels extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Ui\Component\Layout\Tabs\TabInterface { + /** + * @var \Magento\SalesRule\Model\RuleFactory + */ + private $ruleFactory; + + /** + * Initialize dependencies. + * + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param \Magento\SalesRule\Model\RuleFactory $ruleFactory + * @param array $data + */ + public function __construct( + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + \Magento\SalesRule\Model\RuleFactory $ruleFactory, + array $data = [] + ) { + $this->ruleFactory = $ruleFactory; + parent::__construct($context, $registry, $formFactory, $data); + } + /** * @var string */ @@ -83,7 +108,13 @@ class Labels extends \Magento\Backend\Block\Widget\Form\Generic implements */ protected function _prepareForm() { - $rule = $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); + $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); + + if (!$rule) { + $id = $this->getRequest()->getParam('id'); + $rule = $this->ruleFactory->create(); + $rule->load($id); + } /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php index e1cb1f5a19a4f9a2f10ed48211fae21a038b18e4..57f45b87a9bd1e647baffa934942a25e133c4ca6 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php @@ -65,10 +65,14 @@ class Edit extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote $model->addData($data); } - $model->getConditions()->setJsFormObject('rule_conditions_fieldset'); $model->getConditions()->setFormName('sales_rule_form'); - $model->getActions()->setJsFormObject('rule_actions_fieldset'); + $model->getConditions()->setJsFormObject( + $model->getConditionsFieldSetId($model->getConditions()->getFormName()) + ); $model->getActions()->setFormName('sales_rule_form'); + $model->getActions()->setJsFormObject( + $model->getActionsFieldSetId($model->getActions()->getFormName()) + ); $this->_initAction(); diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php index cf383bfed2d0c28b46e728a2bdc40425458018f3..061890e406ddf70a98dedc57babda6efbe195c0c 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php @@ -16,6 +16,7 @@ class NewActionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote public function execute() { $id = $this->getRequest()->getParam('id'); + $formName = $this->getRequest()->getParam('form_namespace'); $typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type'))); $type = $typeArr[0]; @@ -35,7 +36,7 @@ class NewActionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote } if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) { - $model->setJsFormObject($this->getRequest()->getParam('form')); + $model->setJsFormObject($formName); $html = $model->asHtmlRecursive(); } else { $html = ''; diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php index fb0c502a37e1a72734f9d26507ad47ec16e46bb3..dd71d81f871775bed8beba332ad8ff4b89fb020e 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php @@ -16,6 +16,7 @@ class NewConditionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quo public function execute() { $id = $this->getRequest()->getParam('id'); + $formName = $this->getRequest()->getParam('form_namespace'); $typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type'))); $type = $typeArr[0]; @@ -36,6 +37,7 @@ class NewConditionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quo if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) { $model->setJsFormObject($this->getRequest()->getParam('form')); + $model->setFormName($formName); $html = $model->asHtmlRecursive(); } else { $html = ''; diff --git a/app/code/Magento/SalesRule/Model/ResourceModel/Rule.php b/app/code/Magento/SalesRule/Model/ResourceModel/Rule.php index fea1326e605307bcadf9ba892e0baa69d35f3345..122bee0b2c38abed6ed57b149e82eb3355b5c85b 100644 --- a/app/code/Magento/SalesRule/Model/ResourceModel/Rule.php +++ b/app/code/Magento/SalesRule/Model/ResourceModel/Rule.php @@ -403,4 +403,30 @@ class Rule extends AbstractResource } return $this; } + + /** + * Delete the object + * + * @param \Magento\Framework\Model\AbstractModel $object + * @return $this + * @throws \Exception + */ + public function delete(AbstractModel $object) + { + $this->transactionManager->start($this->getConnection()); + try { + $object->beforeDelete(); + $this->_beforeDelete($object); + $this->entityManager->delete('Magento\SalesRule\Api\Data\RuleInterface', $object); + $this->_afterDelete($object); + $object->isDeleted(true); + $object->afterDelete(); + $this->transactionManager->commit(); + $object->afterDeleteCommit(); + } catch (\Exception $exception) { + $this->transactionManager->rollBack(); + throw $exception; + } + return $this; + } } diff --git a/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php b/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php index 209ba4be22a40eb52fff869712d23a01033fddd9..bd9f6872d1f912923bdfcbf8876a40757a6f95e1 100644 --- a/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php +++ b/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php @@ -11,9 +11,8 @@ namespace Magento\SalesRule\Model\ResourceModel\Rule; use Magento\Quote\Model\Quote\Address; /** - * Sales Rules resource collection model - * - * @author Magento Core Team <core@magentocommerce.com> + * Sales Rules resource collection model. + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection { @@ -73,6 +72,52 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr $this->_map['fields']['rule_id'] = 'main_table.rule_id'; } + /** + * @param string $entityType + * @param string $objectField + * @throws \Magento\Framework\Exception\LocalizedException + * @return void + */ + protected function mapAssociatedEntities($entityType, $objectField) + { + if (!$this->_items) { + return; + } + + $entityInfo = $this->_getAssociatedEntityInfo($entityType); + $ruleIdField = $entityInfo['rule_id_field']; + $entityIds = $this->getColumnValues($ruleIdField); + + $select = $this->getConnection()->select()->from( + $this->getTable($entityInfo['associations_table']) + )->where( + $ruleIdField . ' IN (?)', + $entityIds + ); + + $associatedEntities = $this->getConnection()->fetchAll($select); + + array_map(function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField) { + $item = $this->getItemByColumnValue($ruleIdField, $associatedEntity[$ruleIdField]); + $itemAssociatedValue = $item->getData($objectField) === null ? [] : $item->getData($objectField); + $itemAssociatedValue[] = $associatedEntity[$entityInfo['entity_id_field']]; + $item->setData($objectField, $itemAssociatedValue); + }, $associatedEntities); + } + + /** + * @return $this + * @throws \Exception + */ + protected function _afterLoad() + { + $this->mapAssociatedEntities('website', 'website_ids'); + $this->mapAssociatedEntities('customer_group', 'customer_group_ids'); + + $this->setFlag('add_websites_to_result', false); + return parent::_afterLoad(); + } + /** * Filter collection by specified website, customer group, coupon code, date. * Filter collection to use only active rules. @@ -253,4 +298,27 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr return $this; } + + /** + * Limit rules collection by specific customer group + * + * @param int $customerGroupId + * @return $this + */ + public function addCustomerGroupFilter($customerGroupId) + { + $entityInfo = $this->_getAssociatedEntityInfo('customer_group'); + if (!$this->getFlag('is_customer_group_joined')) { + $this->setFlag('is_customer_group_joined', true); + $this->getSelect()->join( + ['customer_group' => $this->getTable($entityInfo['associations_table'])], + $this->getConnection() + ->quoteInto('customer_group.' . $entityInfo['entity_id_field'] . ' = ?', $customerGroupId) + . ' AND main_table.' . $entityInfo['rule_id_field'] . ' = customer_group.' + . $entityInfo['rule_id_field'], + [] + ); + } + return $this; + } } diff --git a/app/code/Magento/SalesRule/Model/Rule.php b/app/code/Magento/SalesRule/Model/Rule.php index a171769505db56b20f1999228ff70d69c994486b..6a6382bb938ee584b56d813e5d3dbb6915ab96ac 100644 --- a/app/code/Magento/SalesRule/Model/Rule.php +++ b/app/code/Magento/SalesRule/Model/Rule.php @@ -598,4 +598,22 @@ class Rule extends \Magento\Rule\Model\AbstractModel } return $address; } + + /** + * @param string $formName + * @return string + */ + public function getConditionsFieldSetId($formName = '') + { + return $formName . 'rule_conditions_fieldset_' . $this->getId(); + } + + /** + * @param string $formName + * @return string + */ + public function getActionsFieldSetId($formName = '') + { + return $formName . 'rule_actions_fieldset_' . $this->getId(); + } } diff --git a/app/code/Magento/SalesRule/Model/Rule/DataProvider.php b/app/code/Magento/SalesRule/Model/Rule/DataProvider.php index 768ec754e0a2fde083f9597bd1b83a137533a714..79bde496876fd735e6d2016d8c6884f9fa6a262e 100644 --- a/app/code/Magento/SalesRule/Model/Rule/DataProvider.php +++ b/app/code/Magento/SalesRule/Model/Rule/DataProvider.php @@ -8,14 +8,9 @@ namespace Magento\SalesRule\Model\Rule; use Magento\SalesRule\Model\ResourceModel\Rule\Collection; use Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory; use Magento\SalesRule\Model\Rule; -use Magento\Store\Model\System\Store; -use Magento\Customer\Api\GroupRepositoryInterface; -use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Framework\Convert\DataObject; /** * Class DataProvider - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider { @@ -29,31 +24,6 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider */ protected $loadedData; - /** - * @var Store - */ - protected $store; - - /** - * @var GroupRepositoryInterface - */ - protected $groupRepository; - - /** - * @var SearchCriteriaBuilder - */ - protected $searchCriteriaBuilder; - - /** - * @var DataObject - */ - protected $objectConverter; - - /** - * @var \Magento\SalesRule\Model\RuleFactory - */ - protected $salesRuleFactory; - /** * Core registry * @@ -62,203 +32,52 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider protected $coreRegistry; /** - * DataProvider constructor. + * @var \Magento\SalesRule\Model\Rule\Metadata\ValueProvider + */ + protected $metadataValueProvider; + + /** + * Initialize dependencies. * * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $collectionFactory - * @param Store $store - * @param GroupRepositoryInterface $groupRepository - * @param SearchCriteriaBuilder $searchCriteriaBuilder - * @param DataObject $objectConverter - * @param \Magento\SalesRule\Model\RuleFactory $salesRuleFactory * @param \Magento\Framework\Registry $registry + * @param Metadata\ValueProvider $metadataValueProvider * @param array $meta * @param array $data - * - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, - Store $store, - GroupRepositoryInterface $groupRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, - DataObject $objectConverter, - \Magento\SalesRule\Model\RuleFactory $salesRuleFactory, \Magento\Framework\Registry $registry, + \Magento\SalesRule\Model\Rule\Metadata\ValueProvider $metadataValueProvider, array $meta = [], array $data = [] ) { - parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->collection = $collectionFactory->create(); - $this->store = $store; - $this->groupRepository = $groupRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->objectConverter = $objectConverter; - $this->salesRuleFactory = $salesRuleFactory; $this->coreRegistry = $registry; - $this->initMeta(); + $this->metadataValueProvider = $metadataValueProvider; + $meta = array_replace_recursive($this->getMetadataValues(), $meta); + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Get metadata values + * + * @return array */ - protected function initMeta() + protected function getMetadataValues() { - $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems(); - $applyOptions = [ - ['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION], - ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION], - ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION], - ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION] - ]; - - $couponTypesOptions = []; - $couponTypes = $this->salesRuleFactory->create()->getCouponTypes(); - foreach ($couponTypes as $key => $couponType) { - $couponTypesOptions[] = [ - 'label' => $couponType, - 'value' => $key, - ]; - } - $rule = $this->coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); - $labels = $rule->getStoreLabels(); - - $this->meta = [ - 'rule_information' => [ - 'children' => [ - 'website_ids' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => $this->store->getWebsiteValuesForForm(), - ], - ], - ], - ], - 'is_active' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => [ - ['label' => __('Active'), 'value' => '1'], - ['label' => __('Inactive'), 'value' => '0'] - ], - ], - ], - ], - ], - 'customer_group_ids' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code'), - ], - ], - ], - ], - 'coupon_type' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => $couponTypesOptions, - ], - ], - ], - ], - 'is_rss' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => [ - ['label' => __('Yes'), 'value' => '1'], - ['label' => __('No'), 'value' => '0'] - ], - ], - ], - ], - ], - ] - ], - 'actions' => [ - 'children' => [ - 'simple_action' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => $applyOptions - ], - ] - ] - ], - 'discount_amount' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'value' => '0', - ], - ], - ], - ], - 'discount_qty' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'value' => '0', - ], - ], - ], - ], - 'apply_to_shipping' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => [ - ['label' => __('Yes'), 'value' => '1'], - ['label' => __('No'), 'value' => '0'] - ] - ], - ], - ], - ], - 'stop_rules_processing' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'options' => [ - ['label' => __('Yes'), 'value' => '1'], - ['label' => __('No'), 'value' => '0'], - ], - ], - ] - ] - ], - ] - ], - 'labels' => [ - 'children' => [ - 'store_labels[0]' => [ - 'arguments' => [ - 'data' => [ - 'config' => [ - 'value' => isset($labels[0]) ? $labels[0] : '', - ], - ] - ] - ] - ] - ], - ]; + return $this->metadataValueProvider->getMetadataValues($rule); } /** - * @return array + * {@inheritdoc} */ public function getData() { diff --git a/app/code/Magento/SalesRule/Model/Rule/Metadata/ValueProvider.php b/app/code/Magento/SalesRule/Model/Rule/Metadata/ValueProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..f2845b5522ec292c46c649a682bc5105b8b684d5 --- /dev/null +++ b/app/code/Magento/SalesRule/Model/Rule/Metadata/ValueProvider.php @@ -0,0 +1,222 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\SalesRule\Model\Rule\Metadata; + +use Magento\SalesRule\Model\ResourceModel\Rule\Collection; +use Magento\SalesRule\Model\Rule; +use Magento\Store\Model\System\Store; +use Magento\Customer\Api\GroupRepositoryInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Convert\DataObject; + +/** + * Metadata provider for sales rule edit form. + */ +class ValueProvider +{ + /** + * @var Store + */ + protected $store; + + /** + * @var GroupRepositoryInterface + */ + protected $groupRepository; + + /** + * @var SearchCriteriaBuilder + */ + protected $searchCriteriaBuilder; + + /** + * @var DataObject + */ + protected $objectConverter; + + /** + * @var \Magento\SalesRule\Model\RuleFactory + */ + protected $salesRuleFactory; + + /** + * Initialize dependencies. + * + * @param Store $store + * @param GroupRepositoryInterface $groupRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param DataObject $objectConverter + * @param \Magento\SalesRule\Model\RuleFactory $salesRuleFactory + */ + public function __construct( + Store $store, + GroupRepositoryInterface $groupRepository, + SearchCriteriaBuilder $searchCriteriaBuilder, + DataObject $objectConverter, + \Magento\SalesRule\Model\RuleFactory $salesRuleFactory + ) { + $this->store = $store; + $this->groupRepository = $groupRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->objectConverter = $objectConverter; + $this->salesRuleFactory = $salesRuleFactory; + } + + /** + * Get metadata for sales rule form. It will be merged with form UI component declaration. + * + * @param Rule $rule + * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule) + { + $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems(); + $applyOptions = [ + ['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION], + ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION], + ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::BY_PERCENT_ACTION], + ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION] + ]; + + $couponTypesOptions = []; + $couponTypes = $this->salesRuleFactory->create()->getCouponTypes(); + foreach ($couponTypes as $key => $couponType) { + $couponTypesOptions[] = [ + 'label' => $couponType, + 'value' => $key, + ]; + } + + $labels = $rule->getStoreLabels(); + + return [ + 'rule_information' => [ + 'children' => [ + 'website_ids' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => $this->store->getWebsiteValuesForForm(), + ], + ], + ], + ], + 'is_active' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => [ + ['label' => __('Active'), 'value' => '1'], + ['label' => __('Inactive'), 'value' => '0'] + ], + ], + ], + ], + ], + 'customer_group_ids' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code'), + ], + ], + ], + ], + 'coupon_type' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => $couponTypesOptions, + ], + ], + ], + ], + 'is_rss' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => [ + ['label' => __('Yes'), 'value' => '1'], + ['label' => __('No'), 'value' => '0'] + ], + ], + ], + ], + ], + ] + ], + 'actions' => [ + 'children' => [ + 'simple_action' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => $applyOptions + ], + ] + ] + ], + 'discount_amount' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'value' => '0', + ], + ], + ], + ], + 'discount_qty' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'value' => '0', + ], + ], + ], + ], + 'apply_to_shipping' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => [ + ['label' => __('Yes'), 'value' => '1'], + ['label' => __('No'), 'value' => '0'] + ] + ], + ], + ], + ], + 'stop_rules_processing' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'options' => [ + ['label' => __('Yes'), 'value' => '1'], + ['label' => __('No'), 'value' => '0'], + ], + ], + ] + ] + ], + ] + ], + 'labels' => [ + 'children' => [ + 'store_labels[0]' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'value' => isset($labels[0]) ? $labels[0] : '', + ], + ] + ] + ] + ] + ], + ]; + } +} diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/RuleTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/RuleTest.php index a3a74f10ecb26295767a61cab45f7ec5cfdfd638..dc09ba26f904842fa531cf94e039f0d2253002a3 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/RuleTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/RuleTest.php @@ -80,7 +80,7 @@ class RuleTest extends \PHPUnit_Framework_TestCase ->willReturn($this->resourcesMock); $this->entityManager = $this->getMockBuilder('Magento\Framework\Model\EntityManager') - ->setMethods(['load', 'save']) + ->setMethods(['load', 'save', 'delete']) ->disableOriginalConstructor() ->getMock(); @@ -125,7 +125,7 @@ class RuleTest extends \PHPUnit_Framework_TestCase 'context' => $context, 'connectionName' => $connectionName, 'associatedEntitiesMap' => $associatedEntitiesMap, - 'entityManager' => $this->entityManager + 'entityManager' => $this->entityManager, ] ); } @@ -310,4 +310,38 @@ class RuleTest extends \PHPUnit_Framework_TestCase return $abstractModelMock; } + + public function testDeleteSuccess() + { + $this->transactionManagerMock->expects($this->once())->method('start'); + $abstractModelMock = $this->getMockBuilder('Magento\Rule\Model\AbstractModel') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $abstractModelMock->expects($this->once())->method('beforeDelete'); + $this->entityManager->expects($this->once())->method('delete'); + $abstractModelMock->expects($this->once())->method('isDeleted'); + $abstractModelMock->expects($this->once())->method('afterDelete'); + $this->transactionManagerMock->expects($this->once())->method('commit'); + + $this->model->delete($abstractModelMock); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage To test exception + */ + public function testDeletionRollbackOnFailure() + { + $expectedException = new \Exception(__('To test exception')); + $this->transactionManagerMock->expects($this->once())->method('start'); + $abstractModelMock = $this->getMockBuilder('Magento\Rule\Model\AbstractModel') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $abstractModelMock->expects($this->once())->method('beforeDelete')->willThrowException($expectedException); + $this->transactionManagerMock->expects($this->once())->method('rollBack'); + + $this->model->delete($abstractModelMock); + } } diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Rule/DataProviderTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/DataProviderTest.php index 385443fc5ef38978e68b5d859325f4bd00f80186..aeb0508c8f3b63156c978ab695b9ee2ce50e0415 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/Rule/DataProviderTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/DataProviderTest.php @@ -53,16 +53,6 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase '', false ); - $this->searchCriteriaBuilderMock = $this->getMock( - 'Magento\Framework\Api\SearchCriteriaBuilder', - [], - [], - '', - false - ); - $this->storeMock = $this->getMock('Magento\Store\Model\System\Store', [], [], '', false); - $this->groupRepositoryMock = $this->getMock('Magento\Customer\Api\GroupRepositoryInterface', [], [], '', false); - $this->dataObjectMock = $this->getMock('Magento\Framework\Convert\DataObject', [], [], '', false); $this->collectionMock = $this->getMock( 'Magento\SalesRule\Model\ResourceModel\Rule\Collection', @@ -72,48 +62,16 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase false ); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); - $searchCriteriaMock = $this->getMock('Magento\Framework\Api\SearchCriteriaInterface', [], [], '', false); - $groupSearchResultsMock = $this->getMock( - 'Magento\Customer\Api\Data\GroupSearchResultsInterface', - [], - [], - '', - false - ); - $groupsMock = $this->getMock('Magento\Customer\Api\Data\GroupInterface', [], [], '', false); - - $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock); - $this->groupRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock) - ->willReturn($groupSearchResultsMock); - $groupSearchResultsMock->expects($this->once())->method('getItems')->willReturn([$groupsMock]); - $this->storeMock->expects($this->once())->method('getWebsiteValuesForForm')->willReturn([]); - $this->dataObjectMock->expects($this->once())->method('toOptionArray')->with([$groupsMock], 'id', 'code') - ->willReturn([]); - $ruleFactoryMock = $this->getMock('Magento\SalesRule\Model\RuleFactory', ['create'], [], '', false); $ruleMock = $this->getMock('Magento\SalesRule\Model\Rule', [], [], '', false); - $ruleFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($ruleMock); - $ruleMock->expects($this->once()) - ->method('getCouponTypes') - ->willReturn( - [ - 'key1' => 'couponType1', - 'key2' => 'couponType2', - ] - ); + $metaDataValueProviderMock = $this->getMockBuilder('Magento\SalesRule\Model\Rule\Metadata\ValueProvider') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); $registryMock = $this->getMock('Magento\Framework\Registry', [], [], '', false); $registryMock->expects($this->once()) ->method('registry') ->willReturn($ruleMock); - $ruleMock->expects($this->once()) - ->method('getStoreLabels') - ->willReturn( - [ - 'label0', - 'label1', - ] - ); + $metaDataValueProviderMock->expects($this->once())->method('getMetadataValues')->willReturn(['data']); $this->model = (new ObjectManager($this))->getObject( 'Magento\SalesRule\Model\Rule\DataProvider', [ @@ -121,12 +79,8 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase 'primaryFieldName' => 'Primary', 'requestFieldName' => 'Request', 'collectionFactory' => $this->collectionFactoryMock, - 'store' => $this->storeMock, - 'groupRepository' => $this->groupRepositoryMock, - 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, - 'objectConverter' => $this->dataObjectMock, - 'salesRuleFactory' => $ruleFactoryMock, 'registry' => $registryMock, + 'metadataValueProvider' => $metaDataValueProviderMock ] ); } diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/ValueProviderTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/ValueProviderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..43f3d5c7143df489abe9bb4d92dbbcfc5be4c8db --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/ValueProviderTest.php @@ -0,0 +1,114 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\SalesRule\Test\Unit\Model\Rule\Metadata; + +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +/** + * @covers Magento\SalesRule\Model\Rule\Metadata\ValueProvider + */ +class ValueProviderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\SalesRule\Model\Rule\Metadata\ValueProvider + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $storeMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $groupRepositoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $searchCriteriaBuilderMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $dataObjectMock; + + /** + * @var \Magento\SalesRule\Model\RuleFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $ruleFactoryMock; + + protected function setUp() + { + $this->searchCriteriaBuilderMock = $this->getMock( + 'Magento\Framework\Api\SearchCriteriaBuilder', + [], + [], + '', + false + ); + $this->storeMock = $this->getMock('Magento\Store\Model\System\Store', [], [], '', false); + $this->groupRepositoryMock = $this->getMock('Magento\Customer\Api\GroupRepositoryInterface', [], [], '', false); + $this->dataObjectMock = $this->getMock('Magento\Framework\Convert\DataObject', [], [], '', false); + $searchCriteriaMock = $this->getMock('Magento\Framework\Api\SearchCriteriaInterface', [], [], '', false); + $groupSearchResultsMock = $this->getMock( + 'Magento\Customer\Api\Data\GroupSearchResultsInterface', + [], + [], + '', + false + ); + $groupsMock = $this->getMock('Magento\Customer\Api\Data\GroupInterface', [], [], '', false); + + $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock); + $this->groupRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock) + ->willReturn($groupSearchResultsMock); + $groupSearchResultsMock->expects($this->once())->method('getItems')->willReturn([$groupsMock]); + $this->storeMock->expects($this->once())->method('getWebsiteValuesForForm')->willReturn([]); + $this->dataObjectMock->expects($this->once())->method('toOptionArray')->with([$groupsMock], 'id', 'code') + ->willReturn([]); + $this->ruleFactoryMock = $this->getMock('Magento\SalesRule\Model\RuleFactory', ['create'], [], '', false); + $this->model = (new ObjectManager($this))->getObject( + 'Magento\SalesRule\Model\Rule\Metadata\ValueProvider', + [ + 'store' => $this->storeMock, + 'groupRepository' => $this->groupRepositoryMock, + 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, + 'objectConverter' => $this->dataObjectMock, + 'salesRuleFactory' => $this->ruleFactoryMock, + ] + ); + } + + public function testGetMetadataValues() + { + $expectedData = include __DIR__ . '/_files/MetaData.php'; + + /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleMock */ + $ruleMock = $this->getMock('Magento\SalesRule\Model\Rule', [], [], '', false); + $this->ruleFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($ruleMock); + $ruleMock->expects($this->once()) + ->method('getCouponTypes') + ->willReturn( + [ + 'key1' => 'couponType1', + 'key2' => 'couponType2', + ] + ); + $ruleMock->expects($this->once()) + ->method('getStoreLabels') + ->willReturn( + [ + 'label0' + ] + ); + $test = $this->model->getMetadataValues($ruleMock); + $this->assertEquals($expectedData, $test); + } +} diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/_files/MetaData.php b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/_files/MetaData.php new file mode 100644 index 0000000000000000000000000000000000000000..d93c504af9e71c7490c304f6b5fd43e87c335daa --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Rule/Metadata/_files/MetaData.php @@ -0,0 +1,170 @@ +<?php +return [ + 'rule_information' => + [ + 'children' => + [ + 'website_ids' => ['arguments' => ['data' => ['config' => ['options' => []]]]], + 'is_active' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + 'options' => + [ + [ + 'label' => __('Active'), + 'value' => '1', + ], + [ + 'label' => __('Inactive'), + 'value' => '0', + ], + ], + ], + ], + ], + ], + 'customer_group_ids' => ['arguments' => ['data' => ['config' => ['options' => []]]]], + 'coupon_type' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + 'options' => + [ + [ + 'label' => 'couponType1', + 'value' => 'key1', + ], + [ + 'label' => 'couponType2', + 'value' => 'key2', + ], + ], + ], + ], + ], + ], + 'is_rss' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + 'options' => + [ + [ + 'label' => __('Yes'), + 'value' => '1', + ], + [ + 'label' => __('No'), + 'value' => '0', + ], + ], + ], + ], + ], + ], + ], + ], + 'actions' => + [ + 'children' => + [ + 'simple_action' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + 'options' => + [ + [ + 'label' => __('Percent of product price discount'), + 'value' => 'by_percent', + ], + [ + 'label' => __('Fixed amount discount'), + 'value' => 'by_fixed', + ], + [ + 'label' => __('Fixed amount discount for whole cart'), + 'value' => 'by_percent', + ], + [ + 'label' => __( + 'Buy X get Y free (discount amount is Y)' + ), + 'value' => 'buy_x_get_y', + ], + ], + ], + ], + ], + ], + 'discount_amount' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], + 'discount_qty' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], + 'apply_to_shipping' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + 'options' => + [ + [ + 'label' => __('Yes'), + 'value' => '1' + ], + [ + 'label' => __('No'), + 'value' => '0' + ], + ], + ], + ], + ], + ], + 'stop_rules_processing' => + [ + 'arguments' => + [ + 'data' => + [ + 'config' => + [ + + 'options' => + [ + [ + 'label' => __('Yes'), + 'value' => '1' + ], + + [ + 'label' => __('No'), + 'value' => '0' + ], + ], + ], + ], + ], + ], + ], + ], + 'labels' => ['children' => ['store_labels[0]' => ['arguments' => ['data' => ['config' => ['value' => 'label0']]]]]], +]; diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/RuleTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/RuleTest.php index 65243ee594e6e9be3a796a2c252dd1c69db7065f..2a007d775bcdb8ac19f739555aafd7ae5acc21ce 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/RuleTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/RuleTest.php @@ -48,11 +48,13 @@ class RuleTest extends \PHPUnit_Framework_TestCase $this->conditionCombineFactoryMock = $this->getMockBuilder( '\Magento\SalesRule\Model\Rule\Condition\CombineFactory' )->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); $this->condProdCombineFactoryMock = $this->getMockBuilder( '\Magento\SalesRule\Model\Rule\Condition\Product\CombineFactory' )->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); $this->model = $objectManager->getObject( @@ -150,4 +152,20 @@ class RuleTest extends \PHPUnit_Framework_TestCase return $conditionMock; } + + public function testGetConditionsFieldSetId() + { + $formName = 'form_name'; + $this->model->setId(100); + $expectedResult = 'form_namerule_conditions_fieldset_100'; + $this->assertEquals($expectedResult, $this->model->getConditionsFieldSetId($formName)); + } + + public function testGetActionsFieldSetId() + { + $formName = 'form_name'; + $this->model->setId(100); + $expectedResult = 'form_namerule_actions_fieldset_100'; + $this->assertEquals($expectedResult, $this->model->getActionsFieldSetId($formName)); + } } diff --git a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml index 241c802efb0874fd3ce31e0345a1e291845a8a06..0a2ff4744720cec14c7669250ae01861b8747c0d 100644 --- a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml +++ b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml @@ -48,12 +48,21 @@ </item> </argument> </dataSource> + <fieldset name="general"> + <argument name="data" xsi:type="array"> + <item name="config" xsi:type="array"> + <item name="label" xsi:type="string">Currently Active</item> + <item name="additionalClasses" xsi:type="string">fieldset-schedule</item> + </item> + </argument> + </fieldset> <fieldset name="rule_information"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string" translate="true">Rule Information</item> <item name="collapsible" xsi:type="boolean">true</item> <item name="sortOrder" xsi:type="number">10</item> + <item name="opened" xsi:type="boolean">true</item> </item> </argument> <field name="name"> @@ -86,15 +95,19 @@ <field name="is_active"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> - <item name="label" xsi:type="string" translate="true">Status</item> - <item name="visible" xsi:type="boolean">true</item> - <item name="dataType" xsi:type="string">number</item> - <item name="formElement" xsi:type="string">select</item> + <item name="dataType" xsi:type="string">boolean</item> + <item name="formElement" xsi:type="string">checkbox</item> <item name="source" xsi:type="string">sales_rule</item> - <item name="dataScope" xsi:type="string">is_active</item> + <item name="prefer" xsi:type="string">toggle</item> + <item name="valueMap" xsi:type="array"> + <item name="true" xsi:type="number">1</item> + <item name="false" xsi:type="number">0</item> + </item> <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> + <item name="default" xsi:type="number">1</item> + <item name="label" xsi:type="string" translate="true">Active</item> </item> </argument> </field> @@ -328,12 +341,16 @@ <field name="is_rss"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> - <item name="label" xsi:type="string" translate="true">Public In RSS Feed</item> - <item name="visible" xsi:type="boolean">true</item> - <item name="dataType" xsi:type="string">number</item> - <item name="formElement" xsi:type="string">select</item> + <item name="dataType" xsi:type="string">boolean</item> + <item name="formElement" xsi:type="string">checkbox</item> <item name="source" xsi:type="string">sales_rule</item> - <item name="dataScope" xsi:type="string">is_rss</item> + <item name="prefer" xsi:type="string">toggle</item> + <item name="valueMap" xsi:type="array"> + <item name="true" xsi:type="number">1</item> + <item name="false" xsi:type="number">0</item> + </item> + <item name="default" xsi:type="number">1</item> + <item name="label" xsi:type="string" translate="true">Public In RSS Feed</item> </item> </argument> </field> @@ -417,26 +434,32 @@ <field name="apply_to_shipping"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> - <item name="label" xsi:type="string" translate="true">Apply to Shipping Amount</item> - <item name="fieldGroup" xsi:type="string">bool</item> - <item name="dataType" xsi:type="string">number</item> - <item name="formElement" xsi:type="string">select</item> - <item name="value" xsi:type="string">0</item> + <item name="dataType" xsi:type="string">boolean</item> + <item name="formElement" xsi:type="string">checkbox</item> <item name="source" xsi:type="string">sales_rule</item> - <item name="dataScope" xsi:type="string">apply_to_shipping</item> + <item name="prefer" xsi:type="string">toggle</item> + <item name="valueMap" xsi:type="array"> + <item name="true" xsi:type="number">1</item> + <item name="false" xsi:type="number">0</item> + </item> + <item name="default" xsi:type="number">0</item> + <item name="label" xsi:type="string" translate="true">Apply to Shipping Amount</item> </item> </argument> </field> <field name="stop_rules_processing"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> - <item name="label" xsi:type="string" translate="true">Discard subsequent rules</item> - <item name="fieldGroup" xsi:type="string">bool</item> - <item name="dataType" xsi:type="string">number</item> - <item name="formElement" xsi:type="string">select</item> - <item name="value" xsi:type="string">0</item> + <item name="dataType" xsi:type="string">boolean</item> + <item name="formElement" xsi:type="string">checkbox</item> <item name="source" xsi:type="string">sales_rule</item> - <item name="dataScope" xsi:type="string">stop_rules_processing</item> + <item name="prefer" xsi:type="string">toggle</item> + <item name="valueMap" xsi:type="array"> + <item name="true" xsi:type="number">1</item> + <item name="false" xsi:type="number">0</item> + </item> + <item name="default" xsi:type="number">0</item> + <item name="label" xsi:type="string" translate="true">Discard subsequent rules</item> </item> </argument> </field> diff --git a/app/code/Magento/Store/Test/Unit/Ui/Component/Listing/Column/StoreTest.php b/app/code/Magento/Store/Test/Unit/Ui/Component/Listing/Column/StoreTest.php index 9c833fa0db6a0805fc3ee13b984ae44b23ff2a28..bac47e50d80ed52f5bf7de4f7a19e9ba534a8c92 100644 --- a/app/code/Magento/Store/Test/Unit/Ui/Component/Listing/Column/StoreTest.php +++ b/app/code/Magento/Store/Test/Unit/Ui/Component/Listing/Column/StoreTest.php @@ -38,6 +38,11 @@ class StoreTest extends \PHPUnit_Framework_TestCase */ protected $escaperMock; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + /** * @var string */ @@ -68,6 +73,10 @@ class StoreTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($this->processorMock); $this->processorMock->expects($this->atLeastOnce())->method('register'); + $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); $this->model = $objectManager->getObject( 'Magento\Store\Ui\Component\Listing\Column\Store', [ @@ -79,10 +88,48 @@ class StoreTest extends \PHPUnit_Framework_TestCase 'data' => ['name' => $this->name] ] ); + + $this->injectMockedDependency($this->storeManagerMock, 'storeManager'); + } + + /** + * Inject mocked object dependency + * + * @param \PHPUnit_Framework_MockObject_MockObject $mockObject + * @param string $propertyName + * @return void + * + * @deprecated + */ + private function injectMockedDependency($mockObject, $propertyName) + { + $reflection = new \ReflectionClass(get_class($this->model)); + $reflectionProperty = $reflection->getProperty($propertyName); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $mockObject); + } + + public function testPrepare() + { + $this->storeManagerMock->expects($this->atLeastOnce())->method('isSingleStoreMode')->willReturn(false); + $this->model->prepare(); + $config = $this->model->getDataByKey('config'); + $this->assertEmpty($config); + } + + public function testPrepareWithSingleStore() + { + $this->storeManagerMock->expects($this->atLeastOnce())->method('isSingleStoreMode')->willReturn(true); + $this->model->prepare(); + $config = $this->model->getDataByKey('config'); + $this->assertNotEmpty($config); + $this->assertArrayHasKey('componentDisabled', $config); + $this->assertTrue($config['componentDisabled']); } /** * @dataProvider prepareDataSourceDataProvider + * @deprecated */ public function testPrepareDataSource($dataSource, $expectedResult) { @@ -112,6 +159,9 @@ class StoreTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->model->prepareDataSource($dataSource), $expectedResult); } + /** + * @deprecated + */ public function prepareDataSourceDataProvider() { $content = "website<br/> group<br/> store<br/>"; diff --git a/app/code/Magento/Store/Ui/Component/Form/Fieldset/Websites.php b/app/code/Magento/Store/Ui/Component/Form/Fieldset/Websites.php new file mode 100644 index 0000000000000000000000000000000000000000..c43ddd6c7f0d0a559c87805d301f22214ff61c5a --- /dev/null +++ b/app/code/Magento/Store/Ui/Component/Form/Fieldset/Websites.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Store\Ui\Component\Form\Fieldset; + +use Magento\Framework\View\Element\UiComponentInterface; +use Magento\Framework\View\Element\UiComponent\ContextInterface; +use Magento\Ui\Component\Form\Fieldset; +use Magento\Store\Model\StoreManagerInterface as StoreManager; + +/** + * Class Websites Fieldset + */ +class Websites extends Fieldset +{ + /** + * Store manager + * + * @var StoreManager + */ + protected $storeManager; + + /** + * Constructor + * + * @param ContextInterface $context + * @param StoreManager $storeManager + * @param UiComponentInterface[] $components + * @param array $data + */ + public function __construct( + ContextInterface $context, + StoreManager $storeManager, + array $components = [], + array $data = [] + ) { + parent::__construct($context, $components, $data); + $this->storeManager = $storeManager; + + } + + /** + * Prepare component configuration + * + * @return void + */ + public function prepare() + { + parent::prepare(); + if ($this->storeManager->isSingleStoreMode()) { + $this->_data['config']['componentDisabled'] = true; + } + } +} diff --git a/app/code/Magento/Store/Ui/Component/Listing/Column/Store.php b/app/code/Magento/Store/Ui/Component/Listing/Column/Store.php index 6a520c36392ca9c27dc86336e9de96200fc29ed1..78520cce1270cb5b6a8fd068da348c1ffb4f32d8 100644 --- a/app/code/Magento/Store/Ui/Component/Listing/Column/Store.php +++ b/app/code/Magento/Store/Ui/Component/Listing/Column/Store.php @@ -10,6 +10,7 @@ use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Store\Model\System\Store as SystemStore; use Magento\Ui\Component\Listing\Columns\Column; +use Magento\Store\Model\StoreManagerInterface as StoreManager; /** * Class Store @@ -30,6 +31,13 @@ class Store extends Column */ protected $systemStore; + /** + * Store manager + * + * @var StoreManager + */ + protected $storeManager; + /** * @var string */ @@ -111,4 +119,33 @@ class Store extends Column return $content; } + + /** + * Prepare component configuration + * + * @return void + */ + public function prepare() + { + parent::prepare(); + if ($this->getStoreManager()->isSingleStoreMode()) { + $this->_data['config']['componentDisabled'] = true; + } + } + + /** + * Get StoreManager dependency + * + * @return StoreManager + * + * @deprecated + */ + private function getStoreManager() + { + if ($this->storeManager === null) { + $this->storeManager = \Magento\Framework\App\ObjectManager::getInstance() + ->get('Magento\Store\Model\StoreManagerInterface'); + } + return $this->storeManager; + } } diff --git a/app/code/Magento/Translation/Controller/Ajax/Index.php b/app/code/Magento/Translation/Controller/Ajax/Index.php index 190b4046b465ccd2fc4aed14c6170f1bb735aa4c..4026546bf8424b33d6e84ada422aaaafa3e6ed97 100644 --- a/app/code/Magento/Translation/Controller/Ajax/Index.php +++ b/app/code/Magento/Translation/Controller/Ajax/Index.php @@ -36,12 +36,11 @@ class Index extends \Magento\Framework\App\Action\Action $translate = (array)$this->getRequest()->getPost('translate'); try { - $this->inlineParser->processAjaxPost($translate); - $response = "{success:true}"; + $response = $this->inlineParser->processAjaxPost($translate); } catch (\Exception $e) { $response = "{error:true,message:'" . $e->getMessage() . "'}"; } - $this->getResponse()->representJson($response); + $this->getResponse()->representJson(json_encode($response)); $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true); } } diff --git a/app/code/Magento/Translation/Model/FileManager.php b/app/code/Magento/Translation/Model/FileManager.php index 341988f2c4de994264ab54fa4c6e98a9b0d3a510..bfef51599a2261017cf52f35c888632e376866aa 100644 --- a/app/code/Magento/Translation/Model/FileManager.php +++ b/app/code/Magento/Translation/Model/FileManager.php @@ -89,4 +89,22 @@ class FileManager { return $this->assetRepo->getStaticViewFileContext()->getPath(); } + + /** + * @param string $content + * @return void + */ + public function updateTranslationFileContent($content) + { + $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . + \DIRECTORY_SEPARATOR . + $this->assetRepo->getStaticViewFileContext()->getPath(); + if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { + $this->driverFile->createDirectory( + $translationDir, + \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE + ); + } + $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); + } } diff --git a/app/code/Magento/Translation/Model/Inline/CacheManager.php b/app/code/Magento/Translation/Model/Inline/CacheManager.php new file mode 100644 index 0000000000000000000000000000000000000000..995409663a6108b2770369031d598d142c20af27 --- /dev/null +++ b/app/code/Magento/Translation/Model/Inline/CacheManager.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Translation\Model\Inline; + +/** + * To manage translations cache + */ +class CacheManager +{ + /** + * @var \Magento\Framework\Event\ManagerInterface + */ + protected $eventManager; + + /** + * @var \Magento\Framework\Translate\ResourceInterface + */ + protected $translateResource; + + /** + * @var \Magento\Framework\Locale\ResolverInterface + */ + protected $localeResolver; + + /** + * @var \Magento\Translation\Model\FileManager + */ + protected $fileManager; + + /** + * Initialize dependencies + * + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Framework\Translate\ResourceInterface $translateResource + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver + * @param \Magento\Translation\Model\FileManager $fileManager + */ + public function __construct( + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Framework\Translate\ResourceInterface $translateResource, + \Magento\Framework\Locale\ResolverInterface $localeResolver, + \Magento\Translation\Model\FileManager $fileManager + ) { + $this->eventManager = $eventManager; + $this->translateResource = $translateResource; + $this->localeResolver = $localeResolver; + $this->fileManager = $fileManager; + } + + /** + * Clears cache and updates translations file + * + * @return array + */ + public function updateAndGetTranslations() + { + $this->eventManager->dispatch('adminhtml_cache_flush_system'); + $translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale()); + $this->fileManager->updateTranslationFileContent(json_encode($translations)); + return $translations; + } +} diff --git a/app/code/Magento/Translation/Model/Inline/Parser.php b/app/code/Magento/Translation/Model/Inline/Parser.php index 7e892832bbecbc0aa70e7f4f98dabc93e1d2ea77..03f2cb7afddfe35ca5e418969df36cb9b735c1a0 100644 --- a/app/code/Magento/Translation/Model/Inline/Parser.php +++ b/app/code/Magento/Translation/Model/Inline/Parser.php @@ -9,6 +9,8 @@ namespace Magento\Translation\Model\Inline; /** * This class is responsible for parsing content and applying necessary html element * wrapping and client scripts for inline translation. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Parser implements \Magento\Framework\Translate\Inline\ParserInterface { @@ -119,6 +121,26 @@ class Parser implements \Magento\Framework\Translate\Inline\ParserInterface */ protected $_appCache; + /** + * @var \Magento\Translation\Model\Inline\CacheManager + */ + private $cacheManager; + + /** + * @return \Magento\Translation\Model\Inline\CacheManager + * + * @deprecated + */ + private function getCacheManger() + { + if (!$this->cacheManager instanceof \Magento\Translation\Model\Inline\CacheManager) { + $this->cacheManager = \Magento\Framework\App\ObjectManager::getInstance()->get( + 'Magento\Translation\Model\Inline\CacheManager' + ); + } + return $this->cacheManager; + } + /** * Initialize base inline translation model * @@ -149,12 +171,12 @@ class Parser implements \Magento\Framework\Translate\Inline\ParserInterface * Parse and save edited translation * * @param array $translateParams - * @return $this + * @return array */ public function processAjaxPost(array $translateParams) { if (!$this->_translateInline->isAllowed()) { - return $this; + return ['inline' => 'not allowed']; } $this->_appCache->invalidate(\Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER); @@ -179,7 +201,8 @@ class Parser implements \Magento\Framework\Translate\Inline\ParserInterface } $resource->saveTranslate($param['original'], $param['custom'], null, $storeId); } - return $this; + + return $this->getCacheManger()->updateAndGetTranslations(); } /** diff --git a/app/code/Magento/Translation/Test/Unit/Model/Inline/CacheManagerTest.php b/app/code/Magento/Translation/Test/Unit/Model/Inline/CacheManagerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..f710d585c0c3d83b2c6051dfa1ad9eb66c4be1d7 --- /dev/null +++ b/app/code/Magento/Translation/Test/Unit/Model/Inline/CacheManagerTest.php @@ -0,0 +1,83 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Translation\Test\Unit\Model\Inline; + +/** + * @covers \Magento\Translation\Model\Inline\CacheManager + */ +class CacheManagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Translation\Model\Inline\CacheManager + */ + protected $model; + + /** + * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $eventManagerMock; + + /** + * @var \Magento\Framework\Translate\ResourceInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $translateResourceMock; + + /** + * @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeResolverMock; + + /** + * @var \Magento\Translation\Model\FileManager|\PHPUnit_Framework_MockObject_MockObject + */ + protected $fileManagerMock; + + protected function setUp() + { + $this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->translateResourceMock = $this->getMockBuilder('Magento\Framework\Translate\ResourceInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->localeResolverMock = $this->getMockBuilder('Magento\Framework\Locale\ResolverInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->fileManagerMock = $this->getMockBuilder('Magento\Translation\Model\FileManager') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManagerHelper->getObject( + 'Magento\Translation\Model\Inline\CacheManager', + [ + 'eventManager' => $this->eventManagerMock, + 'translateResource' => $this->translateResourceMock, + 'localeResolver' => $this->localeResolverMock, + 'fileManager' => $this->fileManagerMock + ] + ); + } + + public function testUpdateAndGetTranslations() + { + $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2']; + + $this->eventManagerMock->expects($this->once())->method('dispatch'); + $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations); + $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US'); + $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent'); + $this->assertEquals($translations, $this->model->updateAndGetTranslations()); + } +} diff --git a/app/code/Magento/Webapi/Controller/Rest.php b/app/code/Magento/Webapi/Controller/Rest.php index 4191b75c1760e19c662e3e969dc7d28fe30f708a..da3e4f9b9c5863c45a2d812a442d082f2d037c7e 100644 --- a/app/code/Magento/Webapi/Controller/Rest.php +++ b/app/code/Magento/Webapi/Controller/Rest.php @@ -20,6 +20,8 @@ use Magento\Webapi\Controller\Rest\ParamsOverrider; use Magento\Webapi\Controller\Rest\Router; use Magento\Webapi\Controller\Rest\Router\Route; use Magento\Webapi\Model\Rest\Swagger\Generator; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Config\ConfigOptionsListConstants; /** * Front controller for WebAPI REST area. @@ -85,6 +87,11 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface /** @var StoreManagerInterface */ private $storeManager; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * Initialize dependencies * @@ -141,6 +148,32 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface $this->storeManager = $storeManager; } + /** + * Get deployment config + * + * @return DeploymentConfig + */ + private function getDeploymentConfig() + { + if (!$this->deploymentConfig instanceof \Magento\Framework\App\DeploymentConfig) { + $this->deploymentConfig = \Magento\Framework\App\ObjectManager::getInstance() + ->get('Magento\Framework\App\DeploymentConfig'); + } + return $this->deploymentConfig; + } + + /** + * Set deployment config + * + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @return void + * @deprecated + */ + public function setDeploymentConfig(\Magento\Framework\App\DeploymentConfig $deploymentConfig) + { + $this->deploymentConfig = $deploymentConfig; + } + /** * Handle REST request * @@ -255,6 +288,10 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface if ($this->_request->getParam(FieldsFilter::FILTER_PARAMETER) && is_array($outputData)) { $outputData = $this->fieldsFilter->filter($outputData); } + $header = $this->getDeploymentConfig()->get(ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT); + if ($header) { + $this->_response->setHeader('X-Frame-Options', $header); + } $this->_response->prepareResponse($outputData); } diff --git a/app/code/Magento/Webapi/Model/Soap/Fault.php b/app/code/Magento/Webapi/Model/Soap/Fault.php index c6cf9637602e9a0168de9f13af05fd9306d0bc13..cb77fe59602c0bdce2341b44eb5fe2722ae7299e 100644 --- a/app/code/Magento/Webapi/Model/Soap/Fault.php +++ b/app/code/Magento/Webapi/Model/Soap/Fault.php @@ -25,7 +25,7 @@ class Fault const NODE_DETAIL_PARAMETERS = 'Parameters'; const NODE_DETAIL_WRAPPED_ERRORS = 'WrappedErrors'; const NODE_DETAIL_WRAPPED_EXCEPTION = 'WrappedException'; - /** Note that parameter node must be unique in scope of all complex types declared in WSDL */ + /* Note that parameter node must be unique in scope of all complex types declared in WSDL */ const NODE_DETAIL_PARAMETER = 'GenericFaultParameter'; const NODE_DETAIL_PARAMETER_KEY = 'key'; const NODE_DETAIL_PARAMETER_VALUE = 'value'; @@ -319,10 +319,15 @@ FAULT_MESSAGE; } $paramsXml = ''; foreach ($parameters as $parameterName => $parameterValue) { - if (is_string($parameterName) && (is_string($parameterValue) || is_numeric($parameterValue))) { + if ((is_string($parameterName) || is_numeric($parameterName)) + && (is_string($parameterValue) || is_numeric($parameterValue)) + ) { $keyNode = self::NODE_DETAIL_PARAMETER_KEY; $valueNode = self::NODE_DETAIL_PARAMETER_VALUE; $parameterNode = self::NODE_DETAIL_PARAMETER; + if (is_numeric($parameterName)) { + $parameterName++; + } $paramsXml .= "<m:$parameterNode><m:$keyNode>$parameterName</m:$keyNode><m:$valueNode>" . htmlspecialchars($parameterValue) . "</m:$valueNode></m:$parameterNode>"; } diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php index 6300ec461160b75bf3478eb6425ff538cccb8e66..ff107918056cb720a7f83ac21ad1daaa664321f8 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php @@ -70,12 +70,20 @@ class RestTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Store\Api\Data\StoreInterface | \PHPUnit_Framework_MockObject_MockObject*/ private $storeMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $deploymentConfigMock; + const SERVICE_METHOD = 'testMethod'; const SERVICE_ID = 'Magento\Webapi\Controller\TestService'; protected function setUp() { + $this->deploymentConfigMock = $this->getMock( + 'Magento\Framework\App\DeploymentConfig', [], [], '', false, false + ); $this->_requestMock = $this->getMockBuilder('Magento\Framework\Webapi\Rest\Request') ->setMethods( [ @@ -87,7 +95,7 @@ class RestTest extends \PHPUnit_Framework_TestCase ->method('getHttpHost') ->willReturn('testHostName.com'); $this->_responseMock = $this->getMockBuilder('Magento\Framework\Webapi\Rest\Response') - ->setMethods(['sendResponse', 'prepareResponse'])->disableOriginalConstructor()->getMock(); + ->setMethods(['sendResponse', 'prepareResponse', 'setHeader'])->disableOriginalConstructor()->getMock(); $routerMock = $this->getMockBuilder('Magento\Webapi\Controller\Rest\Router')->setMethods(['match']) ->disableOriginalConstructor()->getMock(); $this->_routeMock = $this->getMockBuilder('Magento\Webapi\Controller\Rest\Router\Route') @@ -144,6 +152,8 @@ class RestTest extends \PHPUnit_Framework_TestCase 'storeManager' => $this->storeManagerMock ] ); + + $this->_restController->setDeploymentConfig($this->deploymentConfigMock); // Set default expectations used by all tests $this->_routeMock->expects($this->any())->method('getServiceClass')->will($this->returnValue(self::SERVICE_ID)); $this->_routeMock->expects($this->any())->method('getServiceMethod') @@ -218,6 +228,14 @@ class RestTest extends \PHPUnit_Framework_TestCase */ public function testSecureRouteAndRequest($isSecureRoute, $isSecureRequest) { + + $this->deploymentConfigMock->expects($this->once()) + ->method('get') + ->with('x-frame-options') + ->willReturn('SAMEORIGIN'); + + $this->_responseMock->expects($this->once())->method('setHeader')->with('X-Frame-Options', 'SAMEORIGIN'); + $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([])); $this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue($isSecureRoute)); $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue([])); diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php index e0ea010724d62b7a97af4d9639e83f27dcacf2cb..179ee6f8bf8c314a596c7e7aa58e4190798c2a63 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php @@ -25,7 +25,7 @@ class FaultTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Webapi\Model\Soap\Fault */ protected $_soapFault; - /** @var \PHPUnit_Framework_MockObject_MockObject*/ + /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $_localeResolverMock; /** @@ -37,11 +37,10 @@ class FaultTest extends \PHPUnit_Framework_TestCase { $this->_requestMock = $this->getMock('\Magento\Framework\App\RequestInterface'); /** Initialize SUT. */ - $message = "Soap fault reason."; $details = ['param1' => 'value1', 'param2' => 2]; $code = 111; $webapiException = new \Magento\Framework\Webapi\Exception( - __($message), + __('Soap fault reason.'), $code, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR, $details @@ -211,7 +210,7 @@ XML; $details = ['param1' => 'value1', 'param2' => 2]; $code = 111; $webapiException = new \Magento\Framework\Webapi\Exception( - __($message), + __('Soap fault reason.'), $code, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR, $details diff --git a/app/code/Magento/Webapi/Test/Unit/_files/soap_fault/soap_fault_expected_xmls.php b/app/code/Magento/Webapi/Test/Unit/_files/soap_fault/soap_fault_expected_xmls.php index 781151e9f425d227bf1bf6c9ca0ac048e5d5954c..634e374a96b7713c7a3dfa1d7e1d8856ebcc9b80 100644 --- a/app/code/Magento/Webapi/Test/Unit/_files/soap_fault/soap_fault_expected_xmls.php +++ b/app/code/Magento/Webapi/Test/Unit/_files/soap_fault/soap_fault_expected_xmls.php @@ -27,6 +27,10 @@ return [ <m:key>key2</m:key> <m:value>value2</m:value> </m:GenericFaultParameter> + <m:GenericFaultParameter> + <m:key>1</m:key> + <m:value>value3</m:value> + </m:GenericFaultParameter> </m:Parameters> <m:Trace>Trace</m:Trace> </m:GenericFault> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml index 1f3a36bd2388fc412dae86f4c69edd8ba62ec8c1..1239928f4c658dc63c4fb4d4eee1c2fc77b362da 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml @@ -14,7 +14,7 @@ <name /> <description /> <is_active> - <input>select</input> + <input>switcher</input> </is_active> <website_ids> <selector>[name='website_ids']</selector> @@ -34,7 +34,7 @@ <to_date /> <sort_order /> <is_rss> - <input>select</input> + <input>switcher</input> </is_rss> </fields> </rule_information> @@ -44,7 +44,7 @@ <strategy>xpath</strategy> <fields> <conditions_serialized> - <selector>#rule_conditions_fieldset</selector> + <selector>#sales_rule_formrule_conditions_fieldset_</selector> <input>conditions</input> </conditions_serialized> </fields> @@ -61,10 +61,10 @@ <discount_qty /> <discount_step /> <apply_to_shipping> - <input>select</input> + <input>switcher</input> </apply_to_shipping> <stop_rules_processing> - <input>select</input> + <input>switcher</input> </stop_rules_processing> <simple_free_shipping> <input>select</input> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml index 6250b30614abc174d46a38695177d3d386ad9645..19cc143f692757434fe0943b2c8735201a3d25af 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml @@ -9,7 +9,7 @@ <repository class="Magento\SalesRule\Test\Repository\SalesRule"> <dataset name="default"> <field name="name" xsi:type="string">Default price rule %isolation%</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -27,7 +27,7 @@ <dataset name="active_sales_rule_with_percent_price_discount_coupon"> <field name="name" xsi:type="string">Cart Price Rule with Specific Coupon %isolation%</field> <field name="description" xsi:type="string">Description for Cart Price Rule</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -46,7 +46,7 @@ <dataset name="active_sales_rule_with_coupon_10"> <field name="name" xsi:type="string">10% Off Coupon</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -62,7 +62,7 @@ <dataset name="active_sales_rule_with_fixed_price_discount_coupon"> <field name="name" xsi:type="string">Cart Price Rule with Specific Coupon %isolation%</field> <field name="description" xsi:type="string">Description for Cart Price Rule</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -83,7 +83,7 @@ <dataset name="active_sales_rule_for_retailer"> <field name="name" xsi:type="string">Cart Price Rule %isolation%</field> <field name="description" xsi:type="string">Description for Cart Price Rule</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -99,7 +99,7 @@ <dataset name="active_sales_rule_with_complex_conditions"> <field name="name" xsi:type="string">Cart Price Rule with with complex conditions %isolation%</field> <field name="description" xsi:type="string">Cart Price Rule with with complex conditions</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -137,7 +137,7 @@ <dataset name="inactive_sales_rule"> <field name="name" xsi:type="string">Inactive Cart Price Rule %isolation%</field> - <field name="is_active" xsi:type="string">Inactive</field> + <field name="is_active" xsi:type="string">No</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -152,7 +152,7 @@ <dataset name="active_sales_rule_for_all_groups"> <field name="name" xsi:type="string">Cart Price Rule with Specific Coupon %isolation%</field> <field name="description" xsi:type="string">Description for Cart Price Rule</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -175,7 +175,7 @@ <dataset name="active_sales_rule_for_all_groups_no_coupon"> <field name="name" xsi:type="string">Cart Price Rule without Coupon %isolation%</field> <field name="description" xsi:type="string">Description for Cart Price Rule</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -193,7 +193,7 @@ <dataset name="active_sales_rule_product_subselection"> <field name="name" xsi:type="string">Cart Price Rule with product subselection %isolation%</field> <field name="description" xsi:type="string">Cart Price Rule with product subselection</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -220,7 +220,7 @@ <dataset name="active_sales_rule_product_attribute"> <field name="name" xsi:type="string">Cart price rule with attribute conditions %isolation%</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -241,7 +241,7 @@ <dataset name="active_sales_rule_row_total"> <field name="name" xsi:type="string">Cart price rule with row total condition %isolation%</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> @@ -262,7 +262,7 @@ <dataset name="active_sales_total_items"> <field name="name" xsi:type="string">Cart price rule with total items %isolation%</field> - <field name="is_active" xsi:type="string">Active</field> + <field name="is_active" xsi:type="string">Yes</field> <field name="website_ids" xsi:type="array"> <item name="0" xsi:type="string">Main Website</item> </field> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml index 5eba30f7f0837a7a885084a3a0009a3131b4d59d..9c0d036e9c4905240cb191c040e9960716b6b419 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -10,7 +10,7 @@ <variation name="CreateSalesRuleEntityTestVariation1"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule1 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -31,7 +31,7 @@ <variation name="CreateSalesRuleEntityTestVariation2"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule2 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> @@ -53,7 +53,7 @@ <variation name="CreateSalesRuleEntityTestVariation3"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule3 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> @@ -75,7 +75,7 @@ <variation name="CreateSalesRuleEntityTestVariation4"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule4 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> @@ -101,7 +101,7 @@ <data name="customer/dataset" xsi:type="string">default</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule5 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">General</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -127,7 +127,7 @@ <data name="shipping/shipping_method" xsi:type="string">Fixed</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule6 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -155,7 +155,7 @@ <data name="shipping/shipping_method" xsi:type="string">Fixed</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule7 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -184,7 +184,7 @@ <data name="shipping/shipping_method" xsi:type="string">Fixed</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule8 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -208,7 +208,7 @@ <variation name="CreateSalesRuleEntityTestVariation9"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule9 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -227,7 +227,7 @@ <variation name="CreateSalesRuleEntityTestVariation10"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule10 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -252,7 +252,7 @@ <variation name="CreateSalesRuleEntityTestVariation11"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule11 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -281,7 +281,7 @@ <data name="shipping/shipping_method" xsi:type="string">Fixed</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule12 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -306,7 +306,7 @@ <data name="tag" xsi:type="string">test_type:extended_acceptance_test</data> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule13 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -328,7 +328,7 @@ <variation name="CreateSalesRuleEntityTestVariation14"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule14 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> @@ -352,7 +352,7 @@ <variation name="CreateSalesRuleEntityTestVariation15"> <data name="salesRule/data/name" xsi:type="string">Cart Price Rule15 %isolation%</data> <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> - <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/is_active" xsi:type="string">Yes</data> <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> diff --git a/dev/tests/integration/testsuite/Magento/Translation/Controller/AjaxTest.php b/dev/tests/integration/testsuite/Magento/Translation/Controller/AjaxTest.php index 3bfc2aa21ef65ec1907bbccaeb64b9e3270af263..135c87b1ad88fa3aa03a129885d4938e772d9062 100644 --- a/dev/tests/integration/testsuite/Magento/Translation/Controller/AjaxTest.php +++ b/dev/tests/integration/testsuite/Magento/Translation/Controller/AjaxTest.php @@ -8,18 +8,58 @@ namespace Magento\Translation\Controller; class AjaxTest extends \Magento\TestFramework\TestCase\AbstractController { + protected function setUp() + { + /* Called getConfig as workaround for setConfig bug */ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getStore( + 'default' + )->getConfig( + 'dev/translate_inline/active' + ); + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Framework\App\Config\MutableScopeConfigInterface' + )->setValue( + 'dev/translate_inline/active', + true, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + 'default' + ); + parent::setUp(); + } + /** * @dataProvider indexActionDataProvider */ - public function testIndexAction($postData) + public function testIndexAction($postData, $expected) { $this->getRequest()->setPostValue('translate', $postData); $this->dispatch('translation/ajax/index'); - $this->assertEquals('{success:true}', $this->getResponse()->getBody()); + $this->assertEquals($expected, $this->getResponse()->getBody()); } public function indexActionDataProvider() { - return [['test'], [['test']]]; + return [ + [ + [ + [ + 'original' => 'phrase1', + 'custom' => 'translation1' + ] + ], + '{"phrase1":"translation1"}' + ], + [ + [ + [ + 'original' => 'phrase2', + 'custom' => 'translation2' + ] + ], + '{"phrase1":"translation1","phrase2":"translation2"}' + ] + ]; } } diff --git a/dev/tests/static/framework/Magento/Sniffs/Files/LineLengthSniff.php b/dev/tests/static/framework/Magento/Sniffs/Files/LineLengthSniff.php new file mode 100644 index 0000000000000000000000000000000000000000..c69f85ca8758bc3c596cddc2ea2052a24343f5aa --- /dev/null +++ b/dev/tests/static/framework/Magento/Sniffs/Files/LineLengthSniff.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Sniffs\Files; + +/** + * Line length sniff which ignores long lines in case they contain strings intended for translation. + */ +class LineLengthSniff extends \Generic_Sniffs_Files_LineLengthSniff +{ + /** + * Having previous line content allows to ignore long lines in case of multi-line declaration. + * + * @var string + */ + protected $previousLineContent = ''; + + /** + * {@inheritdoc} + */ + protected function checkLineLength(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $lineContent) + { + $previousLineRegexp = '~__\($|Phrase\($~'; + $currentLineRegexp = '~__\(.+\)|Phrase\(.+\)~'; + $currentLineMatch = preg_match($currentLineRegexp, $lineContent) !== 0; + $previousLineMatch = preg_match($previousLineRegexp, $this->previousLineContent) !== 0; + $this->previousLineContent = $lineContent; + $error = 'Variable is not allowed as the first argument of translation function, use string literal instead'; + if ($currentLineMatch) { + $variableRegexp = '~__\(\$.+\)|Phrase\(\$.+\)~'; + if (preg_match($variableRegexp, $lineContent) !== 0) { + $phpcsFile->addError($error, $stackPtr, 'VariableTranslation'); + } + return; + } else if ($previousLineMatch) { + $variableRegexp = '~^\s*\$.+~'; + if (preg_match($variableRegexp, $lineContent) !== 0) { + $phpcsFile->addError($error, $stackPtr, 'VariableTranslation'); + } + return; + } + parent::checkLineLength($phpcsFile, $stackPtr, $lineContent); + } +} diff --git a/dev/tests/static/framework/Magento/ruleset.xml b/dev/tests/static/framework/Magento/ruleset.xml index cc949060fd660d71dd45140e0ccea19b80021ca2..137409c9988b23a6591be5fae32c02a5573a0b6c 100644 --- a/dev/tests/static/framework/Magento/ruleset.xml +++ b/dev/tests/static/framework/Magento/ruleset.xml @@ -6,5 +6,11 @@ */ --> <ruleset name="Magento"> - <description>A custom coding standard.</description> + <description>Custom Magento coding standard.</description> + <rule ref="Magento.Files.LineLength"> + <properties> + <property name="lineLimit" value="120"/> + <property name="absoluteLineLimit" value="120"/> + </properties> + </rule> </ruleset> diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/ruleset.xml b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/ruleset.xml index c1543db7c87f48513fbed0b0267712ae6ddfa201..b0470c869de1708fe22b0df2acc854b546ed0a43 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/ruleset.xml +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/ruleset.xml @@ -10,12 +10,6 @@ <rule ref="Zend.Files.ClosingTag"/> <rule ref="Generic.WhiteSpace.DisallowTabIndent"/> <rule ref="Generic.WhiteSpace.ScopeIndent"/> - <rule ref="Generic.Files.LineLength"> - <properties> - <property name="lineLimit" value="120"/> - <property name="absoluteLineLimit" value="120"/> - </properties> - </rule> <rule ref="Generic.Files.LineEndings"/> <rule ref="PEAR.NamingConventions.ValidClassName"/> <rule ref="Squiz.Functions.GlobalFunction"/> diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index d5a5aa20d2961d9c28415f3a36eeb5b764ce20db..db7f389c81253e6e4cf35f7b328a4116dd4ad0a1 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -2789,6 +2789,9 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface if (($key == 'seq') || ($key == 'sneq')) { $key = $this->_transformStringSqlCondition($key, $value); } + if (($key == 'in' || $key == 'nin') && is_string($value)) { + $value = explode(',', $value); + } $query = $this->_prepareQuotedSqlCondition($conditionKeyMap[$key], $value, $fieldName); } else { $queries = []; diff --git a/lib/web/mage/translate-inline.js b/lib/web/mage/translate-inline.js index ee7f68acd45c6acd31434bce9720c92bb578a7d0..e57d81fee77eaaf2a18474c0ad7db7d82d40e265 100644 --- a/lib/web/mage/translate-inline.js +++ b/lib/web/mage/translate-inline.js @@ -82,6 +82,7 @@ items: templateData, escape: $.mage.escapeHTML }, this.options.translateForm.data); + this.data = data; return $(this.tmpl({ data: data @@ -94,6 +95,7 @@ * @protected */ _onEdit: function(e) { + this.target = e.target; this.element.html(this._prepareContent($(e.target).data('translate'))); this.open(e); }, @@ -122,9 +124,17 @@ }).complete($.proxy(this._formSubmitComplete, this)); }, - _formSubmitComplete: function() { + _formSubmitComplete: function(response) { this.close(); this.formIsSubmitted = false; + this._updatePlaceholder(response.responseJSON[this.data.items[0]['original']]) + }, + + _updatePlaceholder: function(newValue) { + var target = jQuery(this.target); + target.data('translate')[0]['shown'] = newValue; + target.data('translate')[0]['translated'] = newValue; + target.html(newValue); }, /**