X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Extra Fields in Cart using 4.2.2 (https://forum.x-cart.com/showthread.php?t=50417)

icooper 10-28-2009 12:48 PM

Extra Fields in Cart using 4.2.2
 
Hi,

I have been using an extra product field to apply some logic successfully on product list and product pages, but have now got to try and do the same at the cart stage.

I'm OK with the Smarty side of things, but not so up on the PHP side of things. I'm assuming I will need to add an additional query somewhere in a PHP file to make the fields available in a template.

If anyone has done this and can provide any advice and examples of what to add, where and how to pick it up in the template, it would be very much appreciated.

Thanks very much
Ian

icooper 10-29-2009 07:04 AM

Re: Extra Fields in Cart using 4.2.2
 
All sorted with many thanks to mikalou's reply in this thread. :D/

http://forum.x-cart.com/showthread.php?t=40018&highlight=outputting+extra+ fields+on+cart

I was initially looking to retrieve all key fields and select the field I wanted in the template using smarty, but I changed the suggested SQL mod to func.cart.php to also include the extra_fields table, allowing me to retrieve the specific value by service name.

hollaratbear 11-25-2009 01:25 PM

Re: Extra Fields in Cart using 4.2.2
 
I'm having trouble getting this to work in 4.2. Extra field has been created, made the php changes and added info to cart.tpl, but nothing shows. Could you possibly point me in the right direction? Where exactly did you add the info in cart.tpl to make it show?

willieram 01-24-2010 11:05 AM

Re: Extra Fields in Cart using 4.2.2
 
The solution outlined did not work for me as I needed more than one extra field, actually a set of them. You'll have to know a little about smarty, php and SQL to "understand and adapt" though

Here's my mod, it works for 4.3 but ymmv.

Look into module /xcart/include/func/func.cart.php
(on 4.3) around line 1775 you will find the following, add the following code (the one that starts with //@willy

PHP Code:

if ($products_array) {
            
$products_array func_array_merge($product_data$products_array);

//@willy - add extra fields
            
if (!empty($active_modules['Extra_Fields'])) {
                
//var_dump($products_array);
                
$products_ef func_query_hash("SELECT $sql_tbl[extra_fields].*, $sql_tbl[extra_field_values].*, IF($sql_tbl[extra_fields_lng].field != '', $sql_tbl[extra_fields_lng].field, $sql_tbl[extra_fields].field) as field FROM $sql_tbl[extra_field_values]$sql_tbl[extra_fields] LEFT JOIN $sql_tbl[extra_fields_lng] ON $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_fields_lng].fieldid AND $sql_tbl[extra_fields_lng].code = '$shop_language' WHERE $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_field_values].fieldid AND $sql_tbl[extra_field_values].productid = '$productid' AND $sql_tbl[extra_fields].active = 'Y' ORDER BY $sql_tbl[extra_fields].orderby""productid");
                foreach (
$products_ef as $ef) {
                    
$products_array['extra_fields'] = $ef;
                }
                
//echo "<hr>"; var_dump($products_array); exit;
            
}
//@willy - add extra fields 


Then on skin1/customer/main/cart.tpl you could access the extra fields (all of them) like this:

PHP Code:

{$product.extra_fields.0.field}
{
$product.extra_fields.0.value


Change 0 by the index number of your field, which you could find on the extra fields section on the admin side. You could loop them also.

Of course $product is a variable inside a loop on the cart that represents a product of the cart. Look in cart.tpl it's straighforward.

supernovia 04-02-2010 03:28 PM

Re: Extra Fields in Cart using 4.2.2
 
Quote:

Originally Posted by icooper
All sorted with many thanks to mikalou's reply in this thread. :D/

http://forum.x-cart.com/showthread.php?t=40018&highlight=outputting+extra+ fields+on+cart

I was initially looking to retrieve all key fields and select the field I wanted in the template using smarty, but I changed the suggested SQL mod to func.cart.php to also include the extra_fields table, allowing me to retrieve the specific value by service name.


Care to share how you did it? I have been trying to make this work in 4.2.3 to no avail :-/

icooper 04-06-2010 08:30 AM

Re: Extra Fields in Cart using 4.2.2
 
Hi,

I joined the extra_fields table to the query that created the products array in func.cart.php. The query is in the func_products_from_scratch function, and the query is around line 1710 in version 4.2.2.

Quote:

$products_array = func_query_first("SELECT $sql_tbl[products].*, MIN($sql_tbl[pricing].price) as price, $sql_tbl[images_T].image_path, $sql_tbl[images_T].image_x, $sql_tbl[images_T].image_y, IF($sql_tbl[images_P].id IS NULL, '', 'P') as is_pimage, $sql_tbl[images_P].image_path as pimage_path, $sql_tbl[images_P].image_x as pimage_x, $sql_tbl[images_P].image_y as pimage_y, $sql_tbl[extra_fields].service_name as extra_field_name, $sql_tbl[extra_field_values].value as extra_field_value FROM $sql_tbl[pricing],$sql_tbl[products] LEFT JOIN $sql_tbl[images_T] ON $sql_tbl[images_T].id = $sql_tbl[products].productid LEFT JOIN $sql_tbl[extra_field_values] ON $sql_tbl[extra_field_values].productid = $sql_tbl[products].productid LEFT JOIN $sql_tbl[extra_fields] ON $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_field_values].fieldid LEFT JOIN $sql_tbl[images_P] ON $sql_tbl[images_P].id = $sql_tbl[products].productid WHERE $sql_tbl[products].productid=$sql_tbl[pricing].productid AND $sql_tbl[products].forsale != 'N' AND $sql_tbl[products].productid='$productid' AND $avail_condition ".(empty($active_modules['Wholesale_Trading']) ? "$sql_tbl[pricing].quantity = 1" : "$sql_tbl[pricing].quantity<='$amount'")." AND $sql_tbl[pricing].membershipid IN('$membershipid', '0') AND $sql_tbl[pricing].variantid = '$variantid' AND $sql_tbl[extra_fields].service_name = 'EXTRA_FIELD_SERVICE_NAME' GROUP BY $sql_tbl[products].productid ORDER BY $sql_tbl[pricing].quantity DESC");


I've indicated the parts you'll have to modify to suite your requirements.

This allowed me to access the value of the extra field in cart.tpl using '$product.extra_field_value'.

I've not tried it in 4.2.3, so can't vouch for it there I'm afraid, but hope it helps.
Ian


All times are GMT -8. The time now is 03:39 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.