Get create Custom Block in FrontEnd Product page - php

In my magento i want to create a Block in Product Page for this itried like this
Magento- How can i add a new custom block in product details page using module
But no use
Any thing wrong i did here
Any Ideas

Hello check below code may be help you
add into product template (view.phtml) where you want
<?php echo $this->getChildHtml('mynewblock');?>
call block into your custom template xml or catalog.xml
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="mynewblock" template="hello/hello.phtml" />
</reference>
</catalog_product_view>

Related

How to add a block inside order sales view in magento

Sales Order View in Admin panel
This is the layout.xml
<layout>
<adminhtml_sales_order_view>
<reference name="order_tab_info">
<block type="booking/sales_order_view_reservationbooking" name="reservationbooking" template="booking/sales/order/view/reservationbooking.phtml" />
</reference>
</adminhtml_sales_order_view>
This is the block in my module
<?php
class Actino_Booking_Block_Adminhtml_Sales_Order_View_Reservationbooking extends Mage_Core_Block_Template {
}
Here is my explanation about what i want to achieve
In core adminhtml i edited the sales/order/view/info.phtml.. I know that Never edit the core files, but this is only for test for which i want to display my template around the orders view. and then if this works I should have to create or rewrite the info.phtml.
here is my custom reservationbooking.phtml
and in info.phtml i write a code to view this layout
<?php echo $this->getChildHtml('reservationbooking');?>
This is not working. I cant see the text "reservation booking data" in sales order view. without modifying any core files ?
My question is how to add custom field in sales order view ?
Once a try
<adminhtml_sales_order_view>
<reference name="order_info">
<action method="setTemplate">
<template>yourmodule/sales/order/view/reservationbooking.phtml</template>
</action>
</reference>
</adminhtml_sales_order_view>
Create a file in the following
app/design/adminhtml/default/default/template/yourmodule/sales/order/view/reservationbooking.phtml
Now you can add your stuff to the reservationbooking.phtml inside your module, without change the core files

Call custom block on Success Page Magento

I need to call a custom block on success page
I have tried by layout as mention below
<checkout_onepage_success translate="label">
<reference name="content">
<block type="checkout/onepage_success" name="checkout.success" template="checkout/success.phtml" >
<block type="core/template" name="birthday" template="checkout/message/birthday.phtml"/>
</block>
</reference>
</checkout_onepage_success>
In success page
echo $this->getChildHtml('birthday');
I am getting birthday block twice on the page.
Please let me know how we can call custom block on success page.
I don't want to use dynamic block i.e.
echo $this->getLayout()->createBlock('core/template')
->setTemplate('checkout/message/birthday.phtml')->toHtml();
You are getting the birthday block twice because of this line from success.phtml:
<?php echo $this->getChildHtml() ?>
This line renders all child blocks of the main block.
If you want it listed only once remove the line
echo $this->getChildHtml('birthday');
It will be redered by the getChildHtml method anyway.

customize the shopping cart page without affecting the original

I am developing a new custom module in magento. I need to customize the shopping cart page without affecting the original cart.phtml. My module name is Stallioni. I have placed the cart.phtml inside frontend/default/default/template/stallioni/checkout/cart.phtml .How can i use this cart.phtml in my new module instead of the original . I know we should change something in checkout.XML or stallioni/layout/stallioni.xml file. But no idea since i am new.I googled out a day but couldn't find.
http://blog.chapagain.com.np/magento-overriding-template-file-from-custom-module/ this link tells something but it didn't worked for me.I need your help!
If your layout.xml is working add this code in your layout
`<checkout_cart_index>
<reference name="content">
<reference name="checkout.cart">
<action method="setTemplate">
<template>default/default/template/stallioni/checkout/cart.phtml</template>
</action>
</reference>
</reference>
</checkout_cart_index>`
It should work :)

Magento: Related products on order success

Desired result:
On the order success page I want to show products that are related to the ones purchased by the user.
What I did so far:
product attribute that contains related products
added echo $this->getChildHtml('related_products_list'); in checkout/success.phtml
block that extends the product_list, and sets the appropriate collection (note: this is not a rewrite)
class Namespace_CustomersBought_Block_Product_List extends Mage_Catalog_Block_Product_List {
protected function _construct() {
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
// some more code to get the products I need in $relatedProducts
$this->setCollection($relatedProducts);
}
}
added in my custom.xml the following (paths are correct):
<checkout_onepage_success>
<reference name="content">
<block type="namespace_customersbought/product_list" name="related_products_list"
template="module/product/related_list.phtml" after="-">
</block>
</reference>
</checkout_onepage_success>
Where it stopped working
It renders the div I added in checkout/success.phtml, but the getChildHtml() call is empty.
Also, I use Magneto Debug - and the layout update contains my XML.
What I need help with
I would like to understand why this is not working. If I replace <checkout_onepage_success> with <cms_index_index> I get the desired block on the homepage (without having getChildHtml()), so why do they have different behavior?
Also - ideally I wouldn't need to modify the checkout/success.phtml file, it should be output automatically.
I know I'm missing something very simple, but I can't figure out what.
Thank you.
I guess, there is a problem with the line
<reference name="content">
This sets your block a child to the content block. You, however have added the output to the checkout/success.phtml template, which belongs to the block checkout.success. I suggest you replace the xml update with the following
<checkout_onepage_success>
<reference name="checkout.success">
<block type="namespace_customersbought/product_list" name="related_products_list"
template="module/product/related_list.phtml" after="-">
</block>
</reference>
</checkout_onepage_success>

Magento- How can i add a new custom block in product details page using module

I am doing a magento customaization site, I need to add the products addtional attributes like it's type,version etc .I am new to magento , How can i add the new custom block to product details page. I have created a module , and i am using below coding.
app\code\local\SmartGrowth\CompatibleWith\Block\compatible.php
class SmartGrowth_CompatibleWith_Block_CompatibleWith extends Mage_Catalog_Block_Product_View
{
protected function _prepareLayout()
{
//$this->getProduct()->setName($this->getProduct()->getPrice());
$this->getProduct()->setName($this->getProduct()->getShortDescription());
parent::_prepareLayout();
}
}
I have used the below coding in _prepareLayout() but it seem to be repeat the block 5 times and the location of the block appeared is a probs
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => 'catalog/product/compatiblewith.phtml')
);
$this->getLayout()->getBlock('content')->append($block);
Please help how can i do this , I am new to magento , Any help will be appreciated.
There's no need to add the block in code, it should be done using config XML files.
Create an XML config for your module (plenty of tutorials on this).
check catalog.xml (app/design/frontend/base/default/layout/)
<catalog_product_view translate="label">
....
</catalog_product_view>
This is where the blocks are setup for display on the product view page. You can modify this using your own modules XML file, something like this:
<catalog_product_view translate="label">
<reference name="content">
<block type="compatiblewith/compatible" name="my.block" template="compatiblewith/compatible/template.phtml" />
</reference>
</catalog_product_view>
this will show your custom block on the product view page, inside the content area.
You also have an error with the naming of your block if it's called Compatible.php the class should be SmartGrowth_CompatibleWith_Block_Compatible
You can add custom template in product-shop (css class name for the section beside product image) below the Quick View area without modifying core files. in your module's layout file add this code for the required result (do replace "module" "block" with your actual module and block names):
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="module/block" name="module_block" as="other" template="module/block.phtml"/>
</reference>
</reference>
</catalog_product_view>
the target for custom block used is "other" which is a child html provided by default in view.phtml(/app/design/frontend/base/default/template/catalog/product/view.phtml) of magento.
Hopes it'll help.

Categories