Search code examples
phpajaxmagentosyntax-errorrequire-once

magento - Warning: require_once(app/Mage.php): failed to open stream: No such file or directory


Using ajax, I am posting to a php file with the following code. however I recieve the following error when trying to require app/Mage.php:

Warning: require_once(app/Mage.php): failed to open stream: No such file or directory

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

function getProductStockLevel() {
    $productId = 104;
    $product = Mage::getModel('catalog/product')->load($productId);
    $qty = $product->getStockItem()->getQty();
    echo $stockLevel;
}
getProductStockLevel();
?>

Can anyone help, All i need this file to do is return the stock value based on the product ID?

Thanks


Solution

  • You ajax post might not get the correct path, try this instead:

    require_once(__DIR__ . '/app/Mage.php');