Magento: Catalog Page 1 different from other pages - magento

I want to setup the category catalog pages in Magento such that the first page contains the category image and the first three products in that category. Then the following pages contain six products per page without the category image.
I can't figure out how this can be done.

Unfortunately I don't think you can do this without a lot of work. You'll need to rewrite the logic of the pagination, change the page size depending on which page it is, & offset the returned collection.
However you can easily only have the category image displayed on the first page.
This line returns the current page number:
Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
So in template/catalog/category/view.phtml you can just do a conditional around the category image display, find the section:
<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
and replace it with:
<?php if($_imgUrl): ?>
<?php if(Mage::getBlockSingleton('page/html_pager')->getCurrentPage()==1):?>
<?php echo $_imgHtml ?>
<?php endif; ?>
<?php endif; ?>

Related

Magento Retail Store and Wholesale with Different Prices

Hey I was wondering about magento Retail/Wholesale capabilities.
The main store will be for normal customers (retail) and they see normal prices but for wholesalers they need to login and see wholesale prices?
I don't want normal visitors to see wholesale prices.
Is that possible?
Assign product price as customer groups after that use this code on list or view page, you will see product different price on both side same and equal to admin price.
<?php $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($groupId ==1 || $groupId ==""){?>
<?php if($product->getSpecialPrice()){?>
<?php echo "$".$rprice = number_format($product->getPrice(),2); ?> </div>
<?php }else{?>
<?php $product->setCustomerGroupId($groupId);
echo "$".$price = number_format($product->getPriceModel()->getFinalPrice(1, $product),2); ?>
<?php } ?>
</div>
<?php if($product->getSpecialPrice()){ echo "Special Price $".number_format($product->getSpecialPrice(),2);?>
<?php } ?>
<?php }else{echo "$".$price = number_format($product->getPriceModel()->getFinalPrice(1, $product),2); }
?>
for create customer group check this link:
http://www.magentocommerce.com/knowledge-base/entry/customer-groups

what is the difference between the functions getAddUrl and getAddToCartUrl?

I have found two function returning the exactly same value.
getAddUrl in \app\code\local\Mage\Checkout\Helper\Cart.php
getAddToCartUrl in \app\code\local\Mage\Catalog\Block\Product\Abstract.php
what is really the difference between these two?as I am adding an add to cart button in my block.
Which function should I use?
Consider the example below
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_cartUrl=$this->getAddToCartUrl($_product)): ?>
<li><span class="separator">|</span> <?php echo $this->__('Add to Cart') ?></li>
<?php endif; ?>
getAddUrl can fetch you URL of the helper you associate it with, eg: wishlist, compare, etc.
but getAddToCartUrl will only get you the add to cart URL for the product passed to it.
I hope it clarifies things for you
Does your block inherit the Mage_Catalog_Block_Product_Abstract class? If so you should use the getAddToCartUrl method of the block.
Otherwise you should use the helper, there is no neat way of calling a block method without creating the block in this case a product block.
The difference between these two functions is that the getAddToCartUrl (Mage_Catalog_Block_Product_Abstract) will return product view page URL if product has required options.
And getAddUrl (Mage_Checkout_Helper_Cart) will always return url for add product to cart.

Show fatal error when click to product detail page from wishlist page

I am trying to display category name in product detail page. For that I am using
$cat_name=Mage::registry('current_category')->getName();
It shows category name.
But when I went to wishlist page & click to product image then it give error:-
Fatal error: Call to a member function getName() on a non-object in /opt/lampp/htdocs/dominie/app/design/frontend/default/dominie/template/catalog/product/view.phtml.
Please help me how can I solve this issue.
Just tested the code below and it work in v1.7 when added to template/catalog/product/view.phtml.
However Mage::registry('current_category'); is only available if when coming to a product page from a category page (not tested, but may also dependent on if you have seo url that contain the category names within the url)
<?php
$_helper = $this->helper('catalog/output');
$_category_detail=Mage::registry('current_category');
echo $_category_detail->getName(); //gives current category name
echo $_category_detail->getId(); //gives current category id
?>
See http://vinayp.com.np/how-to-get-category-name-and-id-on-product-page-on-magento/
To display all the categories that a product belong to do
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<?php echo $_category->getName() ?>
<?php endforeach; ?>
See http://www.magentocommerce.com/boards/viewthread/27720/
Try to define $cat_name in your wishlist module so that collection from wishlist module will also contain category name from which it was added to wishlist. This will surely reduce your overhead.

How to show the original price in the shopping cart in Magento

I'm having problems trying to show the original unit price in the shopping cart in Magento. By default Magento only shows the special price but I would like to also show the original price to highlight the savings.
I know which template needs changing which is /template/checkout/cart/item/default.phtml.
On line 145 it shows
<?php
echo $this->helper('checkout')->
formatPrice($_incl-$_item->getWeeeTaxDisposition())
?>
which displays the special price. I just don't know the syntax to display the original price.
see below for an alternative method,
i'm not sure if $_item->getPrice has access to the non special price, so jumped it over to product
<?php echo $_item->getProduct()->getPrice(); ?>
within
<?php foreach($this->getItems() as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
// insert it here
<?php endforeach ?>

Display categories on home page in Magento

I am a newbie in Magento and wanted to display all categories on the Magento home page rather than a top nav menu.
I read a lot of articles on it, but nothing has helped. Please point me to the right direction.
Thanks in advance.
The code below does a couple of things, first it will get all the store’s categories - it then checks to see if they are active before continuing.
Code Courtesy : magentocommerce forum
<?php
/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();
/* Get the current category the user is in */
$_current_category=$this->getCurrentCategory();
/* Get the current category path */
$_categorypath = $this->getCurrentCategoryPath();
?>
<ul>
<?php
if ($_main_categories):
/* This bit cycles through the categories - setting the next one to current */
foreach ($_main_categories as $_main_category):
if($_main_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
/* Write the main categories */
?>
<li><?php echo $this->getCurrentCategory()->getName();?></li>
<?php
/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>
<ul>
<? foreach ($_categories as $_category):?>
<? if($_category->getIsActive()):
$cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_subcategory);
?>
<li> <?php echo $_category->getName()?></li>
<? endif;?>
<?endforeach?>
</ul>
<?php /* This resets the category back to the original pages category
**** If this is not done, subsequent calls on the same page will use the last category
**** in the foreach loop
*/ ?>
<?php $layer->setCurrentCategory($_current_category); ?>
<?endif;?>
<?endif;?>
<?php
endif;
endforeach;
else:
?>
<p>$_main_categories array was empty.</p>
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
<?php endif; ?>
I got where the problem was.
The solution is at this link http://samsami2u.wordpress.com/2009/09/15/add-categories-with-images-on-homepage-magento/ and I was trying to add this line
{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}} to home page from back end in layout update xml under design tab but the correct way was to place it in content tab.

Resources