Category : PHP

Magento get all categories

Here is a sample code to extract all categories from magento database: $collection = Mage::getModel(‘catalog/category’)-<getCollection()-<addAttributeToSelect(“name”); $catIds = $collection-<getAllIds(); $cat = Mage::getModel(‘catalog/category’); foreach ($catIds as $catId) { $category = $cat-<load($catId); print $category-<getName() . “”; }

Magento get products from a specific category

Next code is a sample to extract all products from a specific category: $prodCat = Mage::getModel(‘catalog/category’)->load($catId); $prodCat = $prodCat->getProductCollection(); foreach( $prodCat->getAllIds() as $prodId) { $_product=Mage::getModel(‘catalog/product’)->load($prodId); print $_product->getName().””; }

Magento countries and regions

Get all countries: $countries = Mage::getModel(‘directory/country_api’)->items(); Get regions based on country code: $regions = Mage::getModel(‘directory/region_api’)->items($countryCode);

Magento get stores

Get all Magento Stores from database: $stores = Mage::app()->getStores();

Magento Url’s

Bellow are few methods to get some useful magento url’s: Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); //http://www.magentoshop.demo/js/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); //http://www.magentoshop.demo/index.php/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); //http://www.magentoshop.demo/media/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); //http://www.magentoshop.demo/skin/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); //http://www.magentoshop.demo/

Magento get bundled products

Next code can be used to extract bundled products: $bundled_product = new Mage_Catalog_Model_Product(); $bundled_product->load(YOUR_BUNDLED_PRODUCT_ID); $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection($bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product); $bundled_items = array(); foreach($selectionCollection as $option) { $bundled_items[] = $option->product_id; }

Magento session

To set a value in magento session use: Mage::getSingleton(‘core/session’)->setMySessionData(‘My session data’); To get variable value from magento session use: $mySessionData = Mage::getSingleton(‘core/session’)->getMySessionData();

Magento – eCommerce platform

Magento is an open-source ecommerce web application. First version was launched on March 31, 2008. It was created by Varien, building on components of the Zend Framework. “Magento eCommerce Platforms provide the scalability, flexibility and features for business growth. Magento provides feature-rich eCommerce platforms that offer merchants complete flexibility and control over the presentation, content,

Read More →

1 2 3 4