Magentoを別プログラムから操作する
2011年6月20日(月) 19:37 JST
投稿者: 河口
ECサイト構築にMagentoを使用した際、別プログラムとの連携が必要となったので、その方法をご紹介します。
// Magentoのコアファイルの読込み
require_once('app/Mage.php');
// Magentoの初期化
Mage::app('default');
これだけです。後は、Magentoのオブジェクトが自由に使用できるようになります。
// 商品マスタの取得
$product = Mage::getModel('catalog/product)->load(商品ID);
// 商品名を更新
$product->setName('新しい商品名');
$product->save();
// 顧客マスタの取得
$customer = Mage::getModel('customer/customer')->load(顧客ID);
顧客マスタは、現在のセッションからも取得できます。
Mage::getSingleton('core/session', array('name'=>'frontend'));
// ログイン中かどうか
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
// ログイン中の顧客情報取得
$customer = Mage::getSingleton('customer/session')->getCustomer();
}
以上です。 |

