Magento News

 

Magento API Calls

by edmondscommerce (Posted Sat, 12 Sep 2009 17:01:30 GMT)
If I was working locally to Magento then I wouldn’t use the API, I would interact directly by calling up Mage::app();

For example check out this bulk cache update script I pulled together:

Code:
<?php
$magePath 
'/path/to/Mage.php';
require_once 
$magePath;
//Varien_Profiler::enable();
//Mage::setIsDeveloperMode(true);
//ini_set('display_errors', 1);
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
echo 
'

Cleaning overall Cache

';
flush();
// clean overall cache
Mage::app()->cleanCache();
echo 
'done';
flush();
echo 
'

Cleaning Catalog Rewrites

';
flush();
// clear 'refresh_catalog_rewrites':
//Mage::getSingleton('catalog/url')->refreshRewrites();
Mage::getModel('catalog/url')->refreshRewrites();
echo 
'Catalog Rewrites was refreshed succesfuly
'
;
flush();
echo 
'

Cleaning Image Cache

';
flush();
//  clear 'clear_images_cache':
Mage::getModel('catalog/product_image')->clearCache();
echo 
'Image cache was cleared succesfuly
'
;
flush();
echo 
'

Cleaning Layered Navigation

';
flush();
//  clear 'refresh_layered_navigation':
Mage::getSingleton('catalogindex/indexer')->plainReindex();
echo 
'Layered Navigation Indices was refreshed succesfuly
'
;
flush();
echo 
'

Clearing out Search Index

';
flush();
Mage::getModel('catalogsearch/fulltext')->rebuildIndex();
echo 
'Search index was rebuilt succesfully
'
;
flush();
echo 
'

Rebuilding Flat Category

';
Mage::getResourceSingleton('catalog/category_flat')->rebuild();
echo 
'flat category was rebuilt successfully
'
;
flush();
echo 
'

Rebuilding Flat Products

';
Mage::getResourceSingleton('catalog/product_flat_indexer')->rebuild();
echo 
'flat product was rebuilt successfully
'
;
flush();
 

Alternatively for very small things, I sometimes just interact with the database directly, especially if I am only selecting and not updating.



http://magento-forum.co.uk/viewtopic.php?f=5&t=6#p15

Magento Forum

Possibly Related Posts:


 

Leave a Reply