문제

I'm trying to add in a single file on the root folder something than given a sku or id (it can be either get or post)

it will return me the stock as plain text.

I'm trying to figure out if there is a way to do something like.

$products=Mage::getModel('catalog/product')->getCollection();
foreach($products as $_product){
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
echo $stock->getQty();
echo $stock->getMinQty();
echo $stock->getMinSaleQty();
}

but this file isn't connected to Magento

sorry for the bad english,

도움이 되었습니까?

해결책

Copy the index.php, and instead of calling Mage::run(), call:

Mage::app('admin', 'store');

Then after the call above, you can run your Magento code with full access

BIG WARNING NOTE: This grants unauthenticated access to whatever your script does.

다른 팁

This is the proper way to call the magento functionality in your custom file on root of magento. You have to call these first 2 line in your code and rest coding as per magento standards.

<?php
require_once 'app/Mage.php';
Mage::app();

$products=Mage::getModel('catalog/product')->getCollection();
foreach($products as $_product){
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
    echo $stock->getQty();
    echo $stock->getMinQty();
    echo $stock->getMinSaleQty();
}
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top