Search code examples
phpclassmagentomage

Using Magento classes in a single PHP page


Some times i put some php files into my magento's root directory, which is my site's root directory too. I know this may not be best practice, but that is not the point of my question now.

For example, I have made one example.com/calc.php , a very specific calculator that does not interact with any magento data. That works OK.

Some times I did some pages with interaction with magento's data, but all through API calls (and is so slow!!!!)

<?php
$user='mageuser';
$pass='magepass';
$soap = new SoapClient("http://www.example.com/api/v2_soap/?wsdl");
$session = $soap->login($user, $pass);
// and then cancel an order for example
$soap->salesOrderCancel($session, '100004826');

Is it there a way to do this including magento's classes instead of using the API to try to make things faster?

Thanks in advance


Solution

  • <?php
    
    require_once 'app/Mage.php';
    umask(0);
    
    Mage::app();
    
    $order = Mage::getModel('sales/order')->loadByIncrementId('100004826');
    $order->cancel();