Bagisto Forum

    Bagisto

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

    How to check or display attributes of a product card in category, search, home pages

    General Discussion
    3
    4
    229
    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.
    • S
      senchan last edited by senchan

      I use Bagisto v2.2.3 and I created a new product type called External, an attribute family (external) with the attribute external_url (text field).

      On the category/home/search page, how to check if a product card has the external_url attribute or is the external type, display the "Buy now" link button with the external_url value (website url). Other product types like Simple, Bundle etc still show "Add to cart" button. Similarly, display other attributes of a product card.

      Thanks.

      ashish2409 1 Reply Last reply Reply Quote 0
      • ashish2409
        ashish2409 @senchan last edited by

        @senchan

        Hello There,
        Thank you so much for your concern, I really appreciate that. Somehow I am bit confused in above query.
        Can you please help us in understanding the query, I would love if you can add points for the same.

        Thank You So Much.

        S 1 Reply Last reply Reply Quote 0
        • S
          senchan @ashish2409 last edited by senchan

          @ashish2409 Bagisto has default product types: Simple, Configurable, Virtual, Downloadable, Bundle, Grouped which is good for selling in-stock products, not external products.

          For example, I create a text attribute called Link (external_url) and add it to the default attribute family. In the frontend, check if the external_url is not empty, show the <a href="{{ external_url }}>Link button</a>. If empty, show the Add to cart button as default.
          Similarly, I created a new product type called External with the Link field.

          On product page, I use this code to check if it's an external product type, show the Link button or Add to card button. I tried @if ($product->getTypeInstance() instanceof \Webkul\Product\Type\External) in .../components/products/card.blade.php to check if the external product but nothing works. Do you know how to check it? Thanks.

          @if ($product->getTypeInstance() instanceof \Webkul\Product\Type\External)
                                                  
                                                      <a href="{{ $product->getTypeInstance()->getExternalUrl() }}" 
                                                  
                                                         class="secondary-button w-full max-w-full max-md:py-3 max-sm:rounded-lg max-sm:py-1.5" 
                                                  
                                                         target="_blank">
                                                  
                                                          Check it out
                                                  
                                                      </a>
                                                  
                                                  @else
                                                  
                                                  
                                                  
                                                  <x-shop::button
                                                  
                                                      type="submit"
                                                  
                                                      class="secondary-button w-full max-w-full max-md:py-3 max-sm:rounded-lg max-sm:py-1.5"
                                                  
                                                      button-type="secondary-button"
                                                  
                                                      :loading="false"
                                                  
                                                      :title="trans('shop::app.products.view.add-to-cart')"
                                                  
                                                      :disabled="! $product->isSaleable(1)"
                                                  
                                                      ::loading="isStoring.addToCart"
                                                  
                                                  />
                                                  
                                                  
                                                  
                                                  @endif
          1 Reply Last reply Reply Quote 0
          • Rishabh-Webkul
            Rishabh-Webkul last edited by

            Hello @senchan

            Kindly refer to this:

            {!! $product->getTypeInstance()->getPriceHtml() !!}

            We have created the getPriceHtml() method for each product type, and we use this function. If you need to get the external URL, you will need to create a similar function first.

            If you have any issues regarding this then let us know.

            I hope this helps, and it should work fine for you afterwards.

            Thanks & Regards

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