Product Option - Text

Ask the community for help and support.
Post Reply
LeeFoster
VIP Member
VIP Member
Posts: 228
Joined: Sun Feb 28, 2021 9:41 pm
Has thanked: 1 time
Been thanked: 5 times

Product Option - Text

Post by LeeFoster »

Morning All,

Some of the products in our store are customisable, ie. text can be added or changed on them. At the moment we are using the 'Any other information' box on checkout to take these text options.

We'd now like to add a more professional option and have the name/text field on the product page, I know there used to be Option Types for older versions of OScommerce but this hasn't been updated yet.

Is anyone doing something similar? I'd like for it to be controllable from the product info admin section so it only appears on specific pages.

Not Related but I'm also looking for a way to turn off the qty box on specific products where they will be done as a one off.

Thanks in Advance

Tags:
LeeFoster
VIP Member
VIP Member
Posts: 228
Joined: Sun Feb 28, 2021 9:41 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Product Option - Text

Post by LeeFoster »

Right,

I've managed to create an input box on the product info page, now I just need to work out how to pass the information to the cart. Any thoughts on this?

Thanks
User avatar
Kofod95
VIP Member
VIP Member
Posts: 605
Joined: Sat Feb 06, 2021 7:38 pm
Has thanked: 80 times
Been thanked: 141 times

Re: Product Option - Text

Post by Kofod95 »

Not sure at all, but just to try to be helpful:
You should be able to pass it into the $_SESSION['cart'], but you could also make a new $_SESSION['custom_text']. You just have to make sure to insert it into the carts_table, and later into the orders table. That is something I've done before, using the below hook-call from line 140 of includes/system/segments/checkout/insert_order.php

Code: Select all

  $GLOBALS['hooks']->cat('insertOrder', $parameters);
If you have made a new option_value, that activates the custom text, you should be able to just populate the ['options_values'] with the $_SESSION['custom_text'] everywhere necessary. This would however propably limit the input to 250 (or 255 or something like that) characters.
If not, you would need a new field in the cart_table and the orders_products_table, as well as something to show the custom text in your admin.

Bear in mind that you need to sanitize the input to avoid hackers either way.

Hope this makes some kind of sense and is just a little helpful?

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
LeeFoster
VIP Member
VIP Member
Posts: 228
Joined: Sun Feb 28, 2021 9:41 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Product Option - Text

Post by LeeFoster »

Kofod95 wrote: Sat Aug 28, 2021 8:47 pm Not sure at all, but just to try to be helpful:
You should be able to pass it into the $_SESSION['cart'], but you could also make a new $_SESSION['custom_text']. You just have to make sure to insert it into the carts_table, and later into the orders table. That is something I've done before, using the below hook-call from line 140 of includes/system/segments/checkout/insert_order.php

Code: Select all

  $GLOBALS['hooks']->cat('insertOrder', $parameters);
If you have made a new option_value, that activates the custom text, you should be able to just populate the ['options_values'] with the $_SESSION['custom_text'] everywhere necessary. This would however propably limit the input to 250 (or 255 or something like that) characters.
If not, you would need a new field in the cart_table and the orders_products_table, as well as something to show the custom text in your admin.

Bear in mind that you need to sanitize the input to avoid hackers either way.

Hope this makes some kind of sense and is just a little helpful?

//Daniel
This could be exactly the help I need. Do you have an example of doing this you could share?
User avatar
Kofod95
VIP Member
VIP Member
Posts: 605
Joined: Sat Feb 06, 2021 7:38 pm
Has thanked: 80 times
Been thanked: 141 times

Re: Product Option - Text

Post by Kofod95 »

Here: viewtopic.php?f=10&t=409&start=10
The hook

For the session-thing, you could look at includes/actions/add_product.php
I have no good examples for adding it to the cart_table, but I guess it could be found in the shopping_cart class?

Let me know if I should dig deeper :)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
LeeFoster
VIP Member
VIP Member
Posts: 228
Joined: Sun Feb 28, 2021 9:41 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Product Option - Text

Post by LeeFoster »

Thanks @Kofod95 I think it's along the right track but I can't seem to find a hook I can use to put it into the session or the customers_basket table.

Maybe @ecartz can drop by and give some pointers?
LeeFoster
VIP Member
VIP Member
Posts: 228
Joined: Sun Feb 28, 2021 9:41 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Product Option - Text

Post by LeeFoster »

LeeFoster wrote: Thu Aug 26, 2021 8:35 am Not Related but I'm also looking for a way to turn off the qty box on specific products where they will be done as a one off.
This wasn't my main focus but as I wasn't getting too far with the text input, so I switched and got this working this morning. Added a tab in admin to define a one off item and used a hook to hide the input box.
heatherbell
VIP Member
VIP Member
Posts: 1996
Joined: Mon Oct 07, 2019 4:39 am
Has thanked: 26 times
Been thanked: 175 times

Re: Product Option - Text

Post by heatherbell »

LeeFoster wrote: Tue Aug 31, 2021 1:10 pm Maybe @ecartz can drop by and give some pointers?
One of the benefits of being a Pro Supporter is that you can post questions in the VIP PRO Supporters forum where help and support direct from the Core Developers is available.
Maybe you can also share your solution there to benefit others.
Post Reply