Showing posts with label magento products. Show all posts
Showing posts with label magento products. Show all posts

Programmatically Assign Products from one category to other category in Magento


Programmatically Assign Products from one category to other category in Magento

Create a PHP script file in root directory of Magento directory structure and put below code in it.
Adjust category from ID and to ID according to need.
Execute script.
 To
//  5 => 10
$from = 5;
$to = 10;
 
$category = Mage::getModel('catalog/category')->load($from); 
 
$productCollection = $category->setStoreId(1)->getProductCollection();
 
foreach($productCollection as $_product) {
  $product = Mage::getModel('catalog/product')->load($_product->getId());
 
  $newCategories = $origCats = $product->getCategoryIds();
  if(!in_array($to, $origCats)) {
    $newCategories = array_merge($origCats, array($to));
    $product->setCategoryIds($newCategories)->save();
    echo 'Assigned -- ' . $product->getId() . '
'; } } echo 'Completed Execution!!!'; ?>

Magento - Products are not showing up in frontend

Below are the basic things to check when your products are not showing up in frontend

  • Are the products Enabled?
Set "Status" of the product "Enabled"
  • Are the products Visible?
If the product can be sale individually, set it's "Visibility" attribute to "Catalog" OR "Catalog, Search"
  • Are the products In Stock?
Set "Stock Availability" of the product "In Stock"
  • Is Product in sufficient quantity to sell?
Set "Quantity" of the product to some integer greater than 0
  • Are any associated products in stock?
If the product is of type complex, like a bundled or configurable product, at least one of the associated products that comprise it must be in stock and enabled 
  • Are the products in the desired category?
  • Are your Caches and Indices out of date?
Access System -> Cache Management and System -> Index Management menus. Re-index all the indices and Refresh all the caches.