0

I want to use webhook 3rd party after receiving (catch a response) in magento 1.9 my code I want to use like this calling at the end a function in IndexController.php My file is Webhook.php ubicate at Helper folder.

require_once ("D:/wamp/www/magento1.9/app/code/local/Ns/Thorleif/controllers/Adminhtml/IndexController.php");

            $input = file_get_contents('php://input');
            $obj = json_decode($input);
            echo 'test1';

            switch ($obj->event) {
                case 'onProductCreated':
                echo 'test2';
                foreach ($obj->payload->SellerSkus as $sku) {
                    echo 'test3';
                    $prod = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('sku',$sku);
                    $skus = $prod->getData('sku');
                    $img = $prod->getData('image');
                    $websites = Mage::getModel('core/website')->getCollection()->addFieldToFilter('is_default', 1);
                    $website = $websites->getFirstItem();
                    $websiteId = $website->getId();
                    $websiteCode = $website->getCode();
                    $url = Mage::getConfig()->getNode('web/unsecure/base_url', 'website', $websiteCode);
                    $url .= 'media/catalog/product'.$img;
                    $xml = '<?xml version="1.0" encoding="UTF-8" ?><Request><ProductImage>';
                    $xml .= '<SellerSkus>';
                    $xml .= '<Images><Image>';
                    $xml .= 
                    $url;
                    $xml .= '</Images></ProductImage></Request>';
                    echo $xml;
                    var_dump(Ns_Thorleif_Adminhtml_IndexController::postImage($xml));

                }

            }

But I receive this kind of issues

Class 'Mage_Adminhtml_Controller_Action' not found in D:\wamp\www\magento1.9\app\code\local\Ns\Thorleif\controllers\Adminhtml\IndexController.php</b> on line 2

Or if I put it like class file I have a "expecting function" error or "Mage" class doesn't find at level "Mage::getModel". How Can I post at the end postImage($xml) called from controllers/Adminhtml/IndexController.php?

2

Aside from the numerous best practices you're ignoring, this should be possible when you add:

require_once '/path/to/magento/app/Mage.php';

in the top of your file.

After that, do a: Mage::app('admin'); to initialize Magento.

Afterwards, you should be able to use Magento and include the controller Class.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.