Skip to content

Commit

Permalink
Merge pull request #251 from magento-goinc/pr-11.12
Browse files Browse the repository at this point in the history
[SWAT] Bug fixes
  • Loading branch information
Kopylova,Olga(okopylova) committed Dec 18, 2015
2 parents 81ee51c + fe76bca commit 3f148f9
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,10 @@ jQuery(window).load(function() {

});
</script>
<script type="text/x-magento-init">
{
"*": {
"Magento_Bundle/js/bundle-type-handler": {}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Category\Tab;

class Attributes extends \Magento\Backend\Block\Widget\Form\Generic
class Attributes extends \Magento\Catalog\Block\Adminhtml\Form
{
/**
* Retrieve Category object
Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Catalog/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
$categorySetup->updateAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'sort_order', '10');

$groups = [
'display' => ['name' => 'Display Settings', 'sort' => 20, 'id' => null],
'design' => ['name' => 'Custom Design', 'sort' => 30, 'id' => null],
'display' => ['name' => 'Display Settings', 'code' => 'display-settings', 'sort' => 20, 'id' => null],
'design' => ['name' => 'Custom Design', 'code' => 'custom-design', 'sort' => 30, 'id' => null],
];

foreach ($groups as $k => $groupProp) {
$categorySetup->addAttributeGroup($entityTypeId, $attributeSetId, $groupProp['name'], $groupProp['sort']);
$groups[$k]['id'] = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['name']);
$groups[$k]['id'] = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['code']);
}

// update attributes group and sort
Expand Down Expand Up @@ -183,25 +183,25 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
$tabNames = [
'General' => [
'attribute_group_name' => $newGeneralTabName,
'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newGeneralTabName)),
'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newGeneralTabName),
'tab_group_code' => 'basic',
'sort_order' => 10,
],
'Images' => [
'attribute_group_name' => $newImagesTabName,
'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newImagesTabName)),
'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newImagesTabName),
'tab_group_code' => 'basic',
'sort_order' => 20,
],
'Meta Information' => [
'attribute_group_name' => $newMetaTabName,
'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newMetaTabName)),
'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newMetaTabName),
'tab_group_code' => 'basic',
'sort_order' => 30,
],
'Prices' => [
'attribute_group_name' => $newPriceTabName,
'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newPriceTabName)),
'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newPriceTabName),
'tab_group_code' => 'advanced',
'sort_order' => 40,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ define([
*/
init: function () {

if (weight.productHasWeight()) {
//not weight switcher for specific product
if (weight.productHasWeightBySwitcher() && weight.hasWeightSwither()) {
this.type = {
virtual: 'virtual',
real: this.$type.val() //simple, configurable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,102 @@ define([

return {

$weightSwitcher: $('[data-role=weight-switcher]'),
$weight: $('#weight'),
/**
* Get weight
* @returns {*|jQuery|HTMLElement}
*/
$weight: function () {
return $('#weight');
},

/**
* Hide weight switcher
* Weight Switcher
* @returns {*|jQuery|HTMLElement}
*/
hideWeightSwitcher: function () {
this.$weightSwitcher.hide();
$weightSwitcher: function () {
return $('[data-role=weight-switcher]');
},

/**
* Is locked
* @returns {*}
*/
isLocked: function () {
return this.$weight.is('[data-locked]');
return this.$weight().is('[data-locked]');
},

/**
* Disabled
*/
disabled: function () {
this.$weight.addClass('ignore-validate').prop('disabled', true);
this.$weight().addClass('ignore-validate').prop('disabled', true);
},

/**
* Enabled
*/
enabled: function () {
this.$weight.removeClass('ignore-validate').prop('disabled', false);
this.$weight().removeClass('ignore-validate').prop('disabled', false);
},

/**
* Switch Weight
* @returns {*}
*/
switchWeight: function () {
return this.productHasWeight() ? this.enabled() : this.disabled();
return this.productHasWeightBySwitcher() ? this.enabled() : this.disabled();
},

/**
* Product has weight
* @returns {Bool}
* Hide weight switcher
*/
productHasWeight: function () {
return $('input:checked', this.$weightSwitcher).val() === '1';
hideWeightSwitcher: function () {
this.$weightSwitcher().hide();
},

/**
* Notify product weight is changed
* @returns {*|jQuery}
* Has weight swither
* @returns {*}
*/
notifyProductWeightIsChanged: function () {
return $('input:checked', this.$weightSwitcher).trigger('change');
hasWeightSwither: function () {
return this.$weightSwitcher().is(':visible');
},

/**
* Product has weight
* @returns {Bool}
*/
productHasWeightBySwitcher: function () {
return $('input:checked', this.$weightSwitcher()).val() === '1';
},

/**
* Change
* @param {String} data
*/
change: function (data) {
var value = data !== undefined ? +data : !this.productHasWeight();
var value = data !== undefined ? +data : !this.productHasWeightBySwitcher();

$('input[value=' + value + ']', this.$weightSwitcher).prop('checked', true);
$('input[value=' + value + ']', this.$weightSwitcher()).prop('checked', true);
this.switchWeight();
},

/**
* Constructor component
*/
'Magento_Catalog/js/product/weight-handler': function () {
this.bindAll();
this.switchWeight();

if (this.hasWeightSwither()) {
this.switchWeight();
}
},

/**
* Bind all
*/
bindAll: function () {
this.$weightSwitcher.find('input').on('change', this.switchWeight.bind(this));
this.$weightSwitcher().find('input').on('change', this.switchWeight.bind(this));
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define([
_initType: function () {
if (productType.type.current === 'downloadable') {
weight.change(false);
weight.$weightSwitcher.one('change', function () {
weight.$weightSwitcher().one('change', function () {
$(document).trigger('setTypeProduct', null);
});
this.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
*/
class Group extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* Constants for attribute group codes
*/
const TAB_GENERAL_CODE = 'product-details';

const TAB_IMAGE_MANAGEMENT_CODE = 'image-management';

/**
* Resource initialization
*
Expand Down
33 changes: 21 additions & 12 deletions app/code/Magento/Eav/Setup/EavSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EavSetup
*
* @var array
*/
private $defaultGroupIdAssociations = ['General' => 1];
private $defaultGroupIdAssociations = ['general' => 1];

/**
* Default attribute group name
Expand Down Expand Up @@ -134,12 +134,12 @@ public function cleanCache()
public function installDefaultGroupIds()
{
$setIds = $this->getAllAttributeSetIds();
foreach ($this->defaultGroupIdAssociations as $defaultGroupName => $defaultGroupId) {
foreach ($this->defaultGroupIdAssociations as $defaultGroupCode => $defaultGroupId) {
foreach ($setIds as $set) {
$groupId = $this->setup->getTableRow(
'eav_attribute_group',
'attribute_group_name',
$defaultGroupName,
'attribute_group_code',
$defaultGroupCode,
'attribute_group_id',
'attribute_set_id',
$set
Expand Down Expand Up @@ -511,24 +511,24 @@ public function addAttributeGroup($entityTypeId, $setId, $name, $sortOrder = nul
{
$setId = $this->getAttributeSetId($entityTypeId, $setId);
$data = ['attribute_set_id' => $setId, 'attribute_group_name' => $name];
$attributeGroupCode = $this->convertToAttributeGroupCode($name);

if (isset($this->defaultGroupIdAssociations[$name])) {
$data['default_id'] = $this->defaultGroupIdAssociations[$name];
if (isset($this->defaultGroupIdAssociations[$attributeGroupCode])) {
$data['default_id'] = $this->defaultGroupIdAssociations[$attributeGroupCode];
}

if ($sortOrder !== null) {
$data['sort_order'] = $sortOrder;
}

$groupId = $this->getAttributeGroup($entityTypeId, $setId, $name, 'attribute_group_id');
$groupId = $this->getAttributeGroup($entityTypeId, $setId, $attributeGroupCode, 'attribute_group_id');
if ($groupId) {
$this->updateAttributeGroup($entityTypeId, $setId, $groupId, $data);
} else {
if ($sortOrder === null) {
$data['sort_order'] = $this->getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder);
}
if (empty($data['attribute_group_code'])) {
$attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($name)), '-');
if (empty($attributeGroupCode)) {
// in the following code md5 is not used for security purposes
$attributeGroupCode = md5($name);
Expand All @@ -541,6 +541,15 @@ public function addAttributeGroup($entityTypeId, $setId, $name, $sortOrder = nul
return $this;
}

/**
* @param string $groupName
* @return string
*/
public function convertToAttributeGroupCode($groupName)
{
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-');
}

/**
* Update Attribute Group Data
*
Expand Down Expand Up @@ -577,22 +586,22 @@ public function updateAttributeGroup($entityTypeId, $setId, $id, $field, $value
*/
public function getAttributeGroup($entityTypeId, $setId, $id, $field = null)
{
$searchId = $id;
if (is_numeric($id)) {
$searchField = 'attribute_group_id';
} else {
$id = $this->convertToAttributeGroupCode($id);
if (isset($this->defaultGroupIdAssociations[$id])) {
$searchField = 'default_id';
$searchId = $this->defaultGroupIdAssociations[$id];
$id = $this->defaultGroupIdAssociations[$id];
} else {
$searchField = 'attribute_group_name';
$searchField = 'attribute_group_code';
}
}

return $this->setup->getTableRow(
'eav_attribute_group',
$searchField,
$searchId,
$id,
$field,
'attribute_set_id',
$this->getAttributeSetId($entityTypeId, $setId)
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/ProductVideo/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$attributeGroup = $categorySetup->getAttributeGroup(
$entityTypeId,
$attributeSetId,
'Image Management'
'image-management'
);
if (isset($attributeGroup['attribute_group_name'])
&& $attributeGroup['attribute_group_name'] == 'Image Management'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Constraint;

use Magento\Catalog\Test\Page\Product\CatalogProductView;
use Magento\Customer\Test\Fixture\Customer;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Mtf\Fixture\FixtureInterface;

/**
* Assert that displayed tier price on product page equals passed from fixture for specified customer.
*/
class AssertProductTierPriceOnProductPageWithCustomer extends AbstractConstraint
{
/**
* Assertion that tier prices are displayed correctly for specified customer
*
* @param BrowserInterface $browser
* @param CatalogProductView $catalogProductView
* @param FixtureInterface $product
* @param Customer $customer
* @return void
*/
public function processAssert(
BrowserInterface $browser,
CatalogProductView $catalogProductView,
FixtureInterface $product,
Customer $customer
) {
$customer->persist();
$this->loginCustomer($customer);

$productTierPriceAssert = $this->objectManager->get(
'Magento\Catalog\Test\Constraint\AssertProductTierPriceOnProductPage'
);
$productTierPriceAssert->processAssert($browser, $catalogProductView, $product);
}

/**
* Login customer
*
* @param Customer $customer
*
* @return void
*/
protected function loginCustomer($customer)
{
$this->objectManager->create(
'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep',
['customer' => $customer]
)->run();
}

/**
* Returns a string representation of the object
*
* @return string
*/
public function toString()
{
return 'Tier price is displayed on the product page for specific customer.';
}
}
Loading

0 comments on commit 3f148f9

Please sign in to comment.