Display Tiered Pricing on the Cart page - magento

If Im on this page:
http:///checkout/cart/
With products in my cart I would like to display the tiered pricing, the same that is shown on the item page, if available.
My attempt was add
<checkout_cart_index>
<block type="catalog/product_view" name="product.tierprices" as="tierprices" template="catalog/product/view/tierprices.phtml"/>
</checkout_cart_index>
to my xml file and add
<?php echo $this->getChildHtml('tierprices') ?>
to
\app\design\frontend\enterprise\<mytemplate>\template\checkout\cart\item\default.phtml
Doesn’t do anything - any further suggestions?

It seems impossible to easily change layout. You need to modify item renderer and add tier price displaying manually. To fetch list of available tier prices you need to get price model. You can get it from product model
$product->getPriceModel()
or if don't have product model try the following code
Mage::getSingleton('catalog/product_type')->priceFactory($productTypeId)
Quote item contains product type information.
When you have price model just call method getTierPrice() to get all tier prices as array.
$priceModel->getTierPrice()

You could edit the .phtml file and adding the $this->getTierPrices($_product);//or$this->getTierPrices($_item); if you simply want to display the tier prices of products.
Do note that the getTierPrices() only works when being on the product list or product view page, so you would need to copy the getTierPrices() method that can be found inside the List.php to your custom module.

This should give you an idea what needs to be done.
layout file
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_cart_index>
<reference name="additional.product.info">
<block type="LokeyCoding_Cart/TierPrice" name="additional.product.info.tierprice" />
</reference>
</checkout_cart_index>
</version>
block file
<?php
class LokeyCoding_Cart_Block_TierPrice extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$parent = $this->getParentBlock();
if ($parent) {
$item = $parent->getItem();
if ($item instanceof Mage_Sales_Model_Quote_Item) {
return $item->getProduct()->getTierPriceHtml();
}
}
return '';
}
}

Related

Magento - Set Category meta title, keywords and description

I have a category for shoes on my website. The meta title,description and keywords that I give under Catalog/Category for that category are not reflected. This is not specific to a category , I'm just quoting shoes as an example.
I dont want to use settitle,setkeyword,setdescription on layout files to set the above. Why is the default magento functionality not working.
It'd be great help if you could point out the area where the default values are applied.
For category layouts in the default magento theme, the area where the meta tags are set is :
//file: app/code/core/Mage/Catalog/Block/Category/view.php
//class: Mage_Catalog_Block_Category_View
//function: protected function _prepareLayout()
//...
$category = $this->getCurrentCategory();
if ($title = $category->getMetaTitle()) {
$headBlock->setTitle($title);
}
if ($description = $category->getMetaDescription()) {
$headBlock->setDescription($description);
}
if ($keywords = $category->getMetaKeywords()) {
$headBlock->setKeywords($keywords);
}
//...
So I think the questions to ask yourself are why is $category->getMetaTitle() falsey or what, later on in the layout, is overwriting $category->getMetaTitle() or does my theme rewrite the function Mage_Catalog_Block_Category_View::_prepareLayout().
You may want to search all your .xml files for code like this:
<reference name="head">
<action method="setTitle" translate="title" module="catalog"><title>Site Map</title></action>
</reference>
Because any module can change the meta tags using XML.

Prevent Magento from caching query strings, such as limit param

The behavior
I what to display only 3 products per page. So in my catalog.xml I have
<action method="setDefaultGridPerPage"><limit>3</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>3</limit></action>
If I go to /category.html I will see only 3 products. It works, great!
But also I want to be able to show all products at once, so I add to the catalog.xml the following:
<action method="addPagerLimit"><mode>grid</mode><limit>999</limit></action>
Now, if I navigate to /category.html?limit=999 I can see all the categories products, as expected.
The problem:
When I come back to /category.html, with no limit params, it displays all the products instead of the 3 I wish it did. It happends because Magento caches the limit preference.
The question:
Is there a configuration that prevents magento from caching listing options?
Thank you in advance.
In the toolbar block there is a method called disableParamsMemorizing. This should disable the storing of parameters in session.
Try to add this in the toolbar block.
<action method="disableParamsMemorizing" />
or you can override the Mage_Catalog_Block_Product_List class and make the getToolbarBlock method look like this:
public function getToolbarBlock()
{
if ($blockName = $this->getToolbarBlockName()) {
if ($block = $this->getLayout()->getBlock($blockName)) {
$block->disableParamsMemorizing();
return $block;
}
}
$block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
$block->disableParamsMemorizing();
return $block;
}

Set custom page title on home in magento

I am showing only a single product on home page. I want to show the product name in page title. How can I do this?
You have multiple ways of doing this:
In your module's layout xml file (located at app/design/frontend/[package]/[theme]/layout/{your_file_name}.xml):
<reference name="head">
<action method="setTitle"><title>Title text here</title></action>
</reference>
The bad thing here is that you can't set tittle "on the fly".
In your block file (_prepareLayout() method is a good place):
public function _prepareLayout()
{
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->setTitle('Title text here');
return parent::_prepareLayout();
}
Anywhere else:
Mage::app()->getLayout()->getBlock('head')->setTitle('Title text here');
Useful link - Layouts, Blocks and Templates

How can I have the cart sidebar only show up when it's in checkout?

I have modified the layout for checkout so the one-page checkout has a right-hand column and has the sidebar cart in it:
<checkout_onepage_index translate="label">
<label>One Page Checkout</label>
<!-- Mage_Checkout -->
<remove name="left"/>
<update handle="page_two_columns_right" />
<reference name="right">
<block type="checkout/cart_sidebar" name="checkout_cart_sidebar" template="checkout/cart/sidebar.phtml"/>
</reference>
<reference name="root">…snip
I would like the sidebar to appear in the checkout even if it's disabled in other pages via the admin. Basically I just need a boolean value to insert in my overridden sidebar.phtml:
<?php if ($_someBooleanValue || $this->getIsNeedToDisplaySideBar()):?>
What's the best way to set the value of $_someBooleanValue to true when the block is within the checkout process, and false otherwise?
I was able to solve this. What I really needed was getNameInLayout() from Mage_Core_Block_Abstract. Since I control the layout xml I'm dealing with, I know what the name will be (*checkout_cart_sidebar* in this case), so I just needed to check if that was the name of the current block.
<?php if ($this->getNameInLayout() === 'checkout_cart_sidebar'
|| $this->getIsNeedToDisplaySideBar()):?>…snip
The best way is to use the local.xml file in the /app/design/frontend/yourtheme/yourskin/layout folder. You can target specific pages to add/remove blocks from to override the base definitions.
Here's a good primer on the power of the local.xml file:
http://magebase.com/magento-tutorials/5-useful-tricks-for-your-magento-local-xml/
You could get the page name and if the page name equals the page you want it to show up on then show the sidebar.
<?php
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page = $parts[count($parts) - 1];
if($page == "checkoutpage.php")
{
$_someBooleanValue = true;
}
?>
You could check if "checkout" is in the page name also.
<?php
$position = strpos($page, "checkout");
if($position == true){$_someBooleanValue = true;};
?>
However this is just a suggestion, but it may not be the best solution.

use case for getProductAdditionalInformationBlock in magento

I'd like to put some additional info under each item in the cart. I have this info already saved in table "sales_flat_quote_item" in "additional_info" field. So the question is only how to show it globally at all places where the items are shown.
I saw in several places under item name there is a structure like this:
<?php if ($addtInfoBlock = $this->getProductAdditionalInformationBlock()):?>
<?php echo $addtInfoBlock->setItem($_item)->toHtml() ?>
<?php endif;?>
For example in this files:
/app/design/frontend/base/default/template/checkout/cart/item/default.phtml
/app/design/frontend/base/default/template/checkout/onepage/review/item.phtml
So I suppose this is the place I should use for such task.
What I figured out is that:
I have to add my own block definition to for example:
<checkout_cart_index>
<block type="core/text_list" name="additional.product.info" translate="label">
<label>Additional Product Info</label>
<block type="various/itemrendererdefault" name="glass.additional" as="glass" template="checkout/cart/glass_additional.phtml"/>
</block>
</checkout_cart_index>
This is no problem so far. My class is loaded
class Site1_Various_Block_Itemrendererdefault extends Mage_Core_Block_Template {
public function setItem(Varien_Object $item) {
$this->setData('item', $item);
return $this;
}
public function getItem() {
return $this->_getData('item');
}
}
and the template checkout/cart/glass_additional.phtml is called.
But inside the template I have no idea how to get the info about what $item should I process. I tried:
$_item = $this->getItem();
print_r($_item);
$_item = $this->getData();
print_r($_item);
but it returns nothing.
So my question is: How to get $item data inside my template.
Can I access the data set in?
...
$addtInfoBlock->setItem($_item)->toHtml();
...
Krystian, the OP, already self-answered his question.
Quote:
I just solved the issue by setting my block as "additional.product.info"
<checkout_cart_index>
<block type="various/itemrendererdefault" name="additional.product.info" translate="label" template="checkout/cart/glass_additional.phtml"></block>
</checkout_cart_index>
Note: It's absolutely OK to self-answer your own question. Please just post it as an real answer, but not in a question or comment. Posting as real answer helps to keep the "Unanswered" list more clear (avoids making other people wasting their time).
I think to get the item instance you have to try this:
class Site1_Various_Block_Itemrendererdefault extends Mage_Core_Block_Template {
public function setItem(Varien_Object $item) {
$this->setData('item', $item);
return $this;
}
public function getItem() {
$parent = $this->getParentBlock();
if ($parent) {
$item = $parent->getItem();
}
}
}
Thanks !
I was having issues with this as well until I used a block type of core/template and a call to getParentBlock() in my custom template file. This might work for any custom block type but I didn't test.
In your layout/local.xml file:
<checkout_cart_index>
<reference name="additional.product.info">
<block type="core/template" name="additional.product.info.your_template" as="your_template" template="checkout/cart/item/your-template.phtml"/>
</reference>
</checkout_cart_index>
The $addtInfoBlock->setItem($_item)is called on the additional.product.info block, which would be the parent of any blocks you add underneath it. Because of this, you can call $this->getParentBlock() in your template to get access to it's data.
So now, in your checkout/cart/item/your-template.phtml:
$_item = $this->getParentBlock()->getItem();
/* get access to all product attributes, with a performance hit. */
$_product = $_item->getProduct()->load();
/* Some product attributes */
echo $_product->getName();
echo $_product->getSku();

Resources