Good evening,
how can I, when an order is placed and the record is created in order_data, also store an information about the items from a custom field that exists in the products table?
Do I have to modify a schema file?
Good evening,
how can I, when an order is placed and the record is created in order_data, also store an information about the items from a custom field that exists in the products table?
Do I have to modify a schema file?
Hi!
Have you checked the data in the cscart_order_details table? It should already contain all the data for the products in the order.
The data i need are custom fields in product table
Are you referring to this notification(s)? Please be more specific - including screenshots - in what exactly is the issue you try to resolve.
You can use the add_to_cart
hook and add the necessary data into the $cart[‘products’][$_id][‘extra’] array. Then you will be able to find it in the cscart_order_details table in the extra column, serialized. The example of a “brute-force” solution via my_changes add-on:
func.php
<?php
use Tygh\Tygh;
function fn_my_changes_add_to_cart(&$cart, $product_id, $_id)
{
$auth = Tygh::$app['session']['auth'];
$cart['products'][$_id]['extra'] = fn_get_product_data($product_id, $auth);
}
init.php
<?php
fn_register_hooks('add_to_cart');
Thanks for your help.
Is this right,
function fn_my_changes_add_to_cart(&$cart, $product_id, $_id)
{
$auth = Tygh::$app['session']['auth'];
$product_data = db_get_row(
"SELECT availability_label, availability_dur FROM ?:products WHERE product_id = ?i",
$product_id
);
$cart['products'][$_id]['extra'] = [
'availability_label' => $product_data['availability_label'],
'availability_dur' => $product_data['availability_dur'],
];
}```
Yes, that looks to be correct.
Nice, it works for me…
How can i add this extra info to the document invoice template that we send to customer via email?
<table>
<tbody>
<tr>
<td style="padding-right: 20px;" rowspan="2">{{ p.image }}</td>
<td style="vertical-align: middle; text-align: left;"><span style="font-family: Helvetica, Arial, sans-serif; text-transfrom: uppercase;"><strong style="font-weight: 600;">{{ p.name }}</strong></span></td>
</tr>
<tr>
<td style="vertical-align: top; text-align: left;"><span style="font-size: 11px; font-weight: 400; font-family: Helvetica, Arial, sans-serif; color: #a8a8a8;">{% if p.product_code %}{{ p.product_code }}<br> {% endif %}{% if p.options %}{{ p.options }}<br>{% endif %}extra info..</span></td>
</tr>
</tbody>
</table>
The modification for this part is much more complex. You can look at the app/schemas/snippets/order_products_table.php
schema to familiarize yourself with how it works and how to modify it.