Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed MAGE-4238 (#109): disabled select all checkbox when the same optio... #221

Merged
merged 3 commits into from

2 participants

Lindy Yang Andrey Tserkus
Lindy Yang
Collaborator

Disabled select all checkbox when the same options show up for different simple product under configurable associated product grid

Andrey Tserkus zerkella was assigned
Andrey Tserkus

It is better to name the method on action what it does - e.g. _loadConfigurableAttribute() or _cacheConfigurableAttributes().
However, in current case the best name is _getConfigurableAttributes(), as this method must return the array with attributes. Otherwise, the workflow is not clear - the method is called, then data is fetched from other source ($_configAttributeCodes)

Andrey Tserkus

When there are no config attributes in the product, then the caching does not work. Suggested:

  • Make _configAttributeCodes null by default
  • Make condition here as if ($this->_configAttributeCodes == null)...

And there is space needed after if

Andrey Tserkus

A very important thing is that the submitted changeset fixes UI only, but it definitely doesn't fix model or controllers logic, which still allows to run into such an inappropriate situation, as described in the issue ticket.

It is expected, that those models must be fixed as well.

Collaborator

It would be better to locate the methods in the order how they are referenced in the code. So _afterCollection() must be first, then the _configurableAttributes(), then retrieveRowData(), etc. Otherwise for a reader, it is hard to read the code - he reads the class as separate and completely unrelated methods at first, and only one method at the end combines them all together at the time, when a reader has already forgotten, what those methods do.

Andrey Tserkus

The description is better to be re-written. It doesn't make anything more clear.

Expected, that the description should describe purpose of the method. E.g. "Template method, called after the collection is loaded. Process product attributes and update view of the grid accordingly"

Andrey Tserkus

Not sure, that _afterLoadCollection() is the best method to put this logic to. What do you think about _beforeToHtml() - it seems to be more related to rendering, which is affected by its functionality.

Andrey Tserkus

It seems, we don't need to do anything at all, when there are no attribute codes. we can just return from the method call in such a case.

We can restructure the method like:

function () 
{
    parent::_afterLoadCollection();
    if (!$this->_configAttributeCodes()) {
        return $this;
    }

    ...disable the checkbox if needed...

    return $this;
}
Andrey Tserkus

_retrieveRowData() may produce bool, which doesn't suit to be passed to _checkRowData()

Andrey Tserkus

The variable should not start with the underscore

Andrey Tserkus

This method can be simplifed much.

The selected products have same attribute set id, thus they will have same attribute codes to compare values. So the arrays compared are:

  • Always of the same size
  • Always contain same attribute codes

It means, that we can create associative arrays as (code => value) rather than indexed (['code' => <code>, 'value' => <value>], ...). Thus the checking, whether some values differ, can be done just by straight comparison of the arrays. We even don't need this method at all.

$multiSelectAllow = ($needleAttributeValues == $attributeValues)
Lindy Yang lindyk was assigned
Andrey Tserkus
Collaborator

Reopening to fix the issues found and submit the pull request again.
And, of course, we're waiting for the test :)

Kao and others added some commits
Kao Fixed MAGE-4238 (#109): disabled select all checkbox when the same op…
…tions show in the associated product grid with functional testing
41496b8
Andrey Tserkus zerkella Fixed MAGE-4238 (#109): disabled select all checkbox when the same op…
…tions show in the associated product grid with functional testing

- improved readability of changed code
- removed unfinished test
09cff8b
Andrey Tserkus
Collaborator

The code change is ok, removed the non-finished taf tests - they can be made later. Accepted pull request.

Thanks!

Andrey Tserkus zerkella merged commit 30ef052 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2013
  1. Fixed MAGE-4238 (#109): disabled select all checkbox when the same op…

    Kao authored
    …tions show in the associated product grid
  2. Fixed MAGE-4238 (#109): disabled select all checkbox when the same op…

    Kao authored
    …tions show in the associated product grid with functional testing
  3. Andrey Tserkus

    Fixed MAGE-4238 (#109): disabled select all checkbox when the same op…

    zerkella authored
    …tions show in the associated product grid with functional testing
    
    - improved readability of changed code
    - removed unfinished test
This page is out of date. Refresh to see the latest.
83 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php
View
@@ -34,6 +34,8 @@
class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
+ protected $_configAttributeCodes = null;
+
public function __construct()
{
parent::__construct();
@@ -309,4 +311,85 @@ public function getGridUrl()
return $this->getUrl('*/*/superConfig', array('_current'=>true));
}
+ /**
+ * Retrieving configurable attributes
+ */
+ protected function _getConfigAttributeCodes()
+ {
+ if (is_null($this->_configAttributeCodes)) {
+ $product = $this->_getProduct();
+ $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
+ $attributeCodes = array();
+ foreach ($attributes as $attribute) {
+ $productAttribute = $attribute->getProductAttribute();
+ $attributeCodes[] = $productAttribute->getAttributeCode();
+ }
+ $this->_configAttributeCodes = $attributeCodes;
+ }
+ return $this->_configAttributeCodes;
+ }
+
+ /**
+ * Retrieve item row configurable attribute data
+ *
+ * @param Varien_Object $item
+ * @return array
+ */
+ protected function _retrieveRowData(Varien_Object $item)
+ {
+ $attributeValues = array();
+ foreach ($this->_getConfigAttributeCodes() as $attributeCode) {
+ $data = $item->getData($attributeCode);
+ if ($data) {
+ $attributeValues[$attributeCode] = $data;
+ }
+ }
+ return $attributeValues;
+ }
+
+ /**
+ * Checking the data contains the same value of data after collection
+ *
+ * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid
+ */
+ protected function _afterLoadCollection()
+ {
+ parent::_afterLoadCollection();
+
+ $attributeCodes = $this->_getConfigAttributeCodes();
+ if (!$attributeCodes) {
+ return $this;
+ }
+
+ $disableMultiSelect = false;
+ $ids = array();
+ foreach ($this->_collection as $item) {
+ $ids[] = $item->getId();
+ $needleAttributeValues = $this->_retrieveRowData($item);
+ foreach($this->_collection as $item2) {
+ // Skip the data if already checked
+ if (in_array($item2->getId(), $ids)) {
+ continue;
+ }
+ $attributeValues = $this->_retrieveRowData($item2);
+ $disableMultiSelect = ($needleAttributeValues == $attributeValues);
+ if ($disableMultiSelect) {
+ break;
+ }
+ }
+ if ($disableMultiSelect) {
+ break;
+ }
+ }
+
+ // Disable multiselect column
+ if ($disableMultiSelect) {
+ $selectAll = $this->getColumn('in_products');
+ if ($selectAll) {
+ $selectAll->setDisabled(true);
+ }
+ }
+
+ return $this;
+ }
}
2  taf/fixture/default/core/Mage/Product/data/Product.yml
View
@@ -2211,4 +2211,4 @@ configurable_multi_checkout_options:
associated_products_attribute_name: %noValue%
associated_configurable_1: *configurableAssociatedProductMulti
associated_configurable_2: *configurableAssociatedProductMulti
- associated_configurable_3: *configurableAssociatedProductMulti
+ associated_configurable_3: *configurableAssociatedProductMulti
2  taf/fixture/default/core/Mage/Product/uimap/admin/Product.yml
View
@@ -752,4 +752,4 @@ created_empty_simple_from_configurable:
form: *newProductCreationForm
buttons:
close_window: //button[span='Close Window']
- messages: *productMesssages
+ messages: *productMesssages
Something went wrong with that request. Please try again.