1

I need to have two product view pages. One for local products and another one for international prducts. I have customized the default product view page for local produts. I have a link for international product in this product view page. Then I have created a module called 'international' for internatioal products and so when the links clicked, it will display my custom module.

Now I want to add some default funtionalities of default product view page in my custom module. I tried to add addtocart block, however it seems to be not working

This is my international.xml file..which is at /app/design/frontend/default/my_theme/layout

<layout version="0.1.0">
    <international_index_index>
        <reference name="root">
            <action method="setTemplate">
                <template>page/1column.phtml</template>
            </action>
        </reference>
        <reference name="head">
            <action method="addItem">
                <type>skin_css</type>
                <item>css/international.css</item>
            </action>
            <action method="addItem">
                <type>skin_js</type>
                <item>js/international.js</item>
            </action>
        </reference>
        <reference name="content">
            <block type="international/international" name="international"  
             template="catalog/product/international.phtml">
 <!--adding dropdown section -->
                 <block type="core/template" name="dropdown" as="dropdown" 
                 template="catalog/product/dropdown.phtml"/>
 <!--adding common package static block section -->
                 <block type="cms/block" name="common-packages">
                     <action method="setBlockId">
                      <block_id>common-packages</block_id>
                    </action>
                </block>
 <!-- adding addtocart part -->                
                <block type="catalog/product_view" name="product.info.addto" 
                as="addto" template="catalog/product/view/addto.phtml"/>
                <block type="catalog/product_view"  
                name="product.info.addtocart" as="addtocart"  
                template="catalog/product/view/addtocart.phtml"/>

            </block>
        </reference>
    </international_index_index>
</layout> 

now my international.phtml file which is at /app/design/frontend/default/my_theme/template/catalog/product

<?php
 /*
      'getInternationalPlans()' function is used to get our international product 
       according to the user input
  */

      $_product=$this>getInternationalPlans($custom_select_business);                                  
      foreach ( $_product as $product )
      {

       $plan_array [] = $product->getId ();
      }
     /*it unregisters the product  */
      Mage::unregister ( 'product' );
     /*  loading the current product  */
     $_product=Mage::getModel('catalog/product')->load($plan_array[0])
 ?>
  <div> <?php echo $this->getChildHtml('addtocart');   ?></div>

My block definiton is as follows..

 <?php
        class Freefilings_International_Block_International extends  
        Mage_Core_Block_Template
        {
            public function _prepareLayout()
            {
                return parent::_prepareLayout();
            }    
        /*
           returns international product object by filering by bundle type, 
           international country span and business type selected
        */
        public function getInternationalPlans($custom_select_business)
        {
             $products = Mage::getModel ( 'catalog/product' )->getCollection ()
                         ->addAttributeToSelect ( '*' )
                ->addAttributeToFilter( 'business_type', array ('eq' =>      
                          Mage::getResourceModel ( 'catalog/product' )
                   ->getAttribute ( 'business_type' )->getSource ()
                           ->getOptionId ( $custom_select_business ) ) )
                ->addAttributeToFilter( 'country_span', array ('eq' =>    
                            Mage::getResourceModel ( 'catalog/product' )
                   ->getAttribute ( 'country_span' )->getSource ()
                           ->getOptionId ( 'international' ) ) )
                ->addFieldToFilter ( 'type_id', array ('eq' => 'bundle' ) )
                ->load ();       
            return $products;       
       }
}

I Optained the product from the block. However I dont know, how to add default product view page functionalities into my module. Just like this addtocart functionality. How can I convert my custom module into another product view page. Thanks..

2
  • Why not just use a product attribute, and filter by it? Having a whole module and seperate code seems overkill.
    – ProxiBlue
    Commented Dec 10, 2013 at 10:48
  • i have filtered out the product using country_span attribute. i am getting the product correctly. but as like default product view page. i need to display the options, add to cart functionality, price change functionalities when the options of product is selected(i have only bundle products) etc. to add these features as like product view page, what should i do? Commented Dec 10, 2013 at 10:54

2 Answers 2

1

Could you have a different attribute set for the two different product types ( local and international ) Then introduce a custom layout handle so that via XML you can have different templates and introduce your custom block logic into the page that way.

<PRODUCT_ATTRIBUTE_SET_local>
<reference name="product.info">
  <action method="setTemplate"><template>my/custom/product/view.phtml</template></action>
</reference>
</PRODUCT_ATTRIBUTE_SET_local>

Inside this handle you can add a reference to your block that does the custom logic. This way you retain all the product view functionality and are only adding in custom work.

I would recommend looking at: http://magebase.com/magento-tutorials/creating-custom-layout-handles/

1
  • Yes. It is a good approach that i can adopt. However it would help me, if you answered this question little earlier Commented Nov 9, 2014 at 12:56
0

I have solved this problem very easily by Magento's layout power.

For each product magento will generate unique layout handle. Suppose my international product id be 15. Then magento will process <PRODUCT_15> layout handle when we view that product. Since this layout handle is processed after <catalog_product_view>, every changes that we made via our product's unique layout handle will get effect for sure. This way I made a layout of an international product be unique and hence solved the issue of cart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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