0

I'm operating multiple websites(storeviews) and i want to bring all simple products on A website although it doesn't be checked to appear on A website on product-website tab.

There would be only grouped products on A website and then click them, i want to show all of simple products associated with the grouped product even they are not a member of A website.

Literally, I'd like to implement what shows in Magento Admin Page on A website catalog page.

So, I want to modify grouped.phtml file and it needs that a product(grouped product) that this module calls have to call all of associated simple product regardless of checking this website or not. Is there a way to implement this ? Please share your opinion.

app/design/frontend/base/default/template/catalog/product/view/type/Grouped.phtml

<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php if ($this->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable() && $_hasAssociatedProducts): ?>
    <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
    <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

EDIT

/wh-clone/app/code/local/Kbethos/AllProducts/Block/Product/View/Type/Grouped.php

<?php
class Kbethos_AllProducts_Block_Product_View_Type_Grouped extends Mage_Catalog_Block_Product_Abstract
{
    /**
     * Revert getProduct functionality to parent:parent
     * 
     * @see Mage_Catalog_Block_Product_Abstract
     * @return null|Mage_Catalog_Model_Product
     */
    /*
    public function getProduct()
    {
    if (!$this->hasData('product')) {
        $this->setData('product', Mage::registry('product'));
    }

    return $this->getData('product');
    }
    */

}

app/code/local/Kbethos/AllProducts/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Kbethos_AllProducts>
      <version>0.1.0</version>
    </Kbethos_AllProducts>
  </modules>
  <global>
    <blocks>
        <allproducts>
            <class>Kbethos_AllProducts_Block</class>
        </allproducts>  
    </blocks>
    <helpers>
      <allproducts>
        <class>Kbethos_AllProducts_Helper</class>
      </allproducts>
    </helpers>
  </global>
</config>  

app/design/frontend/default/modern/layout/catalog.xml

<!-- 20170608 mj edit - add new block for grouped -->
<PRODUCT_TYPE_grouped translate="label" module="catalog">
    <label>Catalog Product View (Grouped)</label>
    <reference name="product.info">
        <block type="kbethos/allproducts_block" name="product.info.grouped" as="product_type_data" template="catalog/product/view/type/grouped.phtml">
            <block type="core/text_list" name="product.info.grouped.extra" as="product_type_data_extra" translate="label">
                <label>Product Extra Info</label>
            </block>
        </block>
    </reference>
</PRODUCT_TYPE_grouped> 
 <!-- 20170608 mj edit - add new block for grouped -->
0

Method 1

If you take a look at Mage_Catalog_Block_Product_View_Abstract::getProduct (/app/code/core/Mage/Catalog/Block/Product/View/Abstract.php) you can see that the block retrieves the product with a store filter applied to it.

You will need to create a custom module that overrides this function, calling the product without the store filter.

Take a look at http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/ for information regarding how to override blocks (and other classes).

To get you started /app/code/local/MyModule/Grouped/etc/config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <MyModule_Grouped>
            <version>0.1.0</version>
        </MyModule_Grouped>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_view_type_grouped>MyModule_Grouped_Block_Rewrite_Product_View_Type_Grouped</product_view_type_grouped>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

/app/code/local/MyModule/Grouped/Block/Rewrite/Product/View/Type/Grouped.php

class MyModule_Grouped_Block_Rewrite_Product_View_Type_Grouped extends Mage_Catalog_Block_Product_View_Type_Grouped
{
    /**
     * Revert getProduct functionality to parent:parent
     * 
     * @see Mage_Catalog_Block_Product_Abstract
     * @return null|Mage_Catalog_Model_Product
     */
    public function getProduct()
    {
        if (!$this->hasData('product')) {
            $this->setData('product', Mage::registry('product'));
        }

        return $this->getData('product');
    }
}

You'll need to flesh out the module a little more, but hopefully that helps. The block override essentially calls the parent class' parent method (reverting to the default getProduct functionality)

This is untested!

A better way of doing this would be to create your own module that does exactly what you want without overwriting anything!

Method 2

Instead of overriding the functionality in the block class you could create a new block that extends Mage_Catalog_Block_Product_Abstract rather than Mage_Catalog_Block_Product_View_Abstract and simply leave the class empty. As you've extended from Mage_Catalog_Block_Product_Abstract the getProduct functionality will not assign a store to a product.

Then update the PRODUCT_TYPE_configurable node block in your themes layout XML to use your new block that doesn't use any of the store assigning functionality. Eg: mymodule/my_new_grouped_block

<PRODUCT_TYPE_grouped translate="label" module="catalog">
    <label>Catalog Product View (Grouped)</label>
    <reference name="product.info">
        <block type="mymodule/my_new_grouped_block" name="product.info.grouped" as="product_type_data" template="catalog/product/view/type/grouped.phtml">
            <block type="core/text_list" name="product.info.grouped.extra" as="product_type_data_extra" translate="label">
                <label>Product Extra Info</label>
            </block>
        </block>
    </reference>
</PRODUCT_TYPE_grouped>
  • Thank you! Btw is there a way to adapt this code(or function) for a specific website? I mean if i modify this core one or overwriting it, it would affects other websites bc we have multiple websites under one magento installation. They are using different themes so i'm looking for how to bring all simple products on design file. – 3CE Jun 7 '17 at 13:56
  • 1
    See my "Method 2" for that sort of functionality. Basically you'd have to create a custom module in the same way but not rewrite a Magento core file, instead create a custom block, then in your theme specific layout XML files you can set which block you want to display on which site. Just so you know, never modify core files! Always create a module that extends/rewrites them! – Daniel Doyle Jun 7 '17 at 14:02
  • Please see my edit codes? – 3CE Jun 8 '17 at 17:32
  • I edit code as i posted. But it doesn't work :/ Please can you have a look my code? – 3CE Jun 8 '17 at 17:47
  • Hey! your idea was so interesting but i modified core code just a moment and recovered it. It doesn't work. I mean even though i changed getProduct() which brings products filtered by stores with getProduct() which brings products from registry, this block i costumed doesn't work! – 3CE Jun 8 '17 at 19:45

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.