0

I'm trying to add a new function to the \Magento\GroupedProduct\Model\Product\Type\Grouped class

in \USR\GroupedByCore\etc\di.xml I have

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">  

    <preference for="\Magento\GroupedProduct\Model\Product\Type\Grouped"
            type="\USR\GroupedByCore\Model\Product\Type\Grouped" />
</config>

in \USR\GroupedByCore\Model\Product\Type\Grouped.php

<?php 
namespace USR\GroupedByCore\Model\Product\Type;

class Grouped extends \Magento\GroupedProduct\Model\Product\Type\Grouped    
{   

    public function getAssociatedProductsByCore($product,$core)
    {

        return "Something";
    }

 }
?>

I'm calling it this way in Magento_GroupedProdcut\templates\product\view\type\grouped.p‌​html

<?php echo "This should be something: " . $this->getAssociatedProductsByCore($_product,'6'); ?>

Its not returning anything at all. The results is merely "This should be something:".

  • From where you try to call, write more detail. – Sohel Rana May 19 '17 at 16:29
  • Magento_GroupedProdcut\templates\product\view\type\grouped.phtml – sharmstr May 19 '17 at 16:57
0

Figured it out. I needed to call it like this:

$this->getProduct()->getTypeInstance()->getAssociatedProductsByCore($_product, 6); 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.