Zen Cart Logo
Forums / Code Collaboration / Adding custom data to $SESSION['cart']

Adding custom data to $SESSION['cart']

Views: 1,774

Results 1 to 3 of 3
3 May 2017, 7:40 AM
#1
kuya avatar

kuya

New Zenner

Join Date:
Jul 2016
Location:
Philippines
Posts:
6
Plugin Contributions:
0

Adding custom data to $SESSION['cart']

ZC Version: 1.5.5a
PHP version: 7.0
MySQL version: 5.5.54-cll
Template: responsive_classic
Plugins:
Tabbed Products Pro v1.20
Zen Colorbox
Additional Image Swapper
and
some self created shipping & payment modules specific to my locale

The end result I want to achieve:

Each product has an associated "Point Value" (PV). I want to...

  1. See that PV listed on the "View Cart" page
  2. See the "Total PV" for all items ordered
  3. Record the per item PV into the "orders_products" table
  4. Record the "Total PV" in the "orders" table.

What I have done to date (successfully)...

  1. Added the field "products_point_value" to the "products" table
  2. Added the ability to add/edit the value per product in my back office
  3. Show the product PV on the shop product listing and detail pages (only if the user is logged in)

Where I am at now...

  1. Added table column (with associated language definitions) to the "view cart" page (includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php) headings along with Qty, Item Name, Unit & Total ```
<th scope="col" id="scUnitPointValue"><?php echo TABLE_HEADING_POINT_VALUE; ?></th> ``` 2) Added table column to display the PV on the "view cart" page (includes/templates/responsive_classic/templates/tpl_shopping_cart_default.php) ``` <td class="cartUnitDisplay"><?php if ( $detect->isMobile() && !$detect->isTablet() || $_SESSION['layoutType'] == 'mobile' or $detect->isTablet() || $_SESSION['layoutType'] == 'tablet' ) {echo '<b class="hide">' . TABLE_HEADING_POINT_VALUE . ':  </b>'; } ?><?php echo $product['productsPointValue']; ?></td> ``` 3) Added ``` $productsPointValue = $products[$i]['products_point_value']; ``` under ``` $productsPriceTotal = $currencies->format($ppt) ... ``` to the file (includes/modules/pages/shopping_cart/header_php.php) around line 152 4) Added ``` 'productsPointValue'=>$productsPointValue, ``` to the "productArray" above "productsPrice" in the file (includes/modules/pages/shopping_cart/header_php.php) around line 170 5) Added the field "order_total_point_value" to the table "orders" 6) Added the field "products_point_value" to the table "orders_products"

What I don't know...

  1. Where is the db query that gets the per product data to be added to the cart? I think I need to add "products_point_value" to that select statement in order to get it's value
  2. I believe #3 & 4 (above) will add the PV to the session cart array once the select statement is updated. Or am I incorrect?
  3. Then I need to figure out how to have the per product PV totaled and displayed.

I can't move forward to submitting the order (checkout process) until I can successfully have these "PV" values (per product and total) added to the cart array and displayed on the "view cart" page.

I hope someone can point me in the right direction.

Cheers,
John

3 May 2017, 2:15 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding custom data to $SESSION['cart']

/includes/classes/shopping_cart.php
line 1206 - after this line add your custom field to the query, followed by a comma

                                  p.product_is_free, p.products_priced_by_attribute,

line 1376 - duplicate this and add your custom field

                                  'product_is_free' => $products->fields['product_is_free'],
4 May 2017, 9:52 AM
#3
kuya avatar

kuya

New Zenner

Join Date:
Jul 2016
Location:
Philippines
Posts:
6
Plugin Contributions:
0

Re: Adding custom data to $SESSION['cart']

Thank you so much DrByte. Worked like a charm. :)

Now to tackle totaling the PV for all items in the cart, storing that total in the array and displaying it to the customer.

Off-Topic... is there a timeframe for the ability to "override" files in the YOUR-Admin_DIRECTORY ?

Cheers, John