Add to Cart alternative button link

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345504

-- HikaShop version -- : 4.6.1
-- Joomla version -- : 3.10.10
-- PHP version -- : 7.4.32
-- Browser(s) name and version -- : Chrome

Hi guys,
let me say,, for example, that I have a site based on User Subscriptions, like:
- Registered A > free site registration
-- Registered B > paid subscription
--- Registered C > paid subscription

I'd like to add a "virtual" "Registered A" product for guests, so when they surf they can see listed the "Registered A" product with its description and when Guest click on that "Add to Cart" button he should be simply redirected to the registration page.

Please, Do you have any tricks or tips suggestion for it ?
I thought about this simply solution that would be a good improvement for HikaShop also in others use cases:

In Configuration > Features > Main > Catalogue Mode: ... we can set the catalogue mode that will hide the "Add to Cart" button on all products.
If we leave it set to "No", we can reach the same result by product, adding "Product > MAIN OPTIONS > Quantity: 0" = very well.

Now, considering that would be very good to maintain the "Add to Cart" presence in the Product list layout, Why not to add the possibility, when "Configuration > Features > Main > Catalogue Mode: Yes" OR "Product > MAIN OPTIONS > Quantity: 0", to enter a "Product > Main Options > Add to Cart alternative URL link" ?
Where, if added, clicking on the Add to Cart button I will be redirected to the linked page instead of to add the item to the Cart Checkout.
That would be good also for list products of other sites (we have clients that propose discounts codes into description to buy items directly from other partners external eCommerce included Banggood, AliExpress, Amazoon, etc. ... ).
Then, if we need to change the Add to Cart button style and / or to change the Add to Cart language string, we can do it by using CSS and / or creating a new "Product > DISPLAY > Page layout: ..."

Do you agree ? Please, Can you help with the code ? Do you have any suggestion for a better solution ?

Please Log in or Create an account to join the conversation.

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345513

Hi,

If you have the "force canonical URL on listings" setting activated in the HikaShop configuration, you could enter the registration page URL as canonical URL of product Registered A. That way, when the user clicks on the product link on the listing, he would be redirected to the registration form page.

Alternatively, if it's only for one product you can either set the quantity to 0 or the sale start date in the future, or the sale end date in the past for that product Registered A. That way, it will replace the add to cart button by a text.
Then, you can use a translation override to change that text to a button. For example, with the quantity set to 0:

NO_STOCK="<a href='xxxx' class='hikacart hikabtn'>Add to cart</a>"
where xxxx is the URL of your registration page.

Finally, if you want a more complex solution, you could edit the code of the view file "quantity" via the menu Display>Views and change the area displaying the add to cart button to take into account a custom product field where you would enter the URL you would like instead of the add to cart button. It's quite easy. Change:
if($add_to_cart) {
to:
if(!empty($this->row->xxxx)) {
 echo "<a href='".$this->row->xxxx."' class='hikacart hikabtn'>Add to cart</a>";
}elseif($add_to_cart) {
where xxxx is the column name of the custom product field.

Since there are quite a few tricks and small code changes to be able to do this, and it's starting to stray off from what an ecommerce solution is supposed to do, and there are already too much options in HikaShop overwhelming newcomers, I don't think it would be wise to integrate this as a default capability.

Please Log in or Create an account to join the conversation.

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345523

Hi Nicolas,
in first of all really Many Thanks for your super precious suggestions, now:

A - Force canonical URL - good solution, but, in this case:
- AA - we are going to loose the Product page with product description that we are used to fill with instructions, tutorials etc.
- AB - ...and What about Force canonical URL & Multi language ?

B - Language String - good solution, but, as you mentioned, it is a "one product" solution. It could solve two things at the same time (the message shown and the URL redirection), but in this way we are loosing the standard NO_STOCK message feature for others products.
Maybe, Do you have any tricks to call different languages strings like NO_STOCK_XXX / NO_STOCK_YYY depending on situations ? (I'm thinking on something like you done the Translations for the Canonical URL field)

C - Display Views - good solution, but it would force us to create a layout for each URL, which is impractical for Vendors.
- To add this feature by default would need to create an URL field to be called in the new View Layout and, maybe, by calling a personalized ADD_TO_CART_XXX language string.
- If not by default, we could use the Product Custom Filed for it, What do you think ?
Can you help with the code to invoke the Custom Field (URL) into your code suggestion ?

Please Log in or Create an account to join the conversation.

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345531

Hi,

AA. Indeed.

AB. Yes, that would be an issue, especially in multivendor mode as you can't expect the vendors to enter manually the canonical URL for each language.

B. Well, the trick I have in that case is the C solution.

C. Mmm. You missed what I said. My code precisely do what you want. The $this->row->xxxx is precisely there to "invoke the Custom Field (URL)" so that each product can have a different URL for the "fake" add to cart button.

Please Log in or Create an account to join the conversation.

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345562

Hi Nicolas,

so, C - Display Views
- The $this->row->xxxx is precisely there to "invoke the Custom Field (URL)" = Thanks!
- Instead of the "Add to cart" we can create and call a personalized ADD_TO_CART_XXX language string

But

1 - I cannot find any if($add_to_cart) into the .../components/com_hikashop/views/layouts/tmpl/quantity.php file
(I checked also into the button.php) Please, What am I missing ?

2 - HikaShop is using as quantity value conditions:
- "0" for Catalogue mode
- "-1" for Unlimited

As far as I understand in your suggestion you are looking for "Quantity" field when is empty: if(!empty($this->row->xxxx))
So when we'll need to add a different link to the new "Add to Cart" button we should:
- To add the URL into the Product Custom Field
- To leave "empty" the Product > Quantity field
Am I right ? That is very good because instead of contaminating / using existing functions.

I'm asking because right now when trying to save Product with Quantity: empty field, Hika by default is replacing it with -1 (Unlimited)...

PS - "...there are already too much options in HikaShop overwhelming newcomers..." = Got it, I understand you and I'm agree with you. I believe that simplicity is a key to success. Anyway, in the way we are describing it, I despite everything I think it is an excellent solution, to be considered, for the needs of eCommerce today (in the forms I described at the beginning)

Please Log in or Create an account to join the conversation.

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345576

Hi,

C.2 Then, for that, you can replace:
Add to cart
by:
<?php echo (empty($this->row->yyyy) ? 'Add to cart' : $this->row->yyyy); ?>
with yyyy being the column name of another custom product field where the vendor can enter the text of the button, if he doesn't want "Add to cart".

1. It's in product / quantity.php (for the product details page). For the listings, it's product / add_to_cart_ajax.php with the line:
if($add_to_cart && !$has_options && !$global_on_listing) {

2. No. My code will replace the normal add to cart button with the "fake" one as long as the vendor provides the URL in the custom product field.

PS: Thanks !

Please Log in or Create an account to join the conversation.

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345612

Hi Nicolas,

C1 - Got it, thanks:
Product Listings - …/components/com_hikashop/views/product/tmpl/add_to_cart_ajax.php - line 169
Product - …/components/com_hikashop/views/product/tmpl/quantity.php - line 134

C2 - "...No. My code will replace the normal add to cart button with the "fake" one as long as the vendor provides the URL in the custom product field..." = Got it, doesn't matter what is the Quantity field value...

if(!empty($this->row->xxxx)) {
echo "<a href='".$this->row->xxxx."' class='hikacart hikabtn' target=”_blank”>Add to cart</a>";
}elseif($add_to_cart) {

Language String
Add to cart - Instead to create another Custom Field to just add the button text, it would seem more logical to me to use a new dedicated language string (even better for Multi language). Do you agree ?

I created a new ADD_TO_CART_ALT language string …/language/en-GB/en-GB.com_hikashop.ini
And I tried to call it into your code by using:
<?php echo JText::_('ADD_TO_CART_ALT')?>
<?php echo ADD_TO_CART_ALT ?>
But I'm not been able to reach the goal...

Custom Field
Now, connected to the Language String there is the question: Which Custom Field to use?
I had to use the Text type, because by using the Link one I have back some issues and it is not running.
Be able to use the Link Custom Field would allow us to configure quite everything via the Custom Field (apart from assigning a Class to the Custom Field), like: to open in a new window and in special the Link Text shown that will avoid the Language String creation...

Please Log in or Create an account to join the conversation.

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345625

Hi,

C2 Well, you do you. If you prefer it like that, then yes.
The code would be:
<?php echo JText::_('ADD_TO_CART_ALT'); ?>

Custom Field:
You could use a custom field of the type link, but then you need som extra processing to explode the data in $this->row->xxxx to use one bit in one place and the other bit in the other place in the code. Basically, it would make the code more complex and just above you said you prefered one alternative translation key...
I don't think a link type custom field will help, but will just make it more complex that it needs to be.

Please Log in or Create an account to join the conversation.

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345719

Hi Nicolas,

Language String
by replacing Add to Cart with <?php echo JText::_('ADD_TO_CART_ALT'); ?> does not run, the language string is not shown

I have to rewrite the entire code in this way to have back running the language string:

if(!empty($this->row->cart_url_button)) {
$contentalt = JText::_('ADD_TO_CART_ALT');
echo "<a href='".$this->row->cart_url_button."' class='hikacart hikabtn' target=”_blank”>$contentalt</a>";
}elseif($add_to_cart) {

Please, Is it the right way ?

Custom Field
Got it, thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345724

Hi,

It's ok. The previous code should have been ok too. You must have made a typo at some point.

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds
Powered by Kunena Forum