skip to Main Content

My current Product url is in this format : example.com/product_slug . I need to append the category and subcategory URLs along with this URL. The site is implemented using magento,which i am not much familiar with. Is there any option to do this via admin side ?

2

Answers


  1. I have not checked it but you need to set Category Id on Product Object. Try the code below:

    $product->setCategoryId($categoryId)->getProductUrl();
    

    I am quite sure that it will work for you.
    Thanks

    Login or Signup to reply.
  2. You can reuse magento’s catalog url rewrite module.

    You’ll just have to pass the category and the store id as parameters.

    public function __construct(
      MagentoCatalogUrlRewriteModelProductUrlPathGenerator $ProductUrlPathGenerator,
      ....
    
    ) {
      $this->ProductUrlPathGenerator = $ProductUrlPathGenerator;
      ....
    }
    
    public function fetchFullProductUrl($product)
    {
      ...
      return $this->ProductUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search