Handling grouped product attributes Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Select multiple product options at onceLooking for a way to extend attributesBest Practices for Planning Attributes and Attribute SetsMultiple Select - Render as url and searchMagmi: Attributes not being associated with attribute setsMagento 2 - Export/Import Product AttributesImporting attribute sets into Magento programmatically? Magmi?Old attributes persist after attribute set is changed in Magento 2How to change dynamic attributes when simple product is selectedGrouped Products: Filter based on simple productsProgrammatically Delete Product Attribute Sets

Can a non-EU citizen traveling with me come with me through the EU passport line?

Is the Standard Deduction better than Itemized when both are the same amount?

Is there a concise way to say "all of the X, one of each"?

Stars Make Stars

Right-skewed distribution with mean equals to mode?

If 'B is more likely given A', then 'A is more likely given B'

What is the correct way to use the pinch test for dehydration?

Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?

What are the motives behind Cersei's orders given to Bronn?

How do I mention the quality of my school without bragging

Did Xerox really develop the first LAN?

Doubts about chords

Should gear shift center itself while in neutral?

What is a Meta algorithm?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

List *all* the tuples!

Java 8 stream max() function argument type Comparator vs Comparable

How to motivate offshore teams and trust them to deliver?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

Why does Python start at index 1 when iterating an array backwards?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Why was the term "discrete" used in discrete logarithm?



Handling grouped product attributes



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Select multiple product options at onceLooking for a way to extend attributesBest Practices for Planning Attributes and Attribute SetsMultiple Select - Render as url and searchMagmi: Attributes not being associated with attribute setsMagento 2 - Export/Import Product AttributesImporting attribute sets into Magento programmatically? Magmi?Old attributes persist after attribute set is changed in Magento 2How to change dynamic attributes when simple product is selectedGrouped Products: Filter based on simple productsProgrammatically Delete Product Attribute Sets



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6















I'm working on building a new Magento shop (this is my first with Magento).



I'm looking to replicate the look of an existing shop for my product pages, at least in terms of layout:



http://www.panamericantool.com/cobalt-drills/drill-stops.html



http://www.panamericantool.com/screw-driver-bits/paint-cutters.html



I've figured out that I need to use grouped products, with simple products to create the kind of thing I'm after.



In the examples above, each product has separate attributes, I assume these are done via different attribute sets in Magento.



However how do they go displaying those different table headings/values in the theme?



I know I can do ->getAttributeName() or ->getAttribute('attribute_code') in the grouped.phtml file, but this would result in a vast amount of if (->getAttributeName() != '')... and I'd need to change the template when adding more.



I'm sure there is a way of getting all attributes and looping over them, but then how would you differentiate between say the meta_description attribute (also returned by the $_product->getData() method) and an attribute I'd want listed in the table?



How could I achieve something akin to what they have?



I'm also concerned about performance the shop will have 5k products at launch, growing to perhaps 25k-30k as we add our remaining stock. Many of these will need different attributes, but I'm guessing I could share attributes between attribute sets without too many performance issues?




Update:



I've carried on playing around with this, I've found this to get all of a products attributes, however I still don't know of a simple way of showing on certain values on a grouped product table?



$attributes = Mage::getModel('catalog/product_attribute_api')->items($_product->getAttributeSetId());
foreach($attributes as $_attribute)
print_r($_attribute);










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

    – BlueC
    May 26 '16 at 20:26

















6















I'm working on building a new Magento shop (this is my first with Magento).



I'm looking to replicate the look of an existing shop for my product pages, at least in terms of layout:



http://www.panamericantool.com/cobalt-drills/drill-stops.html



http://www.panamericantool.com/screw-driver-bits/paint-cutters.html



I've figured out that I need to use grouped products, with simple products to create the kind of thing I'm after.



In the examples above, each product has separate attributes, I assume these are done via different attribute sets in Magento.



However how do they go displaying those different table headings/values in the theme?



I know I can do ->getAttributeName() or ->getAttribute('attribute_code') in the grouped.phtml file, but this would result in a vast amount of if (->getAttributeName() != '')... and I'd need to change the template when adding more.



I'm sure there is a way of getting all attributes and looping over them, but then how would you differentiate between say the meta_description attribute (also returned by the $_product->getData() method) and an attribute I'd want listed in the table?



How could I achieve something akin to what they have?



I'm also concerned about performance the shop will have 5k products at launch, growing to perhaps 25k-30k as we add our remaining stock. Many of these will need different attributes, but I'm guessing I could share attributes between attribute sets without too many performance issues?




Update:



I've carried on playing around with this, I've found this to get all of a products attributes, however I still don't know of a simple way of showing on certain values on a grouped product table?



$attributes = Mage::getModel('catalog/product_attribute_api')->items($_product->getAttributeSetId());
foreach($attributes as $_attribute)
print_r($_attribute);










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

    – BlueC
    May 26 '16 at 20:26













6












6








6


1






I'm working on building a new Magento shop (this is my first with Magento).



I'm looking to replicate the look of an existing shop for my product pages, at least in terms of layout:



http://www.panamericantool.com/cobalt-drills/drill-stops.html



http://www.panamericantool.com/screw-driver-bits/paint-cutters.html



I've figured out that I need to use grouped products, with simple products to create the kind of thing I'm after.



In the examples above, each product has separate attributes, I assume these are done via different attribute sets in Magento.



However how do they go displaying those different table headings/values in the theme?



I know I can do ->getAttributeName() or ->getAttribute('attribute_code') in the grouped.phtml file, but this would result in a vast amount of if (->getAttributeName() != '')... and I'd need to change the template when adding more.



I'm sure there is a way of getting all attributes and looping over them, but then how would you differentiate between say the meta_description attribute (also returned by the $_product->getData() method) and an attribute I'd want listed in the table?



How could I achieve something akin to what they have?



I'm also concerned about performance the shop will have 5k products at launch, growing to perhaps 25k-30k as we add our remaining stock. Many of these will need different attributes, but I'm guessing I could share attributes between attribute sets without too many performance issues?




Update:



I've carried on playing around with this, I've found this to get all of a products attributes, however I still don't know of a simple way of showing on certain values on a grouped product table?



$attributes = Mage::getModel('catalog/product_attribute_api')->items($_product->getAttributeSetId());
foreach($attributes as $_attribute)
print_r($_attribute);










share|improve this question
















I'm working on building a new Magento shop (this is my first with Magento).



I'm looking to replicate the look of an existing shop for my product pages, at least in terms of layout:



http://www.panamericantool.com/cobalt-drills/drill-stops.html



http://www.panamericantool.com/screw-driver-bits/paint-cutters.html



I've figured out that I need to use grouped products, with simple products to create the kind of thing I'm after.



In the examples above, each product has separate attributes, I assume these are done via different attribute sets in Magento.



However how do they go displaying those different table headings/values in the theme?



I know I can do ->getAttributeName() or ->getAttribute('attribute_code') in the grouped.phtml file, but this would result in a vast amount of if (->getAttributeName() != '')... and I'd need to change the template when adding more.



I'm sure there is a way of getting all attributes and looping over them, but then how would you differentiate between say the meta_description attribute (also returned by the $_product->getData() method) and an attribute I'd want listed in the table?



How could I achieve something akin to what they have?



I'm also concerned about performance the shop will have 5k products at launch, growing to perhaps 25k-30k as we add our remaining stock. Many of these will need different attributes, but I'm guessing I could share attributes between attribute sets without too many performance issues?




Update:



I've carried on playing around with this, I've found this to get all of a products attributes, however I still don't know of a simple way of showing on certain values on a grouped product table?



$attributes = Mage::getModel('catalog/product_attribute_api')->items($_product->getAttributeSetId());
foreach($attributes as $_attribute)
print_r($_attribute);







magento-1.9 attributes product-attribute grouped-products attribute-set






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:54









Community

1




1










asked Mar 2 '15 at 12:00









Tom GreenTom Green

1336




1336





bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

    – BlueC
    May 26 '16 at 20:26

















  • Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

    – BlueC
    May 26 '16 at 20:26
















Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

– BlueC
May 26 '16 at 20:26





Why not use the "Visible on Product View Page on Front-end" property of the attribute to determine whether to show it on the product page?

– BlueC
May 26 '16 at 20:26










2 Answers
2






active

oldest

votes


















0














This should be what you need:



$product->getResource()->getAttribute('attribute_code')->getStoreLabel();





share|improve this answer























  • But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

    – Tom Green
    Mar 3 '15 at 13:01


















0














Why not create an attribute that tells it what attributes to show?



I ended up creating a module that loads the value of two text attributes for grouped products that are attribute code strings. Essentially a helper that Explodes that attribute list string and loops over it to load the associated products attribute data.



Create an attribute I called mine:



grouped_attr_array



Add the attribute to the grouped product's design attribute set in the admin and then them as a semicolon separated field in the product data



torque_range;torque_increments;torque_accuracy



I pulled this code from my module. It's doing some more loading or hiding of default attributes based on a an attribute value and the module is a little more complex. But to get the data shown in the table these are some of the core functions. Hopefully it gives you an idea to build on. This is using magento 1.9.2



The Module's Helper:



public function findAttributes($product, $attributes)

//determined by attribute with id to add additional attributes to the table
//string needs to be ; separated in ADMIN
$strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
if ($strattributes)
$strattributes = explode(';', $strattributes, 5);
foreach ($strattributes as $additionAttribute)
//make sure these are valid attributes
if ($product->getResource()->getAttribute($additionAttribute))
array_push($attributes, $additionAttribute);





public function groupedAttrDump($groupedProduct, $attributes)

$cells = [];
foreach ($attributes as $attrCode)
$attrText = $groupedProduct->getResource()->getAttribute($attrCode);
if($attrText)
array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));


return $cells;


public function groupedAttrHeaders($currentProduct, $attributes)

$theads = [];
foreach ($attributes as $attrCode)
$headerText = $currentProduct->getResource()->getAttribute($attrCode);
if($headerText)
$headerText = $headerText->getStoreLabel();
array_push($theads,$headerText);



return $theads;



Getting Data from helper in groupedproduct.phtml



$attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
$tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);


TH's



 <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
<th><?php echo $attrLabel ?> </th>
<?php endforeach; ?>


TD's the table



<?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
<td><?php if($attr != 'No') echo $attr; ?></td>
<?php endforeach; ?>


I'd like to build out the way of choosing that attribute based on the store's available attributes. Maybe there'a much better way to do this too. Haven't gotten to that yet.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f59241%2fhandling-grouped-product-attributes%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This should be what you need:



    $product->getResource()->getAttribute('attribute_code')->getStoreLabel();





    share|improve this answer























    • But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

      – Tom Green
      Mar 3 '15 at 13:01















    0














    This should be what you need:



    $product->getResource()->getAttribute('attribute_code')->getStoreLabel();





    share|improve this answer























    • But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

      – Tom Green
      Mar 3 '15 at 13:01













    0












    0








    0







    This should be what you need:



    $product->getResource()->getAttribute('attribute_code')->getStoreLabel();





    share|improve this answer













    This should be what you need:



    $product->getResource()->getAttribute('attribute_code')->getStoreLabel();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 2 '15 at 19:35









    benmarksbenmarks

    15.3k436105




    15.3k436105












    • But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

      – Tom Green
      Mar 3 '15 at 13:01

















    • But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

      – Tom Green
      Mar 3 '15 at 13:01
















    But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

    – Tom Green
    Mar 3 '15 at 13:01





    But this would just get a single attribute, I need a way of showing different attributes for different products - as per the links I included in the OP?

    – Tom Green
    Mar 3 '15 at 13:01













    0














    Why not create an attribute that tells it what attributes to show?



    I ended up creating a module that loads the value of two text attributes for grouped products that are attribute code strings. Essentially a helper that Explodes that attribute list string and loops over it to load the associated products attribute data.



    Create an attribute I called mine:



    grouped_attr_array



    Add the attribute to the grouped product's design attribute set in the admin and then them as a semicolon separated field in the product data



    torque_range;torque_increments;torque_accuracy



    I pulled this code from my module. It's doing some more loading or hiding of default attributes based on a an attribute value and the module is a little more complex. But to get the data shown in the table these are some of the core functions. Hopefully it gives you an idea to build on. This is using magento 1.9.2



    The Module's Helper:



    public function findAttributes($product, $attributes)

    //determined by attribute with id to add additional attributes to the table
    //string needs to be ; separated in ADMIN
    $strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
    if ($strattributes)
    $strattributes = explode(';', $strattributes, 5);
    foreach ($strattributes as $additionAttribute)
    //make sure these are valid attributes
    if ($product->getResource()->getAttribute($additionAttribute))
    array_push($attributes, $additionAttribute);





    public function groupedAttrDump($groupedProduct, $attributes)

    $cells = [];
    foreach ($attributes as $attrCode)
    $attrText = $groupedProduct->getResource()->getAttribute($attrCode);
    if($attrText)
    array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));


    return $cells;


    public function groupedAttrHeaders($currentProduct, $attributes)

    $theads = [];
    foreach ($attributes as $attrCode)
    $headerText = $currentProduct->getResource()->getAttribute($attrCode);
    if($headerText)
    $headerText = $headerText->getStoreLabel();
    array_push($theads,$headerText);



    return $theads;



    Getting Data from helper in groupedproduct.phtml



    $attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
    $tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);


    TH's



     <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
    <th><?php echo $attrLabel ?> </th>
    <?php endforeach; ?>


    TD's the table



    <?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
    <td><?php if($attr != 'No') echo $attr; ?></td>
    <?php endforeach; ?>


    I'd like to build out the way of choosing that attribute based on the store's available attributes. Maybe there'a much better way to do this too. Haven't gotten to that yet.






    share|improve this answer



























      0














      Why not create an attribute that tells it what attributes to show?



      I ended up creating a module that loads the value of two text attributes for grouped products that are attribute code strings. Essentially a helper that Explodes that attribute list string and loops over it to load the associated products attribute data.



      Create an attribute I called mine:



      grouped_attr_array



      Add the attribute to the grouped product's design attribute set in the admin and then them as a semicolon separated field in the product data



      torque_range;torque_increments;torque_accuracy



      I pulled this code from my module. It's doing some more loading or hiding of default attributes based on a an attribute value and the module is a little more complex. But to get the data shown in the table these are some of the core functions. Hopefully it gives you an idea to build on. This is using magento 1.9.2



      The Module's Helper:



      public function findAttributes($product, $attributes)

      //determined by attribute with id to add additional attributes to the table
      //string needs to be ; separated in ADMIN
      $strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
      if ($strattributes)
      $strattributes = explode(';', $strattributes, 5);
      foreach ($strattributes as $additionAttribute)
      //make sure these are valid attributes
      if ($product->getResource()->getAttribute($additionAttribute))
      array_push($attributes, $additionAttribute);





      public function groupedAttrDump($groupedProduct, $attributes)

      $cells = [];
      foreach ($attributes as $attrCode)
      $attrText = $groupedProduct->getResource()->getAttribute($attrCode);
      if($attrText)
      array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));


      return $cells;


      public function groupedAttrHeaders($currentProduct, $attributes)

      $theads = [];
      foreach ($attributes as $attrCode)
      $headerText = $currentProduct->getResource()->getAttribute($attrCode);
      if($headerText)
      $headerText = $headerText->getStoreLabel();
      array_push($theads,$headerText);



      return $theads;



      Getting Data from helper in groupedproduct.phtml



      $attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
      $tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);


      TH's



       <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
      <th><?php echo $attrLabel ?> </th>
      <?php endforeach; ?>


      TD's the table



      <?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
      <td><?php if($attr != 'No') echo $attr; ?></td>
      <?php endforeach; ?>


      I'd like to build out the way of choosing that attribute based on the store's available attributes. Maybe there'a much better way to do this too. Haven't gotten to that yet.






      share|improve this answer

























        0












        0








        0







        Why not create an attribute that tells it what attributes to show?



        I ended up creating a module that loads the value of two text attributes for grouped products that are attribute code strings. Essentially a helper that Explodes that attribute list string and loops over it to load the associated products attribute data.



        Create an attribute I called mine:



        grouped_attr_array



        Add the attribute to the grouped product's design attribute set in the admin and then them as a semicolon separated field in the product data



        torque_range;torque_increments;torque_accuracy



        I pulled this code from my module. It's doing some more loading or hiding of default attributes based on a an attribute value and the module is a little more complex. But to get the data shown in the table these are some of the core functions. Hopefully it gives you an idea to build on. This is using magento 1.9.2



        The Module's Helper:



        public function findAttributes($product, $attributes)

        //determined by attribute with id to add additional attributes to the table
        //string needs to be ; separated in ADMIN
        $strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
        if ($strattributes)
        $strattributes = explode(';', $strattributes, 5);
        foreach ($strattributes as $additionAttribute)
        //make sure these are valid attributes
        if ($product->getResource()->getAttribute($additionAttribute))
        array_push($attributes, $additionAttribute);





        public function groupedAttrDump($groupedProduct, $attributes)

        $cells = [];
        foreach ($attributes as $attrCode)
        $attrText = $groupedProduct->getResource()->getAttribute($attrCode);
        if($attrText)
        array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));


        return $cells;


        public function groupedAttrHeaders($currentProduct, $attributes)

        $theads = [];
        foreach ($attributes as $attrCode)
        $headerText = $currentProduct->getResource()->getAttribute($attrCode);
        if($headerText)
        $headerText = $headerText->getStoreLabel();
        array_push($theads,$headerText);



        return $theads;



        Getting Data from helper in groupedproduct.phtml



        $attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
        $tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);


        TH's



         <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
        <th><?php echo $attrLabel ?> </th>
        <?php endforeach; ?>


        TD's the table



        <?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
        <td><?php if($attr != 'No') echo $attr; ?></td>
        <?php endforeach; ?>


        I'd like to build out the way of choosing that attribute based on the store's available attributes. Maybe there'a much better way to do this too. Haven't gotten to that yet.






        share|improve this answer













        Why not create an attribute that tells it what attributes to show?



        I ended up creating a module that loads the value of two text attributes for grouped products that are attribute code strings. Essentially a helper that Explodes that attribute list string and loops over it to load the associated products attribute data.



        Create an attribute I called mine:



        grouped_attr_array



        Add the attribute to the grouped product's design attribute set in the admin and then them as a semicolon separated field in the product data



        torque_range;torque_increments;torque_accuracy



        I pulled this code from my module. It's doing some more loading or hiding of default attributes based on a an attribute value and the module is a little more complex. But to get the data shown in the table these are some of the core functions. Hopefully it gives you an idea to build on. This is using magento 1.9.2



        The Module's Helper:



        public function findAttributes($product, $attributes)

        //determined by attribute with id to add additional attributes to the table
        //string needs to be ; separated in ADMIN
        $strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
        if ($strattributes)
        $strattributes = explode(';', $strattributes, 5);
        foreach ($strattributes as $additionAttribute)
        //make sure these are valid attributes
        if ($product->getResource()->getAttribute($additionAttribute))
        array_push($attributes, $additionAttribute);





        public function groupedAttrDump($groupedProduct, $attributes)

        $cells = [];
        foreach ($attributes as $attrCode)
        $attrText = $groupedProduct->getResource()->getAttribute($attrCode);
        if($attrText)
        array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));


        return $cells;


        public function groupedAttrHeaders($currentProduct, $attributes)

        $theads = [];
        foreach ($attributes as $attrCode)
        $headerText = $currentProduct->getResource()->getAttribute($attrCode);
        if($headerText)
        $headerText = $headerText->getStoreLabel();
        array_push($theads,$headerText);



        return $theads;



        Getting Data from helper in groupedproduct.phtml



        $attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
        $tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);


        TH's



         <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
        <th><?php echo $attrLabel ?> </th>
        <?php endforeach; ?>


        TD's the table



        <?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
        <td><?php if($attr != 'No') echo $attr; ?></td>
        <?php endforeach; ?>


        I'd like to build out the way of choosing that attribute based on the store's available attributes. Maybe there'a much better way to do this too. Haven't gotten to that yet.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 26 '16 at 20:20









        asherrardasherrard

        1666




        1666



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f59241%2fhandling-grouped-product-attributes%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2