views:

1727

answers:

2

I am new to Magento and using their API. I need to be able to get the product url from the API call. I see that I can access the url_key and url_path, but unfortunately that's not necessarily what the URL for the product is (ie it may be category/my-product-url.html) where url_key would contain my-product-url and url_path would only contain my-product-url.html. Further complicating things, it may even be /category/sub-category/my-product-url.html. So, how would I get the full url with the category and everything as it is setup in the url rewrite information? Seems like this should come with the product information from the product.info api call but it doesn't.

+1  A: 

Magento Product api does not provide such functionality

although there are easy ways to extend specific api in custom modules, but here is the quickest way if you don't want to write a custom module ( as i think it's difficult for a new magento developer)

open this file:
app/code/core/Mage/Catalog/Model/Product.api

and change info method to this:


public function info($productId, $store = null, $attributes = null)
    {
        $product = $this->_getProduct($productId, $store);

        if (!$product->getId()) {
            $this->_fault('not_exists');
        }

        $result = array( // Basic product data
            'product_id' => $product->getId(),
            'sku'        => $product->getSku(),
            'set'        => $product->getAttributeSetId(),
            'type'       => $product->getTypeId(),
            'categories' => $product->getCategoryIds(),
            'websites'   => $product->getWebsiteIds(),
            'full_url'   => $product->getProductUrl()
        );

        foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
            if ($this->_isAllowedAttribute($attribute, $attributes)) {
                $result[$attribute->getAttributeCode()] = $product->getData(
                                                                $attribute->getAttributeCode());
            }
        }

        return $result;
    }

afterwards you can call product.info and use full_url field

cubny
A: 

This is not entirely correct. In fact, the file app/code/core/Mage/Catalog/Model/Product.api does not even exist. This is the correct path: app\code\core\Mage\Catalog\Model\Product\Api\V2.php

Anton Xedin