• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

get category of product

Modules
2
5
837
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Ahed last edited by 18 Jul 2022, 10:56

    hello
    i need to view the root gategory for each product when view info of product
    how i can get the category of product by product

    1 Reply Last reply Reply Quote 0
    • N
      Naresh-webkul last edited by 18 Jul 2022, 11:43

      Hi @Ahed ,
      You can call the following method to get the products category-wise.
      You can find the file on the following path:
      packages/Webkul/Velocity/src/http/Controllers/Shop/ShopController.php

      Selection_017.png

      1 Reply Last reply Reply Quote 0
      • A
        Ahed last edited by 18 Jul 2022, 11:45

        no i need get the category of product

        N 1 Reply Last reply 18 Jul 2022, 11:49 Reply Quote 0
        • N
          Naresh-webkul last edited by 18 Jul 2022, 11:48

          Also if you want to find the categories related to the product you can check the following method at the following path:
          packages/Webkul/Product/src/Helpers

          /**
           * Returns product categories
           *
           * @param \Webkul\Product\Contracts\Product|\Webkul\Product\Contracts\ProductFlat  $product
               * @return string
               */
              public function getProductCategories($product)
              {
                  if ($product instanceof \Webkul\Product\Models\ProductFlat) {
                      $categories = $product->product->categories;
                  } else {
                      $categories = $product->categories;
                  }
                  $names = [];
                  foreach ($categories as $key => $category) {
                      $names[] = $category->name;
                  }
                  return implode(', ', $names);
              }
          
          1 Reply Last reply Reply Quote 0
          • N
            Naresh-webkul @Ahed last edited by 18 Jul 2022, 11:49

            @Ahed ,
            will you please elaborate on exactly what you want?

            1 Reply Last reply Reply Quote 0
            4 out of 5
            • First post
              4/5
              Last post