The checklist for whether items are in stock follows. Some will seem stupid until the first time you spend an hour trying to figure this problem out:
- The products must be Visible in Catalog.
- The products must be Enabled.
- Product must have a stock Quantity.
- The product must be set to In Stock.
- If the product is set not to track stock, it still has to have a stock Quantity and be set to In Stock.
- The product must be assigned to the target Category.
- If using multi-website mode (or if you imported the products through Data Flow), the products must be assigned to the target Website.
- You must refresh your Cache / Indices, just to make sure.
Welcome to Magento. Hope that helps!
Joe
Finally very simple...
Use the definition block below :
{{block type="catalog/product_new" name="home.catalog.product.new" alias="allCatalogNewProducts" category_id="5" template="catalog/product/new.phtml"}}
To retrieve the category_id, you should modifiy the _beforeToHtml function of the new class like this :
File in \app\code\core\Mage\Catalog\Block\Product\New.php
Prefer surcharge this file in local path
protected function _beforeToHtml()
{
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToSort('news_from_date', 'desc')
->setPageSize($this->getProductsCount())
->setCurPage(1)
;
if($categoryId=$this->getData('category_id')){
$category = Mage::getModel('catalog/category')->load($categoryId);
$collection->addCategoryFilter($category);
}
$this->setProductCollection($collection);
return parent::_beforeToHtml();
You can see that an if statement has been added :
if($categoryId=$this->getData('category_id')){
$category = Mage::getModel('catalog/category')->load($categoryId);
$collection->addCategoryFilter($category);
}
You retrieve the category_id with the function $this->getData('category_id')
Enjoy...
Best Answer
In PHP code you can put them into the category while you are importing them.
Say you have a product called $product and a category ID called $category_id
You can set the categories which a product belongs to by doing the following
If the product already has categories and you'd like to add one more then you can use
getCategoryIds()
like this:Or, as mentioned by Joshua Peck in the comments, you can use the
category_api
model to add or remove a product from a category without affecting it's current category assignments: