How to check or display attributes of a product card in category, search, home pages
-
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.
-
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.
-
@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
-
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