Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Extra Fields in Cart using 4.2.2

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-28-2009, 12:48 PM
 
icooper icooper is offline
 

Newbie
  
Join Date: Jul 2009
Posts: 3
 

Default 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
__________________
X-Cart Gold 4.2.2
http://www.themissingdimension.com

Last edited by icooper : 10-29-2009 at 07:06 AM. Reason: Solved
Reply With Quote
  #2  
Old 10-29-2009, 07:04 AM
 
icooper icooper is offline
 

Newbie
  
Join Date: Jul 2009
Posts: 3
 

Default Re: Extra Fields in Cart using 4.2.2

All sorted with many thanks to mikalou's reply in this thread.

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.
__________________
X-Cart Gold 4.2.2
http://www.themissingdimension.com
Reply With Quote
  #3  
Old 11-25-2009, 01:25 PM
 
hollaratbear hollaratbear is offline
 

Advanced Member
  
Join Date: Nov 2009
Posts: 37
 

Default 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?
__________________
hollaratbear
Xcart Gold 4.2.1 Newbie
Reply With Quote
  #4  
Old 01-24-2010, 11:05 AM
 
willieram willieram is offline
 

Newbie
  
Join Date: Jan 2010
Posts: 6
 

Default 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.
__________________
Willie
Reply With Quote

The following 2 users thank willieram for this useful post:
alinush (10-03-2015), matallen (03-26-2010)
  #5  
Old 04-02-2010, 03:28 PM
  supernovia's Avatar 
supernovia supernovia is offline
 

Advanced Member
  
Join Date: Jun 2009
Location: Utah
Posts: 32
 

Default 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.

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 :-/
__________________
Velda Christensen
http://www.novapages.com
Reply With Quote
  #6  
Old 04-06-2010, 08:30 AM
 
icooper icooper is offline
 

Newbie
  
Join Date: Jul 2009
Posts: 3
 

Default 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
__________________
X-Cart Gold 4.2.2
http://www.themissingdimension.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:06 AM.

   

 
X-Cart forums © 2001-2020