Bagisto Forum

    Bagisto

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

    get category of product

    Modules
    2
    5
    541
    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

      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

        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

          no i need get the category of product

          N 1 Reply Last reply Reply Quote 0
          • N
            Naresh-webkul last edited by

            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

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post