I'm currently using Magento 1.1.6. My store only sells unique items (shirts with exclusive designs) which means at any one time, only 1 unit is available for each items.
How do I omit those items which are already sold from being displayed in the front page?
BTW, I'm using these code to show products on the front page:
{{block type="catalog/product_list" category_id="3" template="catalog/product/list_home_batik.phtml"}}
Go to System>Configuration>Catalog>Inventory>Stock Options. the dropdown for "Display Out of Stock Products" change to No.
I supposed the file catalog/product/list_home_batik.phtml is based on catalog/product/list.phtml
You can modify the file catalog/product/list_home_batik.phtml by adding
<?php if($_product->isSaleable()): ?>
just after
<?php foreach ($_productCollection as $_product): ?>
and by adding
<?php foreach ($_productCollection as $_product): ?>
just before
<?php endforeach; ?>
If it doesn't work, you should provide the complete file so I can have a look at it.
Related
I am trying to figure out how to hide the regular price on a product page only if tiered pricing exists for the product. Any tips would be gratefully appreciated.
I have been working on the following code to conditionally display price if tiered pricing but just cannot get it to work.
<?php if (count($_tierPrices) == 0): ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php endif; ?>
Tier price is something that is added when a certain quantity of product is selected. So for default product there should not be any tier price. When certain product is selected tier price is added
There is a block which displays tier price if there is any tier price present
Wrap the code with a conditional statement in catalog/product/view/type/default.phtml:
<?php if (count($_tierPrices) == 0): ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php endif; ?>
Add a conditional statement in catalog/product/view/type/default.phtml
<?php if (count($this->getTierPrices()) == 0): ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php endif;?>
I am trying to limit the number of products from a certain category to 4 on my homepage.
The code I am trying to do this with is:
{{block type="catalog/product_list" column_count="4" category_id="13" template="catalog/product/list.phtml"}}
Here are some of the things I have tried:
num_products="4"
limit = 4, limit="4"
count = 4, count="4"
_productCollection="4"
_productsCount="4"
I have made a copy of list.phtml thinking there might be a way to change it in there, but was unable to find out a way.
At the very top pf list.phtml is this code:
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
And under grid view there is this:
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
Any ideas on to limit the products either within the block or the template file?
The quicker is replace column_count=4 by is_homepage=1
and in the phtml add this :
<?php if($this->getIsHomepage() && $i==4) break; ?>
before this :
<?php if ($i++%$_columnCount==0): ?>
Then you will have just 1 row on homepage (if 4 by row as I suppose) so total 4 products
Try
{{block type="catalog/product_list" limit="4" category_id="13" template="catalog/product/list.phtml"}}
See
http://www.mcnab.co/blog/e-commerce/magento/magento-displaying-products-in-a-static-block/
Magento Product Collection Limit via XML
IN Magento ver. 1.9.0.1
i found a simple solution just add these line in list.phtml
just find the foreach loop it comes two times so need to add in both location.
<?php $i=0; ?>
<?php foreach ($_productCollection as $_product):
if($i == 6) break;
$i++;
?>
i put it for 6 record you may change it to as you required.
thanks
When I was facing this problem them i search to many sites but there is very less sites that make me understand of it..
I edited it myself by doing these step to show FIXED NUMBER OF PRODUCTS FROM CERTAIN CATEGORIES follows as:-
go to
1) app\design\frontend\default\<your theme>\template\catalog\product
copy list.phtml and save as list_new.phtml
Now open list_new.phtml and search '' after ending the if loop insert this code
<?php if($i<=4): // for 4 product?>
and close after the list ended.
<?php endif // for 4 product?>
The code will look like this-
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<?php if($i<=4): // for 4 product?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?>">
// some code here
</li>
<?php endif // for 4 product?>
2) Now go to CMS>Pages>select home page >content> and copy this code (change your categy id here)
{{block type="catalog/product_list" name="product_list" category_id="<category id>" column_count="4"mode="grid" template="catalog/product/list_new.phtml"}}
try this:
$_productCollection=$this->getLoadedProductCollection();
$_productCollection->getSelect()->limit(5);
Within our magento site we have the root category for the shop (this is just "default category"). Under this we have set-up some top-level categories (let's for example call these "electronics" and "furniture"), with a bunch of sub categories.
So as an example our category structure might be
Electronics
DVD players
MP3 Players
Computers
Furniture
3 Piece's
Armchairs
Tables
Sofabeds
I have managed to edit the layout/template for the "sub categories" such as "dvd players" so that we display a custom product list view.
Now what we want to do, is for the top level categories (the very first categories under the root category), is display a custom grid of all the subcategories and their associated thumbnail images, not the product list!
How do i assign a completely different template just for those top level categories?
If someone could provide an insight on how to do this and the step's we need to take (i should be ok with the code itself, its just how to implement it such as custom modules and templates)
Thanks
Sounds like you want a custom page layout that you can apply to your top level categories. A page layout is essentially a named page template that you can select in a dropdown to apply to products or categories.
To define a layout, add it in the global/page/layouts node of a module's config.xml, like so:
<global>
<page>
<layouts>
<my_custom_layout_name translate="label">
<label>My Custom Layout</label>
<template>page/my-custom-layout.phtml</template>
<layout_handle>my_custom_layout</layout_handle>
</my_custom_layout_name>
<layouts>
<page>
<global>
Then you just need to create the page/my-custom-layout.phtml template file somewhere in the app/design template fallback chain.
The layout_handle node specifies the name of a new layout handle that will be added to any page that uses this layout, allowing you to target it in layout XML files with a <my_custom_layout> node.
The .phtml file you're referencing will be the template for the entire HTML page, so it should include <html>, <head>, <body> tags and anything else you'd find in one of the default page/*.phtml templates (1column, empty, 2columns-left, etc). Between this and targeted layout XML, you can completely customize this page from scratch.
The final step is just to select this new layout under the "Custom Design" tab when editing each of your parent categories in Catalog->Manage Categories. If you don't see your layout in the dropdown, make sure your XML is configured properly (see app/code/core/Mage/Page/etc/config.xml for reference) and refresh your cache.
One way to do this would be to create a new template which which will be your category grid, then call that template as a static block on your selected categories, which you will select via the CMS. See below.
Create the category grid template
Navigate to “app/design/frontend/default/TEMPLATE/catalog/navigation”
In this path, we will create a file call category_listing.phtml
This file will have the following code:
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>
<h2><?php echo $this->__('Browse Products') ?> </h2>
<div class="subcat-listing">
<ul class="subcat-products">
<? foreach ($_categories as $_category):?>
<? if($_category->getIsActive()): ?>
<?php $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); ?>
<?php $layer = Mage::getSingleton('catalog/layer'); ?>
<?php $layer->setCurrentCategory($cur_category); ?>
<? if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
<li> <a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<img src="<?php echo $_imageUrl ?>" width="auto" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<? if($_description=$this->getCurrentCategory()->getDescription()):?>
<p class="category-description">
<?php echo $_description ?></</p>
<?php endif; ?>
<? endif; ?>
<? endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
Call this template in a static block
Go to the menu “CMS/Static block” and create new block.
Add this to the content section of the CMS block:
{{block type="catalog/navigation" name="catalog.categories" template="catalog/navigation/category_listing.phtml"}} . Then save the block.
Use this static block on category pages.
Go to the menu Catalog/Manage Categories
Now we need find the category that we want to show the new grid on
Select the categorie that you want, and in the tab“DISPLAY SETTINGS we set the following information:
DISPLAY MODE: STATIC BLOCK
CMS Block: Category Listing (the block that we create before)
Is Anchor: NO
Click SAVE. Remember that in the tab “Custom Design” you may need select your template. Remember also that the category much have an image assigned to it.
I've managed to add options to configurable products on my catalog pages using the code found here: http://www.magentocommerce.com/boards/viewthread/21039/P45/#t167724. What I'd like to do now is only show the options that are available according to the stock of the simple product that the option is coming from.
For example, if I have a t-shirt (configurable product) that has various colors (simple products) and my red color is out of stock, red wouldn't be shown as an option when the configurable product is displayed.
What's the best way to do this?
Update:
For the sake of clarity, here is the relevant block of code from the link I posted.
<?php if($product->getTypeId() == "configurable"): ?>
<?php $attValConfig = $product->getTypeInstance()->getConfigurableAttributesAsArray(); ?>
<?php if(sizeof($attValConfig)): ?>
<?php foreach($attValConfig as $attValConfigSingle): ?>
<fieldset class="product-options" id="product-options-wrapper">
<label><?php echo $attValConfigSingle['label']; ?>:</label>
<select name="super_attribute[<?php echo $attValConfigSingle['attribute_id'] ?>]" id="attribute<?php echo $_product->getId() ?>" class="required-entry super-attribute-select">
<?php foreach($attValConfigSingle['values'] as $attValConfigSingleVal): ?>
<option value="<?php echo $attValConfigSingleVal['value_index'] ?>"><?php echo $attValConfigSingleVal['label'] ?></option>
<?php endforeach; ?>
</select>
</fieldset>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
Since this code is simply getting all of the configurable options and displaying them, it doesn't check to see if the simple product that backs the configurable option is in stock. How do I do this?
I just wondering why we are checking the quantity for stock status why dont't we look on stock availability of simple products.
I have achieved to show out of stock on configurable product according to stock status.
Now you can make product "out stock" and "in stock" through stock availability attribute of simple product.
Try the following ( do what you want returning result ) :
$_productCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addIdFilter($productId) // this line is wrong, don't care this
->addFieldToFilter('qty', array('gteq' => 1));
I have the following requirement;
I want to show a products configured related products on the category listing page (list.phtml).
I figured I could make some call on the list.phtml inbetween the for each loop for each product using the [b]$_product[/b] variable but I can't seem to populate the relatedProductCollection
sorry new to all this is it even possible.
<?php foreach ($_productCollection as[b] $_product[/b]):?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?>last<?php endif; ?>" >
<div class="product-shop">
<div class="f-fix">
<?php $product->getRelatedProductCollection(); ?>
</li>
<?php endforeach; ?>
$product has been used to call the getRelatedProductCollection function.
but,
In that foreach loop you have taken it as $_product.
Can you see the difference ??
Underscore is missing. This is taken from your code. Make the variable same in both the places and try.