Magento set "Show All" products by specific category (or in .phtml) rather than globally - magento

I'm aware of the setting in the admin panel for the default number of products to show on the category list pages. This appears to be a global setting for the whole store. I'm looking for a way to set this on a per category basis (e.g. have most categories default to 25 products per page, but one specific category default to showing all products on the first page). Ideally this would be done in admin or in a .phtml file if possible. How can I set the default products per page for a specific category?

Take a look in
design/package/theme/catalog/product/list/toolbar.phtml
The items per page select drop down is generated by a for loop around:
$this->getAvailableLimit()
The block for the toolbar has the following method on it:
public function getLimitUrl($limit)
{
return $this->getPagerUrl(array(
$this->getLimitVarName() => $limit,
$this->getPageVarName() => null
));
}
The trick is to do one of the two following:
1) leverage magento to build the proper url when it is injected in any link directing to the category you want to be in view all mode.
2) on the /catalog/product/list/toolbar.phtml block check the current category, if the current category is the desired category execute the following code:
if( strtoupper($this->getLimitVarName()) != "ALL" )
{
$viewAllUrl = $this->getLimitUrl('All');
$this->_redirectUrl( $viewAllUrl );
}

At Admin Panel
Go to -> CMS -> Pages -> Home Page
Click on "Content" tab on LEFT
Click on "Show/Hide Editor" Button at RIGHT
Copy - Paste This Code there :
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
Give Category ID of your desired Category
To check Category_id of any category Go to : Catalog Menu -> Manage Catagories
Click on category, at right side's TITLE somewhat like will be displayed :
"CATEGORY_NAME ( ID : 5 )"
Regards.

Related

setPostedProducts with flat catalog category / product

I'm using setPostedProducts to maintain a sale/discount category.
On my dev machine, it's working (flat catalog category and product is off).
On my stage machine (flat catalog category and product is on), it's not working anymore.
How can I fix this?
category = Mage::getModel('catalog/category')->load($categoryId); // category id of my sales category
$category->setPostedProducts(array(123 => 1)); // product 123 should be the only one in my sales category for testing purposes
$category->save();
Don't really know why, but what solved my problem was adding
Mage::app('admin');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
before executing setPostedProduct().
I suppose that in admin the _getResource() function translates into Mage_Catalog_Model_Resource_Category instead of Mage_Catalog_Model_Resource_Category_Flat

Magento display a 3rd price on the product page

I would like to add a third price to my products like "MSRP" on the latest version but not available on mine (Magento 1.4.1.1).
I would like to display it on the product page and it has to change according to the selected option.
So, I started by creating a new attribute called "msrp".
I managed to get it for every child product on my view.phtml file with the following code:
<?php
if($_product->isConfigurable())
{
$_associatedProducts = $_product->getTypeInstance()->getUsedProducts();
foreach($_associatedProducts as $assProducts)
{
$msrp = $assProducts->getData("msrp");
echo "MSRP: ".$msrp."<br />" ;
}
}
?>
Now the question is how to show it only one at a time and which corresponds to the selected option?
(Just like the normal price changes when we select an option.)
Maybe with a piece of javascript in this file?
/app/design/frontend/[...]/[...]/template/catalog/product/view/type/options/configurable.phtml
Thanks for your help !

Magento Bundle Product - Multiple Options with Same products. How to stop Magento from hiding the repetitive products?

I am trying to setup a bundle product within Magento. This product should allow the customer to select 4 free products to include with the bundle. These products can be all different or 4 of the same product.
For example
Free Product 1
Free Product 2
Free Product 3
A customer could select four of Free Product 1, or one of Free Product 1 & 2, with two of Free Product 3.
I am using 4 drop-down input types which each have all three Free products as options. So a customer can choose any of the three products for each Free Gift line item.
Magento is only displaying one of the drop-down select lists, I believe due to the fact that each drop-down contains the same product list.
Where would I need to look to stop Magento from checking if the product options are already listed in a previous selection?
Unless you're doing this programmatically (that is writing the code), there's no way to do this.
When Magento adds a product, it first looks into the quote / shopping cart to see if one already exists. If one does, it pulls that one and adds to the quantity. There is no way to turn this off.
Programmatically, you very manually add an item to a shopping cart. This is how...
$cart = Mage::getSingleton("checkout/cart");
foreach ($products_to_add as $product_id => $custom_options) {
$product = Mage::getModel("catalog/product")->load($product_id);
$options = new Varien_Object(array("options" => $custom_options,
"qty" => 1));
// some products may result in multiple products getting added to cart
// I beleive this pulls them all and sets the custom options accordingly
$add_all = $product->getTypeInstance(true)
->prepareForCartAdvanced($options, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
foreach ($add_all as $add_me) {
$item = Mage::getModel('sales/quote_item');
$item->setStoreId(Mage::app()->getStore()->getId());
$item->setOptions($add_me->getCustomOptions())
->setProduct($add_me);
$item->setQty(1);
$cart->getQuote()->addItem($item);
}
}
// when done adding all the items, finally call save on the cart
$cart->save();

Count articles in category

I would like to display article count in a single category.
$categoryName = "CategoryName";
$n = count($this->category->$categoryName);
echo "This category has ".$n." articles in it!";
This is not working (example).
There is a parameter allowing you to do this already. Assign a Category List or Category Blog Menu item and then choose under the Category Options parameters tab. Change No Articles Message to show.
The reason that your code isn't working - is because a single category is just represented by $this->category.
However for either Category Blog or Category List layouts you can simply use:
$categoryName = "CategoryName";
if($this->category->title==$categoryName) {
count($this->category->getNumItems(true))
}
http://docs.joomla.org/Help25:Menus_Menu_Item_Article_Category_Blog#Category_Options
Try this.
The default category layout contain the count of the articles in it.
take a look at this components\com_content\views\categories\tmpl
Also you can found the count count($item->getChildren())
Hope this may you..

How can I add "Quantity" to a VirtueMart "Browse" page?

My VirtueMart shop.browse page has the typical columns of SKU, Name, Price, and "Update" (which contains the Add to Cart button). I would like to add a Quantity column between Price and Update so that a buyer can choose a quantity prior to pressing the "Add to Cart" button.
Though I don't know HOW to do this, I think I know WHERE to do it:
/public_html/components/com_virtuemart/themes/default/templates/browse/includes/browse_listtable.tpl.php
Lines 67-72 of that file tell the program how to build the table, but what I DON'T know how to do is modify the code source to tell it to include quantity as an element for the table. Here's the code:
// Loop through each row and build the table
foreach($data as $key => $value) {
$table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
$i = $i == 1 ? 2 : 1;
}
Which include file is actually being called in this foreach loop, and what code would I add to reference quantity data?
You should not modify your core code. If you just need to put quantity box inside your browse template use variable $form_addtocart
It will give you quantity box and add to cart button.
All variables for browse page and for flypage template you can find here:
http://virtuemart.net/documentation/Developer_Manual/Modifying_the_Layout.html
If this is not what you are trying to get, please be more specific, or show your web page.

Resources