Jump to content

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


Daamon

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.

Link to comment
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.

Link to comment
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!

Link to comment
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

Link to comment
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.

Link to comment
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).

 

Link to comment
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.

Link to comment
Share on other sites

  • 4 months later...
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...