Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Weis committed May 16, 2016
2 parents 0d20774 + a5be15b commit 3b770f7
Show file tree
Hide file tree
Showing 36 changed files with 505 additions and 117 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<argument name="storage" xsi:type="object">Magento\Backend\Model\Session\Quote\Storage</argument>
</arguments>
</type>
<type name="Magento\Framework\Console\CommandList">
<type name="Magento\Framework\Console\CommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="cacheEnableCommand" xsi:type="object">Magento\Backend\Console\Command\CacheEnableCommand</item>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/view/base/web/js/price-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ define([
};
});

$option.text(template(toTemplate));
$option.html(template(toTemplate));
});
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;

use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\Pricing\PriceCurrencyInterface;

/**
* Class AbstractModifier
Expand Down Expand Up @@ -195,13 +195,24 @@ protected function getGroupCodeByField(array $meta, $field)
}

/**
* Format number to have only two decimals after delimiter
* Format price to have only two decimals after delimiter
*
* @param mixed $value
* @return string
*/
protected function formatFloat($value)
protected function formatPrice($value)
{
return $value !== null ? number_format((float)$value, 2, '.', '') : '';
return $value !== null ? number_format((float)$value, PriceCurrencyInterface::DEFAULT_PRECISION, '.', '') : '';
}

/**
* Strip excessive decimal digits from weight number
*
* @param mixed $value
* @return string
*/
protected function formatWeight($value)
{
return (float)$value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ public function modifyData(array $data)

/** @var \Magento\Catalog\Model\Product\Option $option */
foreach ($productOptions as $index => $option) {
$options[$index] = $this->formatFloatByPath(static::FIELD_PRICE_NAME, $option->getData());
$options[$index] = $this->formatPriceByPath(static::FIELD_PRICE_NAME, $option->getData());
$values = $option->getValues() ?: [];

/** @var \Magento\Catalog\Model\Product\Option $value */
foreach ($values as $value) {
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatFloatByPath(
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatPriceByPath(
static::FIELD_PRICE_NAME,
$value->getData()
);
Expand All @@ -188,12 +188,12 @@ public function modifyData(array $data)
* @param array $data
* @return array
*/
protected function formatFloatByPath($path, array $data)
protected function formatPriceByPath($path, array $data)
{
$value = $this->arrayManager->get($path, $data);

if (is_numeric($value)) {
$data = $this->arrayManager->replace($path, $data, $this->formatFloat($value));
$data = $this->arrayManager->replace($path, $data, $this->formatPrice($value));
}

return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function modifyData(array $data)
foreach ($attributes as $attribute) {
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
$attributeValue = $this->formatFloat($attributeValue);
$attributeValue = $this->formatPrice($attributeValue);
}
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function modifyData(array $data)
{
$data = $this->customizeNumberFormat($data);
$data = $this->customizeWeightFormat($data);
$data = $this->customizeAdvancedPriceFormat($data);
$modelId = $this->locator->getProduct()->getId();

Expand All @@ -54,42 +54,29 @@ public function modifyData(array $data)
}

/**
* Customizing number fields
* Customizing weight fields
*
* @param array $data
* @return array
*/
protected function customizeNumberFormat(array $data)
protected function customizeWeightFormat(array $data)
{
$model = $this->locator->getProduct();
$modelId = $model->getId();
$numberFields = [ProductAttributeInterface::CODE_WEIGHT];
$weightFields = [ProductAttributeInterface::CODE_WEIGHT];

foreach ($numberFields as $fieldCode) {
foreach ($weightFields as $fieldCode) {
$path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/' . $fieldCode;
$number = (float)$this->arrayManager->get($path, $data);
$data = $this->arrayManager->replace(
$path,
$data,
$this->formatNumber($number)
$this->formatWeight($this->arrayManager->get($path, $data))
);
}

return $data;
}

/**
* Formatting numeric field
*
* @param float $number
* @param int $decimals
* @return string
*/
protected function formatNumber($number, $decimals = 2)
{
return number_format($number, $decimals);
}

/**
* Customizing number fields for advanced price
*
Expand All @@ -104,7 +91,7 @@ protected function customizeAdvancedPriceFormat(array $data)
if (isset($data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode])) {
foreach ($data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode] as &$value) {
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
$this->formatNumber($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
(int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\Console\CommandList">
<type name="Magento\Framework\Console\CommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="imagesResizeCommand" xsi:type="object">Magento\Catalog\Console\Command\ImagesResizeCommand</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
</argument>
</arguments>
<block class="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content" as="content">
<arguments>
<argument name="config" xsi:type="array">
<item name="parentComponent" xsi:type="string">product_form.product_form.block_gallery.block_gallery</item>
</argument>
</arguments>
<block class="Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo" name="new-video"
template="Magento_ProductVideo::product/edit/slideout/form.phtml"/>
</block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $formName = $block->getFormName();
<div id="<?php echo $block->getHtmlId() ?>"
class="gallery"
data-mage-init='{"productGallery":{"template":"#<?php echo $block->getHtmlId() ?>-template"}}'
data-parent-component="<?php echo $block->escapeHtml($block->getData('config/parentComponent')) ?>"
data-images="<?php echo $block->escapeHtml($block->getImagesJson()) ?>"
data-types="<?php echo $block->escapeHtml(
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ define([
'jquery',
'underscore',
'mage/template',
'uiRegistry',
'jquery/ui',
'baseImage'
], function ($, _, mageTemplate) {
], function ($, _, mageTemplate, registry) {
'use strict';

/**
Expand Down Expand Up @@ -53,6 +54,7 @@ define([
_create: function () {
this.options.types = this.options.types || this.element.data('types');
this.options.images = this.options.images || this.element.data('images');
this.options.parentComponent = this.options.parentComponent || this.element.data('parent-component');

this.imgTmpl = mageTemplate(this.element.find(this.options.template).html().trim());

Expand Down Expand Up @@ -153,6 +155,19 @@ define([
}).first();
},

/**
* Mark parent fieldset that content was updated
*/
_contentUpdated: function () {
if (this.options.initialized && this.options.parentComponent) {
registry.async(this.options.parentComponent)(
function (parentComponent) {
parentComponent.bubble('update', true);
}
);
}
},

/**
* Add image
* @param event
Expand Down Expand Up @@ -205,6 +220,7 @@ define([
}, this));

this._updateImagesRoles();
this._contentUpdated();
},

/**
Expand Down Expand Up @@ -284,6 +300,8 @@ define([
imageData.label;

$title.text(value);

this._contentUpdated();
},

/**
Expand All @@ -297,6 +315,8 @@ define([

imageData.isRemoved = true;
$imageContainer.addClass('removed').hide().find('.is-removed').val(1);

this._contentUpdated();
},

/**
Expand All @@ -321,6 +341,7 @@ define([
}
this.element.find('.image-' + data.type).val(this.options.types[data.type].value || 'no_selection');
this._updateImagesRoles();
this._contentUpdated();
},

/**
Expand All @@ -339,6 +360,8 @@ define([
$(element).val(index);
}
}, this));

this._contentUpdated();
},

/**
Expand All @@ -362,6 +385,8 @@ define([
}
this.element.trigger('resort');
}

this._contentUpdated();
}
});

Expand Down Expand Up @@ -572,6 +597,8 @@ define([

$imageContainer.find('[name*="disabled"]').val(disabled);
imageData.disabled = disabled;

this._contentUpdated();
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Qty Uses Decimals</item>
<item name="formElement" xsi:type="string">select</item>
<item name="rawOptions" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">stock_data.is_qty_decimal</item>
<item name="value" xsi:type="number">0</item>
<item name="sortOrder" xsi:type="number">600</item>
Expand Down
49 changes: 49 additions & 0 deletions app/code/Magento/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\ResourceModel\Page as ResourceCmsPage;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Cms\Helper\Page as PageHelper;

/**
* Cms Page Model
Expand All @@ -17,6 +20,7 @@
* @method ResourceCmsPage getResource()
* @method Page setStoreId(array $storeId)
* @method array getStoreId()
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
*/
class Page extends AbstractModel implements PageInterface, IdentityInterface
{
Expand Down Expand Up @@ -49,6 +53,11 @@ class Page extends AbstractModel implements PageInterface, IdentityInterface
*/
protected $_eventPrefix = 'cms_page';

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* Initialize resource model
*
Expand Down Expand Up @@ -526,4 +535,44 @@ public function setIsActive($isActive)
{
return $this->setData(self::IS_ACTIVE, $isActive);
}

/**
* {@inheritdoc}
*/
public function beforeSave()
{
$originalIdentifier = $this->getOrigData('identifier');
$currentIdentifier = $this->getIdentifier();

if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
return parent::beforeSave();
}

switch ($originalIdentifier) {
case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_ROUTE_PAGE):
throw new LocalizedException(
__('This identifier is reserved for "CMS No Route Page" in configuration.')
);
case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_HOME_PAGE):
throw new LocalizedException(__('This identifier is reserved for "CMS Home Page" in configuration.'));
case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_COOKIES_PAGE):
throw new LocalizedException(
__('This identifier is reserved for "CMS No Cookies Page" in configuration.')
);
}

return parent::beforeSave();
}

/**
* @return ScopeConfigInterface
*/
private function getScopeConfig()
{
if (null === $this->scopeConfig) {
$this->scopeConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
}

return $this->scopeConfig;
}
}
Loading

0 comments on commit 3b770f7

Please sign in to comment.