Get product link from Magento API

I am new to Magento and use their API. I need to get the product url from an API call. I see that I can access url_key and url_path, but, unfortunately, it is not necessary that the URL for the product (that is, it may be the category / my -product-url.html), where url_key will contain my-product- url and url_path are just my-product-url.html. A further complication of things could be / category / sub -category / my-product-url.html. So, how can I get the full URL with the category and everything, how is this configured in url rewrite information? It looks like this should be followed by product information from the call to product.info api, but it is not.

+3
source share
2 answers

Magento Product api does not provide this functionality

Although there are simple ways to extend a specific API in custom modules, itโ€™s the fastest way if you donโ€™t want to write a custom module (since I find it difficult to create a new magento developer).

Copy the source API class of the product from the folder corein localbefore editing anything (thus, the installation of Magento will remain "update-save").

  • copy api.php from:
    app/code/core/Mage/Catalog/Model/Product/Api.php
  • to:
    app/code/local/Mage/Catalog/Model/Product/Api.php

Now change the method infoin the copied file to include full_url. Add the following line to $result-array. (Be sure to set the necessary commas at the end of the lines of the array.)

'full_url' => $product->getProductUrl(),

Your method code should look like this:

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


    $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;
}

product.info full_url API.

+3

, , , , \\ โ€‹โ€‹\ Mage\\Model\\product.php

-1

Source: https://habr.com/ru/post/1723378/


All Articles