Protuct page "Add To Cart" Redirect

  • Posts: 25
  • Thank you received: 0
7 years 6 months ago #270133

-- HikaShop version -- : Essential 2.6.3
-- Joomla version -- : 3.6.5
-- PHP version -- : 5.6.24

Hello,

This a basically a pre sales question. I need to find a solution for my unique products before I upgrade.

I would like to have a second product page for each of my main products. The second product page would list the "Options" that are
specific to the Main Product.

For each "Main Product", I would like to have an "Add To Cart" button with a custom redirect. So after the main product is added to the cart the customer is redirected to the 2nd product page, which, has the Options for the Main Product listed on it.

The "Add To Cart" Button on the "Main Product" page would actually say something like "Add to Cart and Proceed to Options"
And the "Options" product page would have a traditional add to cart button, which, could redirect to cart or simply stay on current page.
The Options page images will actually contain text that explain each option.

I must keep the products and their related products on separate pages because they need to be added to the cart in different.
quantities. i.e. Main product quantity 125, option quantity 1. A custom item field price plugin in place of product options did not work out for me.

The "add to cart custom redirect" would be unique to each Main Product and therefor a universal configuration for a redirect would not work.

I've seen several posts on redirects but none that would explain how to do this. I suspect the Add to cart HTML link for each product will have
something to do with a solution. However, if I knew what modification to make to that link, I still would need to know where to put it. i.e. what file, where in the file, and how to access the correct file. And again, it would be done each product. Of course the redirects would need to remain intact through any updates.

Any help will be greatly appreciated,

Michael

Last edit: 7 years 6 months ago by MichaelGary.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 6 months ago #270148

Hi,

With a HikaShop previous to HikaShop 3, or with the "add to cart legacy" setting turn on in order to use the old add to cart system, the redirection after the add to cart uses the parameter return_url.
You can find it defined in the file "show" of the view "product" with the line:

<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url))); ?>"/>
So doing what you want should be quite easy in that case.
You would create a custom field of the table "product" via the menu Display>Custom fields so that you could then enter the URL of the options page for each product, and then at the top of the product/show view file, you could add such code:
<?php if(!empty($this->element->XXX)) $this->redirect_url = $this->element->XXX; ?>
where XXX would be the column name of the custom field.

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

  • Posts: 25
  • Thank you received: 0
7 years 6 months ago #270224

Hello,

Tried variations for several hours, no luck.

Is this screenshot showing the proper file regarding "show" of the view "product"? and is the place where I inserted the line ok? " And the name of the custom field is inserted twice? in both places that you had xxx?



And also please, you said the custom field Table is product
1. what "field" type should it be?
2. what part of the custom field configuration do I enter the url for the options page?
3. what is the proper way to retrieve or find the "Options" product url? just go to product in front end and copy url in browser address field?
3. Is this custom field suppose to display on the front end Main Product page in the form of a link?
4. Or, does this custom field and added code simply show up in the backend and override the existing "Add to Cart" button and "After a product is added to the cart" setting? i.e. original "add to cart" button now redirects according to the custom order filed and added code?
5. Is that file specific to the product or will the redirect code for every product (several hundred) all be added to that same file?

Thank you in advance for you patience and help.

Michael

Attachments:
Last edit: 7 years 6 months ago by MichaelGary.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 6 months ago #270235

Hi,

0. The code change looks fine. You also need to make sure that you did the change for the correct template you're using on your frontend and not another one.
1. I suppose you'll want a custom field of the type "text" in order to be able to enter the URL in each product in a text input field.
2. It's not in the custom field settings that you enter the URL since it needs to be different for different products. It's when you edit the products, in the input field of the custom field.
3. Yes, exactly.
4. That code change will indeed allow you to override the system linked to the option "After a product is added to the cart". Just make sure that this setting is not set to "stay and display a notice popup" or "always stay on the page" or you won't get the redirection at all.
5. You just need to do that code modification once for all the products and then enter the URL you want in the custom field of each product.

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

  • Posts: 25
  • Thank you received: 0
7 years 6 months ago #270283

Thank you but still no luck,

Could you check my steps below and look at configuration screenshots?

1. Created custom product field. label and Column name is "testing" NOTE: it is not "product_testing" like other column names

2. Added Primary Product No. 478 in the configuration of custom product field

3. Entered "Options Product" url into custom product field on Primary Product No. 478 backend configuration page
"Options Product" url is http://localhost/ssm/index.php/tuf-cal/product/no-478-tuf-cal-overlaminated-white-vinyl

4. Added code to Front end rnshop product view of show file. <?php if(!empty($this->element->testing)) $this->redirect_url = $this->element->testing; ?>

5. System > configuration cart setting "After a product is added to the cart" set to Always Go to Checkout.

Last edit: 7 years 6 months ago by MichaelGary.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 6 months ago #270330

Hi,

1. You say it is not product_testing, but in the screenshot of your custom field settings, in the "column name" option I do see that you have "product_testing". You even selected it. So did you change your custom field ? Otherwise, the code should use product_testing if the column name is product_testing.

2. That is not needed. You want the custom field in the product edition screen of all the products so that you can enter the URL in the custom field if any.

3. I see that your product has characteristics. In that case the code needs to be different. It needs to be:
<?php if(!empty($this->element->main->XXX)) $this->redirect_url = $this->element->main->XXX; ?>
Otherwise, with the code I gave before, the system will use the redirect_url that you've configured in the default variant of the product instead of the value from the custom field of the main product.

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

  • Posts: 25
  • Thank you received: 0
7 years 6 months ago #270349

Thank you,

Regarding "column name" option I do see that you have "product_testing". That was a prior configuration, I always have the actual "column name"
in the show file code.

Nonetheless, it still will not work for me. I thought the silver bullet was going to be the fact that I have Characteristics in the product. Changing to the
proper code for products with Characteristics didn't help.

Would you be willing to log on to the back end and see if you can make it work?

If so, I am sending login info via your contact form.

Thanks

Michael

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 5 months ago #270351

Hi,

Looking at the pages on your link, the change is taken into account. However, it seems that you have activated the "Use AJAX when possible for add to cart buttons" setting in the HikaShop configuration and that modification can only work if that option is turned off.

Please understand that this is outside user support. And on top of that, we only provide support for valid commercial editions of HikaShop.
I already gave you code samples and hints as to what to do. Please see with a developer on your end if you need debugging for that customization.

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

Time to create page: 0.098 seconds
Powered by Kunena Forum