Skip to content

Commit

Permalink
Merge pull request #566 from magento-goinc/MAGETWO-41755
Browse files Browse the repository at this point in the history
[GoInc] Configurable Product Variation Update, manual selection product an association - create grid
  • Loading branch information
Slabko,Michael(mslabko) committed Sep 7, 2015
2 parents 91dc2d6 + 744f317 commit 7c59753
Show file tree
Hide file tree
Showing 20 changed files with 802 additions and 442 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function getGalleryImages()
$product = $this->getProduct();
$images = $product->getMediaGalleryImages();
if ($images instanceof \Magento\Framework\Data\Collection) {
foreach ($images as &$image) {
foreach ($images as $image) {
/* @var \Magento\Framework\DataObject $image */
$image->setData(
'small_image_url',
$this->_imageHelper->init($product, 'product_page_image_small')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function execute()

if ($attribute->getId() && !$attributeId) {
if (strlen($this->getRequest()->getParam('attribute_code'))) {
$response->setAttributes(['attribute_code' => __('An attribute with this code already exists.')]);
$response->setMessage(
__('An attribute with this code already exists.')
);
} else {
$response->setAttributes(
['attribute_label' => __('An attribute with the same code (%1) already exists.', $attributeCode)]
$response->setMessage(
__('An attribute with the same code (%1) already exists.', $attributeCode)
);
}
$response->setError(true);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Ui/Component/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function create($attribute, $context)
'dataScope' => $columnName,
'label' => __($attribute->getDefaultFrontendLabel()),
];
if ($attribute->usesSource()) {
if ($attribute->usesSource() && $attribute->getSourceModel()) {
$config['options'] = $attribute->getSource()->getAllOptions();
$config['caption'] = __('Select...');
}
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Catalog/Ui/Component/Listing/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class Filters extends \Magento\Ui\Component\Filters
{
/**
* @var AttributeRepository
*/
protected $attributeRepository;

/**
* @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
* @param \Magento\Catalog\Ui\Component\FilterFactory $filterFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Ui\Component\Listing\AssociatedProduct;

class Filters extends \Magento\Ui\Component\Filters
{
/**
* @var \Magento\Eav\Model\Resource\Entity\Attribute\CollectionFactory
*/
protected $attributeCollectionFactory;

/**
* @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
* @param \Magento\Catalog\Ui\Component\FilterFactory $filterFactory
* @param \Magento\Eav\Model\Resource\Entity\Attribute\CollectionFactory $attributeCollectionFactory
* @param array $components
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\UiComponent\ContextInterface $context,
\Magento\Catalog\Ui\Component\FilterFactory $filterFactory,
\Magento\Eav\Model\Resource\Entity\Attribute\CollectionFactory $attributeCollectionFactory,
array $components = [],
array $data = []
) {
parent::__construct($context, $components, $data);
$this->filterFactory = $filterFactory;
$this->attributeCollectionFactory = $attributeCollectionFactory;
}

/**
* {@inheritdoc}
*/
public function prepare()
{
$attributeIds = $this->context->getRequestParam('attribute_ids');
if ($attributeIds) {
foreach ($this->getAttributes($attributeIds) as $attribute) {
$filter = $this->filterFactory->create($attribute, $this->getContext());
$filter->prepare();
$this->addComponent($attribute->getAttributeCode(), $filter);
}
}
parent::prepare();
}

/**
* @param array $attributeIds
* @return mixed
*/
protected function getAttributes($attributeIds)
{
$attributeCollection = $this->attributeCollectionFactory->create();
return $attributeCollection->addFieldToFilter('attribute_code', ['in' => $attributeIds]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,8 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="admin.product.edit.tab.super.config.grid.container">
<block class="Magento\Backend\Block\Widget\Grid" name="admin.product.edit.tab.super.config.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">configurable_associated_products_grid</argument>
<argument name="dataSource" xsi:type="object">Magento\ConfigurableProduct\Model\Resource\Product\Collection\AssociatedProduct</argument>
<argument name="use_ajax" xsi:type="string">true</argument>
<argument name="default_sort" xsi:type="string">entity_id</argument>
<argument name="default_dir" xsi:type="string">DESC</argument>
<argument name="save_parameters_in_session" xsi:type="string">0</argument>
<argument name="grid_url" xsi:type="url" path="*/product_superConfig/index">
<param name="_current">1</param>
</argument>
</arguments>
<block class="Magento\ConfigurableProduct\Block\Product\Configurable\AssociatedSelector\Backend\Grid\ColumnSet" as="grid.columnSet" name="admin.product.edit.tab.super.config.grid.columnSet">
<arguments>
<argument name="id" xsi:type="string">super_product_links</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="entity_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">ID</argument>
<argument name="width" xsi:type="string">60px</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">entity_id</argument>
<argument name="id" xsi:type="string">entity_id</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
<argument name="renderer" xsi:type="string">Magento\ConfigurableProduct\Block\Product\Configurable\AssociatedSelector\Renderer\Id</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="name">
<arguments>
<argument name="header" xsi:type="string" translate="true">Name</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="index" xsi:type="string">name</argument>
<argument name="id" xsi:type="string">name</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="price">
<arguments>
<argument name="header" xsi:type="string" translate="true">Price</argument>
<argument name="type" xsi:type="string">currency</argument>
<argument name="index" xsi:type="string">price</argument>
<argument name="id" xsi:type="string">price</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="sku" name="admin.product.edit.tab.super.config.grid.sku">
<arguments>
<argument name="header" xsi:type="string" translate="true">SKU</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="index" xsi:type="string">sku</argument>
<argument name="id" xsi:type="string">sku</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="weight">
<arguments>
<argument name="header" xsi:type="string" translate="true">Weight</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">weight</argument>
<argument name="id" xsi:type="string">weight</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="inventory_in_stock" after="admin.product.edit.tab.super.config.grid.sku">
<arguments>
<argument name="header" xsi:type="string" translate="true">Stock Availability</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">inventory_in_stock</argument>
<argument name="id" xsi:type="string">inventory_in_stock</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
<argument name="renderer" xsi:type="string">Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Grid\Renderer\Inventory</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="qty" after="admin.product.edit.tab.super.config.grid.sku">
<arguments>
<argument name="header" xsi:type="string" translate="true">Qty</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">qty</argument>
<argument name="id" xsi:type="string">qty</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">1</argument>
</arguments>
</block>
</block>
<block class="Magento\Backend\Block\Template" name="manual.product.grid" template="Magento_ConfigurableProduct::catalog/product/edit/super/manual-product-grid.phtml" as="grid">
<uiComponent name="configurable_associated_product_listing"/>
</block>
</referenceBlock>
<referenceBlock name="product_tabs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@
</div>

<div class="attribute-entity-actions">
<button type="button" class="action-select-all action-tertiary" data-bind="click: $parent.selectAllAttributes">
<button type="button"
class="action-select-all action-tertiary"
data-bind="click: $parent.selectAllAttributes"
title="<?= $block->escapeHtml(__('Select All')) ?>">
<span><?= __('Select All') ?></span>
</button>
<button type="button" class="action-deselect-all action-tertiary" data-bind="click: $parent.deSelectAllAttributes">
<button type="button"
class="action-deselect-all action-tertiary"
data-bind="click: $parent.deSelectAllAttributes"
title="<?= $block->escapeHtml(__('Deselect All')) ?>">
<span><?= __('Deselect All') ?></span>
</button>
<button type="button"
class="action-remove-all action-tertiary"
data-bind="click: $parent.removeAttribute.bind($parent)"
title="<?= $block->escapeHtml(__('Remove Attribute')) ?>">
<span><?= __('Remove Attribute') ?></span>
</button>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="admin__data-grid-wrap admin__data-grid-wrap-static">
<!-- ko if: gridNew().length -->
<!-- ko template: {name: getGridTemplate(), data: {
grid: gridNew(),
grid: gridNew,
id: getGridId(),
title: $t('New Product Review'),
note: $t('Here are the products you\'re about to create.')
Expand All @@ -23,7 +23,7 @@

<!-- ko if: gridExisting().length -->
<!-- ko template: {name: getGridTemplate(), data: {
grid: gridExisting(),
grid: gridExisting,
id: getGridId(),
title: $t('Associated Products'),
note: $t('You created these products for this configuration.')
Expand All @@ -32,7 +32,7 @@

<!-- ko if: gridDeleted().length -->
<!-- ko template: {name: getGridTemplate(), data: {
grid: gridDeleted(),
grid: gridDeleted,
id: getGridId(),
title: $t('Disassociated Products'),
note: $t('These products are not associated.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
You need to create a simple product for each configuration (Ex: a product for each color).');?>
</div>
</div>
<!--<div class="product-create-configuration-actions">
<a class="action-menu-item" data-action="choose" onclick="jQuery('#associated-products-container').trigger('openModal');" href="#">
<?/*= __('Add Products Manually');*/?>
</a>
</div>-->
<div class="product-create-configuration-actions">
<button data-action="open-steps-wizard" title="Create Product Configurations"
class="action-secondary" data-bind="click: open">
Expand Down Expand Up @@ -123,70 +128,7 @@ require([
$(this).html('');
})
.on('click', '[data-action=choose]', function(event) {
event.preventDefault();
var grid = window.<?php echo $block->getGridJsObject() ?>;
var $button = $(this);
var attributeIds = [];
variationsContainer.find("input[name='attributes[]']").each(function () {
attributeIds.push($(this).val());
});

grid.reloadParams = {
filter: $button.data('attributes'),
'attributes[]': attributeIds
};
grid.reload(null, function() {
$gridDialog.trigger('openModal');
});

grid.rowClickCallback = function(grid, event) {
if (!this.rows || !this.rows.length) {
return;
}
var $gridRow = $(event.target).closest('tr'),
columnSelectorTemplate = '[data-column="%s"]';

if ($gridRow.find(columnSelectorTemplate.replace('%s', 'entity_id')).length) {
var $matrixRow = $button.parents('[data-role=row]');

$.each('name,sku,qty,weight,entity_id,price'.split(','), function () {
var columnSelector = columnSelectorTemplate.replace('%s', this),
target = $matrixRow.find(columnSelector),
value = $.trim($gridRow.find(columnSelector).text());

target[target.is('input') ? 'val' : 'text'](value);//.append(button);
});

var parentElement = $matrixRow.find('[data-column=image]'),
uploaderControl = parentElement.find('[data-action=upload-image]', parentElement),
imageElement = $matrixRow.find('[data-role=image]'),
selectedImageSrc = $gridRow.find('[data-role=image-url]').val();

if (imageElement.length) {
selectedImageSrc = selectedImageSrc || noImageUrl;
imageElement.attr('src', selectedImageSrc);
} else {
var tmpl = $('[data-role=product-variations-matrix]').find('[data-template-for=variation-image]').html();

tmpl = mageTemplate(tmpl, {
data: {
url: selectedImageSrc
}
});

$(tmpl).prependTo(uploaderControl);
}
$matrixRow.find('[name=image]')
.attr('src', selectedImageSrc)
.attr('data-locked', '1')
.trigger('click')
.prop({disabled: true});

$matrixRow.find('[name$="[image]"]').remove();
$matrixRow.find('[data-block="variation-images"]').remove();
}
$gridDialog.trigger('closeModal');
};
$gridDialog.trigger('openModal');
});
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Super\Config\Grid\ManualProduct */

?>
<div>
<div data-role="messages" class="messages">
<div class="message ">
<div>
<?= __('Choose a new product to delete and replace the current product configuration.') ?>
<?= __('For better results, add attributes and attribute values to your products.') ?>
</div>
</div>
</div>
<?= $block->getChildHtml(); ?>
</div>
Loading

0 comments on commit 7c59753

Please sign in to comment.