Skip to content

Commit

Permalink
Merge pull request #429 from magento-troll/MAGETWO-49205
Browse files Browse the repository at this point in the history
[Troll] Add scope selector on Category Page
  • Loading branch information
slopukhov committed Mar 15, 2016
2 parents 0fbca05 + 0d786b9 commit f278923
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 11 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,13 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
$select = $connection->select();
if ($attribute->getBackend()->getType() === 'static') {
$value = $object->getData($attribute->getAttributeCode());
$bind = ['attribute_code' => trim($value)];
$bind = ['value' => trim($value)];

$select->from(
$this->getEntityTable(),
$this->getEntityIdField()
)->where(
$attribute->getAttributeCode() . ' = :attribute_code'
$attribute->getAttributeCode() . ' = :value'
);
} else {
$value = $object->getData($attribute->getAttributeCode());
Expand All @@ -950,7 +950,7 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
];
$select->from(
$attribute->getBackend()->getTable(),
$attribute->getBackend()->getEntityIdField()
$object->getResource()->getLinkField()
)->where(
'attribute_id = :attribute_id'
)->where(
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Eav/Model/ResourceModel/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function execute($entityType, $data)
if ((!array_key_exists($attribute->getAttributeCode(), $snapshot)
|| $snapshot[$attribute->getAttributeCode()] === false)
&& array_key_exists($attribute->getAttributeCode(), $data)
&& $data[$attribute->getAttributeCode()] !== false
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
) {
$this->attributePersistor->registerInsert(
Expand All @@ -147,6 +148,7 @@ public function execute($entityType, $data)
if (array_key_exists($attribute->getAttributeCode(), $snapshot)
&& $snapshot[$attribute->getAttributeCode()] !== false
&& array_key_exists($attribute->getAttributeCode(), $data)
&& $data[$attribute->getAttributeCode()] !== false
&& $snapshot[$attribute->getAttributeCode()] != $data[$attribute->getAttributeCode()]
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
) {
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Ui/Component/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public function prepare()
$this->getContext()->addActions($this->getData('actions'), $this);
}

if ($this->hasData('html_blocks')) {
$this->getContext()->addHtmlBlocks($this->getData('html_blocks'), $this);
}

if ($this->hasData('buttons')) {
$this->getContext()->addButtons($this->getData('buttons'), $this);
}
Expand Down
15 changes: 15 additions & 0 deletions app/code/Magento/Ui/Component/Control/ActionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ public function update($key, array $data)
}
}

/**
* Add html block
*
* @param string $type
* @param string $name
* @param array $arguments
* @return void
*/
public function addHtmlBlock($type, $name = '', array $arguments = [])
{
$toolbar = $this->getToolbar();
$container = $this->context->getPageLayout()->createBlock($type, $name, $arguments);
$toolbar->setChild($name, $container);
}

/**
* Create button container
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ define([
/** @inheritdoc*/
destroyInserted: function () {
if (this.isRendered) {
this.externalForm().destroy();
this.externalForm().delegate('destroy');
this.removeActions();
this.responseStatus(undefined);
this.responseData = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ define([
return this;
}

self.previousParams = params || {};

$.async({
component: this.name
}, function (el) {
self.contentEl = $(el);
self.startRender = true;
params = _.extend(params || {}, self.params);
params = _.extend({}, self.params, params || {});
request = self.requestData(params, self.renderSettings);
request
.done(self.onRender)
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/modal/modal-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ define([
* @returns {Object} Chainable.
*/
initSelector: function () {
var modalClass = this.name.replace(/\./g, '_');

this.contentSelector = '.' + this.modalClass;
this.options.modalClass = this.name.replace(/\./g, '_');
this.rootSelector = '.' + this.options.modalClass;
this.options.modalClass = this.options.modalClass + ' ' + modalClass;
this.rootSelector = '.' + modalClass;

return this;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

@import 'module/_scheduled-changes.less';
@import 'module/_staging-data-tooltip.less';
@import 'module/_scheduled-changes-modal.less';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// /**
// * Copyright © 2015 Magento. All rights reserved.
// * See COPYING.txt for license details.
// */

//
// Scheduled changes modal
// _____________________________________________

//
// Slide modal panel with store switcher
// ---------------------------------------------

.scheduled-changes-modal-slide {
.page-actions {
.lib-vendor-prefix-display(flex);
width: 100%;

.store-switcher {
.lib-vendor-prefix-order(-1);
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;

.admin__action-dropdown {
font-size: @action-dropdown__font-size;
letter-spacing: -.025em;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,58 @@ public function testSuggestCategoriesActionNoSuggestions()
public function saveActionDataProvider()
{
return [
//'default values' removed from here. Should be fixed in MAGETWO-49481
'default values' => [
[
'id' => '2',
'entity_id' => '2',
'path' => '1/2',
'url_key' => 'default-category',
'is_anchor' => false,
'use_default' => [
'name' => 1,
'is_active' => 1,
'thumbnail' => 1,
'description' => 1,
'image' => 1,
'meta_title' => 1,
'meta_keywords' => 1,
'meta_description' => 1,
'include_in_menu' => 1,
'display_mode' => 1,
'landing_page' => 1,
'available_sort_by' => 1,
'default_sort_by' => 1,
'filter_price_range' => 1,
'custom_apply_to_products' => 1,
'custom_design' => 1,
'custom_design_from' => 1,
'custom_design_to' => 1,
'page_layout' => 1,
'custom_layout_update' => 1,
],
],
[
'name' => false,
'default_sort_by' => false,
'display_mode' => false,
'meta_title' => false,
'custom_design' => false,
'page_layout' => false,
'is_active' => false,
'include_in_menu' => false,
'landing_page' => false,
'is_anchor' => false,
'custom_apply_to_products' => false,
'available_sort_by' => false,
'description' => false,
'meta_keywords' => false,
'meta_description' => false,
'custom_layout_update' => false,
'custom_design_from' => false,
'custom_design_to' => false,
'filter_price_range' => false
],
],
'custom values' => [
[
'id' => '2',
Expand All @@ -163,7 +214,7 @@ public function saveActionDataProvider()
'url_key' => 'default-category',
'display_mode' => 'PRODUCTS',
'landing_page' => '1',
'is_anchor' => '1',
'is_anchor' => true,
'custom_apply_to_products' => '0',
'custom_design' => 'Magento/blank',
'custom_design_from' => '5/21/2015',
Expand Down Expand Up @@ -232,7 +283,7 @@ public function saveActionDataProvider()
'url_key' => 'default-category',
'display_mode' => 'PRODUCTS',
'landing_page' => '1',
'is_anchor' => '1',
'is_anchor' => true,
'custom_apply_to_products' => '0',
'custom_design' => 'Magento/blank',
'custom_design_from' => '5/29/2015',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ protected function setUp()
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\Catalog\Model\Product'
);
$this->markTestSkipped('Test skipped due to changes that appear after MAGETWO-45654');
}

public static function tearDownAfterClass()
Expand Down Expand Up @@ -434,6 +433,47 @@ public function testValidate()
}
}

/**
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/products_with_unique_input_attribute.php
*/
public function testValidateUniqueInputAttributeValue()
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get('Magento\Catalog\Model\ResourceModel\Eav\Attribute')
->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'unique_input_attribute');
$this->_model->setTypeId(
'simple'
)->setAttributeSetId(
4
)->setName(
'Simple Product with non-unique value'
)->setSku(
'some product SKU'
)->setPrice(
10
)->setMetaTitle(
'meta title'
)->setData(
$attribute->getAttributeCode(),
'unique value'
)->setVisibility(
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
)->setStatus(
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
)->setCollectExceptionMessages(
true
);

$validationResult = $this->_model->validate();
$this->assertCount(1, $validationResult);
$this->assertContains(
'The value of attribute "' . $attribute->getDefaultFrontendLabel() . '" must be unique',
$validationResult
);
}

/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoAppIsolation enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
require __DIR__ . '/unique_input_attribute.php';

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

/** @var $product \Magento\Catalog\Model\Product */
$product = $objectManager->create('Magento\Catalog\Model\Product');
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setName('Simple Product with unique input attribute')
->setSku('simple product with unique input attribute')
->setPrice(10)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setWebsiteIds([1])
->setStockData(['qty' => 100, 'is_in_stock' => 1])
->setData($attribute->getAttributeCode(), 'unique value')
->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* "Input" fixture of product EAV attribute.
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var \Magento\Eav\Model\Entity\Type $entityType */
$entityType = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Eav\Model\Entity\Type');
$entityType->loadByCode('catalog_product');
$defaultSetId = $entityType->getDefaultAttributeSetId();
/** @var \Magento\Eav\Model\Entity\Attribute\Set $defaultSet */
$defaultSet = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\Eav\Model\Entity\Attribute\Set'
);
$defaultSet->load($defaultSetId);
$defaultGroupId = $defaultSet->getDefaultGroupId();

/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\Catalog\Model\ResourceModel\Eav\Attribute'
);
$attribute->setAttributeCode(
'unique_input_attribute'
)->setEntityTypeId(
$entityType->getEntityTypeId()
)->setAttributeGroupId(
$defaultGroupId
)->setAttributeSetId(
$defaultSetId
)->setFrontendInput(
'text'
)->setFrontendLabel(
'Unique Input Attribute'
)->setBackendType(
'varchar'
)->setIsUserDefined(
1
)->setIsUnique(
1
)->save();
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ public function sortButtons(array $itemA, array $itemB)
return $sortOrderA - $sortOrderB;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function addHtmlBlocks(array $htmlBlocks, UiComponentInterface $component)
{
if (!empty($htmlBlocks)) {
foreach ($htmlBlocks as $htmlBlock => $blockData) {
$this->actionPool->addHtmlBlock($blockData['type'], $blockData['name'], $blockData['arguments']);
}
}
}

/**
* Getting requested accept type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public function getPageLayout();
*/
public function addButtons(array $buttons, UiComponentInterface $component);

/**
* Add html block in the actions toolbar
*
* @param array $htmlBlocks
* @param UiComponentInterface $component
* @return void
*/
public function addHtmlBlocks(array $htmlBlocks, UiComponentInterface $component);

/**
* Get render engine
*
Expand Down
Loading

0 comments on commit f278923

Please sign in to comment.