3

Requirement: I am a newbie in magento trying to make a custom SOAP API in Magento 1.9 for managing wishlist. I need to connect it to an android application being developed in ionic V1.
At first i tried to use this extension magento-api but could not find a way to maintain session information in android. So, i moved to developing my own API.
I am able to fetch wishlist information(wishlist_id, items etc) and add to it.

Issue: But after adding a product in the wishlist via soap call, it is only shown in the admin area for the customer and not on the front-end of the website(User is logged in). Only products added from front-end(browser) are shown on front-end wishlist page.

After comparing the functionality from the front-end(/app/code/core/Mage/Wishlist/controllers/IndexController.php) with my Api.php(shown below) seems like my $buyRequest variable is missing some 'form-key' but i do not understand magento too much to understand this.

I have added the Api.php at /app/code/core/Mage/Wishlist/ModelApi.php.

My code to add product to wishlist is as follows:

public function create($customer_id, $product_id, $store = null){
    $return_result = array(
        'code' => 0,
        'msg' => null,
        'model' => null,
        'customer_id' => $customer_id,
        'product_id' => $product_id
    );
    $buyRequest = new Varien_Object(array());
    $params = array('product' => $product_id,
            'qty' => 1,
            'store_id' => $store,
            );
    $buyRequest->setData($params);

    $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer_id, true);
    $product = Mage::getModel('catalog/product')->load($product_id);
    $result = $wishlist->addNewItem($product, $buyRequest);

    Mage::helper('wishlist')->calculate();
    if($result){
        $return_result['msg'] = 'Product '.$product_id.' Added ';
        $return_result['model'] = $result;
    }  
    return json_encode($return_result);
}

I used the following link to implement the add functionality and used some code in the from the /app/code/core/Mage/Wishlist/controllers/IndexController.php file: add catalog product in wishlist programmatically in magento

Any help would be appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.