Jump to content

Archived

This topic is now archived and is closed to further replies.

Daamon

[Resolved] Add fields for a specific product - which database table?

Recommended Posts

Hi,

My second post and I'm totally new to CubeCart... For a small set of specific products within my shop, I want to have a number of mandatory fields appear when any one of those products are ordered and on a "per product" basis, i.e. if more than any one of these products is purchased in a single transaction these fields appear for each product in the transaction.

I want the data captured in these fields to be recorded as part of the order details, not the customer.

My questions:

1) Which table(s) in the phpMyAdmin area would the new fields need to be added to? Any tips on some of the more unusual field options (e.g. I get "mandatory", but others?) when creating them...

2) I know I'll need some PHP coding to have the fields appear (getting that sorted) and I think it'd be best to have that occur in the "Basket" stage of the purchase. Which PHP file(s) would be the ones to change the code in?

3) It'd be great if I could have this mandatory data appear in the CubeCart Admin Control Panel -> Orders -> Overview tab - Order Summary. I'm guessing this would be PHP code changes too - again, which file(s)?

Many thanks in advance.

Share this post


Link to post
Share on other sites

I am thinking the most likely approach is in admin:

1. Product Options: Option Groups tab, Add new group of a textbox type. Make it 'Required'.
2. Edit a product. On the Options tab, for Add new option, select the textbox just created. Fill in the rest (Negative, Price, etc) and click the green circle with the white plus in it to add it to the list of options. Click the Save and Reload button.
3. Make sure this new option is enabled in the product's list of options.

Make it plain in the product's description that the customer must only order a quantity of one so that unique entries in the textbox would apply to each individual item placed in the basket.

Cubecart does a good job of keeping separate the unique line items in the shopping basket based on the options selected, but will join exactly the same option sets to a total of that line item. That is, if I add a small green widget embossed with "SuperDad", then add another small green widget embossed with "SuperMom", then add a large blue widget embossed with "SuperDad", there will be three individual items in the shopping basket. Another small green widget embossed with "Superdad" will now have two of those in the shopping basket.

All the options chosen when placing an item in the shopping basket is shown everywhere. (Ok, maybe for CC608, maybe not, but certainly for CC6010.)

To capture custom data that pertains to the inventory of an order, that data could be stored in the CubeCart_order_inventory table. An easier location would be part of the "Cart" class's '_basket' property. You can stick anything in Cart->_basket. It will end up in CubeCart_order_summary, 'basket' column.

The skin template to show custom data will be in /templates/ and are content.checkout.*.php. The asterisk represents 'small', and 'medium-up'. (Depends on the browser viewport size.)

The admin skin templates would be orders.index.php and orders.print.php.

Even though the templates end in php, the templates are actually written in HTML.

Share this post


Link to post
Share on other sites

Hi bsmither,

Thank you! Superstar!

I followed points 1 - 3 and, in the basket, gave me exactly what I was after. But it 10 minutes and I didn't need any PHP coding or setting up new fields / tables in the database - sooooo much easier! Fantatstic!

Regarding your info from "To capture custom data..." onwards - I wasn't clear on what that meant and was going to ask for more info, but luckily took a look at CubeCart Admin Control Panel -> Orders -> Inventory tab and the fields are there (blank) for existing orders so I'm assuming they'll be populated now they're in place.

Thank you so much!

Share this post


Link to post
Share on other sites

Sounds like you're pleased with the results, so I'll mark this as Resolved. But if you run into any issues once you start actually populating your products and options, feel free to continue this thread, and I'll take the Resolved off for the time being.

Share this post


Link to post
Share on other sites

Hi. We've now had a "live" customer come through and we are, indeed, happy(ish) with the results. I say "ish" because we are now capturing the information we really need to have, but it's not where we expected it - attached screen shots will explain...

- The newly captured data is appearing in an semi-formatted, concatenated way in the Order Summary. It's usable, but not pretty

- It's not appearing in the Order Inventory screen - which would be nicer and more user friendly.

Given that bsmither "may" have described how to achieve this above, if that's the solution can someone explain it in more layman's terms assuming less knowledge - particularly for the paragraph "To capture custom data ..." onwards, which folders the various files are in, and which files(?) the properties are in? I'm sure I can figure out "how" to change things once I know where those things are...

Cheers!

1_summary_screen.jpg

2_inventory_screen.jpg

Share this post


Link to post
Share on other sites

"Regarding your info from "To capture custom data..." onwards - I wasn't clear on what that meant."

The explanation from that point on was a direct response on discussing your original three questions about custom data. Because I offered a likely alternative, which seems to work for you, I think we can dispense with the "custom data" approach.

From your image, there are two things to fix: the formatting of the options (each option with response on its own line), and the missing responses to the options on the Order Inventory tab.

More later.

Share this post


Link to post
Share on other sites

In the file /admin/skins/default/templates/element.product_options.php:

For CC608:
Line 33:
From:
   <textarea  class="text_calc" name="inv[{$product.id}][productOptions][{$option.option_id}][{$OPT.assign_id}]" rel="{$option.symbol}{$option.decimal_price}" placeholder="{if $option.price}({$option.symbol}{$option.price}){/if}" id="option_{$option.option_id}">{$option.value}</textarea>

To:
   <textarea  class="text_calc" name="inv[{$product.id}][productOptions][{$option.option_id}][{$option.assign_id}]" rel="{$option.symbol}{$option.decimal_price}" placeholder="{if $option.price}({$option.symbol}{$option.price}){/if}" id="option_{$option.option_id}">{$option.value}</textarea>

This edit is in CC609 and later. But reports are there is still some kind of problem.

Please make the above edit and test, especially when you move the order to Completed.

In the file /admin/sources/orders.index.inc.php:

For CC608:

Find near line 289:
$product['options_text'] = implode(' ', cc_unserialize($product['product_options']));

Change to:
$product['options_text'] = implode('\n', cc_unserialize($product['product_options']));

This edit separates each option with a new line instead of a space. However, web browser do not honor line breaks in the source code. So, this next edit will have the skin template substitute the HTML code <br> for the new lines.

In the file /admin/skins/default/templates/orders.index.php:

For CC608:

Find near line 173:
<br>{$product.options_text}

Change to:
<br>{$product.options_text|nl2br}

Because changes were made to templates, it is a good idea to clear the skin template cache (admin, Maintenance, Rebuild tab, Clear Cache).

 

Share this post


Link to post
Share on other sites

Hi bsmither,

Thanks for picking this up again, and for the detailed instructions. I've made (and saved) the edits to the three files, I also did the "Clear Cache" you suggested - ticking all 4 boxes under "Cache" and then "Submit". Unfortunately not achieving the desired results - not at first, at least, but your suggestions gave me an idea and I had a little play...

The outcome:

1) The "Order Summary" tab (new) entries are now "separated" by a \n - I tested out changing this in the "orders.index.inc.php" file to something different, refreshed the page and seen my test change come through. I also tried a /n in case it was a typo - this was displayed too, no "new line" separation.

Being curious, I tried <br> instead of \n - and that worked... Woo hoo! It looks good.

2) The "Order Inventory" tab has no entries, as before. However, given the outcome in 1), I reckon the people who are using these changes will be happy with that. The status of the orders I'm looking at is Processing or Pending, none are Order Complete. Could it be this? If we can get this working, it'd be great.

Thanks so much for your help - very much appreciated.

Share this post


Link to post
Share on other sites

Completely off topic - but @Daamon I LOVE your signature! It fits my knowledge level perfectly!!!

I removed the Resolved for now.

Share this post


Link to post
Share on other sites
On 3/14/2016 at 8:55 PM, Daamon said:

2) The "Order Inventory" tab has no entries, as before. However, given the outcome in 1), I reckon the people who are using these changes will be happy with that. The status of the orders I'm looking at is Processing or Pending, none are Order Complete. Could it be this? If we can get this working, it'd be great.

This has been resolved. Details, courtesy of a LOT of help and investigation by @bsmither:

In the skins/mican/templates folder the Mican template file content.product.php, lines 86-90, where productOptions are being populated, the variable used is {$OPT.assign_id} but should be {$option.assign_id}.

A bug report has been filed: https://github.com/cubecart/v6/issues/1196

Apparently, this issue may well be present in a number of CC5 front-end skins.

Share this post


Link to post
Share on other sites

×
×
  • Create New...