Skip to content

Commit

Permalink
Merge branch 'develop' into MAGETWO-39265
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Logvin committed Aug 6, 2015
2 parents 27abdc9 + 12f560b commit 6f065d7
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,19 @@ public function getProductStockQty(Product $product)
{
return $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId())->getQty();
}

/**
* @param array $initData
* @return string
*/
public function getVariationWizard($initData)
{
/** @var \Magento\Ui\Block\Component\StepsWizard $wizardBlock */
$wizardBlock = $this->getChildBlock('variation-steps-wizard');
if ($wizardBlock) {
$wizardBlock->setInitData($initData);
return $wizardBlock->toHtml();
}
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,34 @@ public function testGetProductStockQty()

$this->assertEquals($qty, $this->_block->getProductStockQty($productMock));
}

/**
* @dataProvider getVariationWizardDataProvider
* @param string $wizardBlockName
* @param string $wizardHtml
*/
public function testGetVariationWizard($wizardBlockName, $wizardHtml)
{
$initData = ['some-key' => 'some-value'];

$layout = $this->getMock('Magento\Framework\View\LayoutInterface');
$wizardBlock = $this->getMock('Magento\Ui\Block\Component\StepsWizard', [], [], '', false);
$layout->expects($this->any())->method('getChildName')->with(null, 'variation-steps-wizard')
->willReturn($wizardBlockName);
$layout->expects($this->any())->method('getBlock')->with($wizardBlockName)->willReturn($wizardBlock);
$wizardBlock->expects($this->any())->method('setInitData')->with($initData);
$wizardBlock->expects($this->any())->method('toHtml')->willReturn($wizardHtml);

$this->_block->setLayout($layout);

$this->assertEquals($wizardHtml, $this->_block->getVariationWizard($initData));
}

/**
* @return array
*/
public function getVariationWizardDataProvider()
{
return [['WizardBlockName', 'WizardHtml'], ['', '']];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,4 @@
<css src="Magento_ConfigurableProduct::css/configurable-product.css"/>
</head>
<update handle="catalog_product_superconfig_config"/>
<body>
<referenceBlock name="product_tabs">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" template="Magento_ConfigurableProduct::catalog/product/edit/super/generator.phtml" name="product-variations-generator" as="generator">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Attribute" template="Magento_ConfigurableProduct::catalog/product/edit/super/attribute-template.phtml" as="attribute-renderer"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Matrix" template="Magento_ConfigurableProduct::catalog/product/edit/super/matrix.phtml" as="matrix"/>
</block>
</block>
<action method="addTab">
<argument name="name" xsi:type="string">super_config</argument>
<argument name="block" xsi:type="string">admin.product.edit.tab.super.config.grid.container</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,4 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="catalog_product_superconfig_config"/>
<body>
<referenceBlock name="product_tabs">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" template="Magento_ConfigurableProduct::catalog/product/edit/super/generator.phtml" name="product-variations-generator" as="generator">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Attribute" template="Magento_ConfigurableProduct::catalog/product/edit/super/attribute-template.phtml" as="attribute-renderer"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Matrix" template="Magento_ConfigurableProduct::catalog/product/edit/super/matrix.phtml" as="matrix"/>
</block>
</block>
<action method="addTab">
<argument name="name" xsi:type="string">super_config</argument>
<argument name="block" xsi:type="string">admin.product.edit.tab.super.config.grid.container</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,4 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="catalog_product_superconfig_config"/>
<body>
<referenceBlock name="product_tabs">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" template="Magento_ConfigurableProduct::catalog/product/edit/super/generator.phtml" name="product-variations-generator" as="generator">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Attribute" template="Magento_ConfigurableProduct::catalog/product/edit/super/attribute-template.phtml" as="attribute-renderer"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Matrix" template="Magento_ConfigurableProduct::catalog/product/edit/super/matrix.phtml" as="matrix"/>
</block>
</block>
<action method="addTab">
<argument name="name" xsi:type="string">super_config</argument>
<argument name="block" xsi:type="string">admin.product.edit.tab.super.config.grid.container</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,27 @@
</block>
</block>
</referenceBlock>
<referenceContainer name="content">
<block class="Magento\Ui\Block\Component\StepsWizard" name="variation-steps-wizard">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes" name="step1" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/select_attributes.phtml">
<uiComponent name="product_attributes_listing"/>
<referenceBlock name="product_tabs">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" template="Magento_ConfigurableProduct::catalog/product/edit/super/generator.phtml" name="product-variations-generator" as="generator">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Attribute" template="Magento_ConfigurableProduct::catalog/product/edit/super/attribute-template.phtml" as="attribute-renderer"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Matrix" template="Magento_ConfigurableProduct::catalog/product/edit/super/matrix.phtml" as="matrix">
<block class="Magento\Ui\Block\Component\StepsWizard" name="variation-steps-wizard">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes" name="step1" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/select_attributes.phtml">
<uiComponent name="product_attributes_listing"/>
</block>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues" name="step2" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/attributes_values.phtml"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Bulk" name="step3" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/bulk.phtml"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Summary" name="step4" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/summary.phtml"/>
</block>
</block>
</block>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues" name="step2" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/attributes_values.phtml"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Bulk" name="step3"
template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/bulk.phtml"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Summary" name="step4" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/summary.phtml"/>
</block>
</referenceContainer>
<action method="addTab">
<argument name="name" xsi:type="string">super_config</argument>
<argument name="block" xsi:type="string">admin.product.edit.tab.super.config.grid.container</argument>
</action>
</referenceBlock>

</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,4 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="catalog_product_superconfig_config"/>
<body>
<referenceBlock name="product_tabs">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config" template="Magento_ConfigurableProduct::catalog/product/edit/super/generator.phtml" name="product-variations-generator" as="generator">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Attribute" template="Magento_ConfigurableProduct::catalog/product/edit/super/attribute-template.phtml" as="attribute-renderer"/>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Matrix" template="Magento_ConfigurableProduct::catalog/product/edit/super/matrix.phtml" as="matrix"/>
</block>
</block>
<action method="addTab">
<argument name="name" xsi:type="string">super_config</argument>
<argument name="block" xsi:type="string">admin.product.edit.tab.super.config.grid.container</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes */
?>
<div class="select-attributes-block">
<div class="select-attributes-actions">
<div class="select-attributes-actions" data-type="skipKO">
<?= $block->getAddNewAttributeButton(); ?>
</div>
<h2 class="steps-wizard-title"><?= __('Step 1: Select Attributes') ?></h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
</div>

<div class="fieldset-wrapper-content collapse" data-collapsed="true" id="<?php echo $block->getId() ?>-content">
<div class="product-create-configuration">
<div data-bind="scope: 'variation-steps-wizard'" class="product-create-configuration">
<div class="product-create-configuration-info">
<div class="note">
<?= __('Configurable products allow customers to choose options (Ex: shirt color).
Expand All @@ -28,8 +28,14 @@ use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
</div>
<div class="product-create-configuration-actions">
<button data-action="open-steps-wizard" title="Create Product Configurations"
class="action-secondary" onclick="return openVariationsWizard();">
<span><?= __('Create Configurations') ?></span>
class="action-secondary" data-bind="click: open">
<span data-role="button-label" data-edit-label="<?= __('Edit Configurations') ?>">
<?= $block->getProduct()->getId()
&& $block->getProduct()->getTypeId() === 'configurable'
? __('Edit Configurations')
: __('Create Configurations')
?>
</span>
</button>
</div>
</div>
Expand All @@ -47,15 +53,6 @@ use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
</div>
</div>
<script>
var openVariationsWizard = function() {
var $form = jQuery('[data-form=edit-product]');
if (!$form.valid()) {
$form.data('validator').focusInvalid();
return false;
}
jQuery('[data-role=step-wizard-dialog]').trigger('openModal');
return false;
};
require([
'jquery',
'mage/template',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if ($variations) {
'value' => $optionId,
];
$variationOptions[] = $variationOption;
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
$attributes[$attribute->getAttributeId()]['chosen'][$optionId] = $variationOption;
}

$productMatrix[] = [
Expand All @@ -64,6 +64,7 @@ if ($variations) {
];
}
}
$attributes = array_values($attributes);
}
?>

Expand Down Expand Up @@ -269,6 +270,16 @@ if ($variations) {
</div>
<!-- /ko -->
</div>
<div data-role="step-wizard-dialog"
data-mage-init='{"Magento_Ui/js/modal/modal":{"type":"slide","title":"<?= __('Create Product Configurations') ?>",
"buttons":[]}}'
class="no-display">
<?php
echo $block->getVariationWizard([
'attributes' => $attributes
]);
?>
</div>
<script type="text/x-magento-init">
{
"*": {
Expand All @@ -277,7 +288,7 @@ if ($variations) {
"configurableVariations": {
"component": "Magento_ConfigurableProduct/js/variations/variations",
"variations": <?= $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($productMatrix) ?>,
"productAttributes": <?= $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode(array_values($attributes)) ?>,
"productAttributes": <?= $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($attributes) ?>,
"productUrl": "<?= $block->getUrl('catalog/product/edit', ['id' => '%id%']) ?>"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="links" xsi:type="array">
<item name="applied" xsi:type="string">not-save-filter</item>
</item>
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="dataScope" xsi:type="string">filters</item>
<item name="storageConfig" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define([
});

return Collapsible.extend({
stepInitialized: false,
attributes: ko.observableArray([]),
createOption: function () {
// this - current attribute
Expand Down Expand Up @@ -136,10 +137,33 @@ define([
showLoader: true
}).done(function(attributes){
this.attributes(saveAttributes.call(this, attributes));
this.doInitSavedOptions();
}.bind(this));
},
doInitSavedOptions: function() {
if (false === this.stepInitialized) {
this.stepInitialized = true;
_.each(this.attributes(), function(attribute) {
var selectedAttribute = _.findWhere(this.initData.attributes, {id: attribute.id});
if (selectedAttribute) {
var selectedOptions = _.pluck(selectedAttribute.chosen, 'value');
var selectedOptionsIds = _.pluck(_.filter(attribute.options(), function (option) {
return _.contains(selectedOptions, option.value)
}), 'id');
attribute.chosenOptions(selectedOptionsIds);
}
}.bind(this));
}
},
render: function(wizard) {
this.wizard = wizard;
if (this.initData) {
this.wizard.notifyMessage(
$.mage.__('When you remove or add an attribute, we automatically ' +
'update all configurations and you will need to manually recreate the current configurations.'),
false
);
}
this.requestAttributes(wizard.data.attributesIds());
},
force: function(wizard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ define([
},
types: ['each', 'single', 'none'],
render: function (wizard) {
this.wizard = wizard;
if (this.initData) {
this.wizard.notifyMessage(
$.mage.__('When you remove or add an attribute, we automatically ' +
'update all configurations and you will need to manually recreate the current configurations.'),
false
);
}
this.attributes(wizard.data.attributes());

//fill option section data
Expand Down
Loading

0 comments on commit 6f065d7

Please sign in to comment.