PDA

View Full Version : osCmax 2.5.2 & Canada Post - Adding Length, Width, and Height parameters to shopping_cart.php



JRR
10-15-2012, 01:49 PM
I am trying to integrate Canada Post to 2.5.2 (this section is to give the customer a quote) and have determined that the file that needs editing to deal with this is catalog/includes/classes/shopping_cart.php - somewhere around lines 552- so I've tried:

'price' => $products_price,
'quantity' => $this->contents[$products_id]['qty'],
'weight' => (isset($products['products_weight']) ? $products['products_weight'] : ''),
'length' => $products_length,
'width' => $products_width,
'height' => $products_height,
'ready_to_ship' => (isset($products['products_ready_to_ship']) ? $products['products_ready_to_ship'] : ''),
'final_price' => ($products_price + $this->attributes_price($products_id)),

And a few other variations 'xxx' => $products[products_xxx], or 'xxx' => $product[products_xxx], with no success. Checking the log file for the variable products_array I get (using a couple of example products):

Array
(
[0] => Array
(
[id] => 43
[name] => Addams Family Ramp
[model] => Ramp_TAF_Clear
[code] => Ramp_TAF_Clear
[image] => ramps/taf1s.jpg
[discount_categories_id] =>
[price] => 149.0000
[quantity] => 1
[weight] => 0.800
[length] =>
[width] =>
[height] =>
[ready_to_ship] =>
[final_price] => 149
[tax_class_id] => 1
[products_ship_price] =>
[products_ship_price_two] =>
[products_ship_zip] =>
[attributes] =>
)

[1] => Array
(
[id] => 2
[name] => BLUE ESR Meter - KIT
[model] => BLUE_ESR_Kit
[code] => BLUE_ESR_Kit
[image] => kits/BlueESR_Assem.jpg
[discount_categories_id] =>
[price] => 79.9500
[quantity] => 1
[weight] => 0.270
[length] =>
[width] =>
[height] =>
[ready_to_ship] =>
[final_price] => 79.95
[tax_class_id] => 1
[products_ship_price] =>
[products_ship_price_two] =>
[products_ship_zip] =>
[attributes] =>
)

)

This log is created by the following script added just after the previous array:

file_put_contents('log.txt', print_r($products_array, true));

So, my question is - how do I define/extract the required elements (length, width, height) from the products_id or whatever and make sure it is added to products_array?

Note too that ready_to_ship is also blank - it should show either a 0 or a 1, not a blank

Thanks!

FYI - other Canada Post integrations mentioned using a third party to process, unfortunately only work in southern Ontario - about 2000 miles east of my shop...Canada Post now offers an API, but I haven't a clue how to start integrating that!

JRR
10-16-2012, 06:36 PM
OK, the problem is rooted in the upgrades to the shopping_cart.php module related to the add-ons Quantity Price Breaks Per Product (QPBPP) and Separate Pricing Per Customer (SPPC).
The instructions to add the code to add the Canada Post module where I am stuck are:

(from Canada Post module upgrade notes applied to shopping_cart.php) Find:

$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

(from Canada Post module upgrade notes applied to shopping_cart.php) Replace with (added bits are underlined):

$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

The rest of the Canada Post modifications are easy to figure out, it is just this that has me stuck...
The problem is with this section of code in the osCmax 2.5.2 shopping_cart.php (around line 490) - I can't figure out how to add the dimension info into this code:

$products_array = array();
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
// BOF QPBPP for SPPC
$pf->loadProduct($products_id, $languages_id); // does query if necessary and adds to
// PriceFormatterStore or gets info from it next
if ($products = $pfs->getPriceFormatterData($products_id)) {
if (tep_not_null($this->contents[$products_id]['discount_categories_id'])) {
$nof_items_in_cart_same_cat = $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
$nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $this->contents[$products_id]['qty'];
} else {
$nof_other_items_in_cart_same_cat = 0;
}
$products_price = $pf->computePrice($this->contents[$products_id]['qty'], $nof_other_items_in_cart_same_cat);

whereas the original 2.3.1 code is (around line 327):

$products_array = array();
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
if ($products = tep_db_fetch_array($products_query)) {
$prid = $products['products_id'];
$products_price = $products['products_price'];


All I have to do is add p.products_length/width... after p.products_weight in the immediately above code and then I get the passing of the dimensions.
So, how do I insert those dimensions into the oscMax 2.5.2 version that has QPBPP & SPPC added and they have changed the code enough that I can't figure it out...
When I inserted (after editing for Canada Post) the original Oscommerce 2.3.1 version of shopping_cart.php (and used it in place of the osCmax version) I now get the correct length/width/height/ready_to_ship showing up in the log.txt file:

Array
(
[0] => Array
(
[id] => 43
[name] => Addams Family Ramp
[model] => Ramp_TAF_Clear
[image] => ramps/taf1s.jpg
[price] => 149.0000
[quantity] => 1
[weight] => 0.800
[length] => 61.00
[width] => 30.00
[height] => 15.00
[ready_to_ship] => 0
[final_price] => 149
[tax_class_id] => 1
[attributes] =>
)

)

Hope someone has an idea!

Thanks!

pgmarshall
10-16-2012, 10:49 PM
Basically you need to look in catalog/includes/classes/PriceFormatter.php

In osCmax we have replaced all of the hundreds of queries littered all over the place which work out the prices, weight, etc. with a single class called Priceformatter - this allows us to use a single piece of code to construct the output (including the buy now buttons).

Look in the file and you will see a query under //Collect required data

You will then need to add the new data items into the data array - look at lines 99 and 119 for the array construction.

Hope this helps.

Regards.

JRR
10-17-2012, 09:01 AM
Thanks!

However when I edited Priceformatter.php as follows (starting at line 53):

//Collect required data - Added for Canada Post - p.products_length, p.products_width, p.products_height, p.products_ready_to_ship
$sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," .
" p.manufacturers_id, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_quantity," .
" p.products_qty_blocks as qtyBlocks, p.products_min_order_qty, p.products_tax_class_id," .
" NULL as specials_new_products_price," .
" ptdc.discount_categories_id from " . TABLE_PRODUCTS . " p left join (select products_id, discount_categories_id from " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . "" .
" where products_id = '" . (int)$product_id . "' and customers_group_id = '" . $this->cg_id . "') as ptdc on " .
" p.products_id = ptdc.products_id, " .
" " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1'" .
" and pd.products_id = p.products_id " .
" and p.products_id = '" . (int)$product_id . "'" .
" and pd.language_id = '". (int)$language_id ."'";

then again at lines 99 on:

//Compose cachable structure
$price_formatter_data = array(
'products_name' => $product_info['products_name'],
'products_model' => $product_info['products_model'],
'products_image' => $product_info['products_image'],
'products_id' => $product_info['products_id'],
'manufacturers_id' => $product_info['manufacturers_id'],
'products_price' => $product_info['products_price'],
'specials_new_products_price' => $product_info['specials_new_products_price'],
'products_tax_class_id' => $product_info['products_tax_class_id'],
'discount_categories_id' => $product_info['discount_categories_id'],
'products_weight' => $product_info['products_weight'],
'length' => $products['products_length'],
'width' => $products['products_width'],
'height' => $products['products_height'],
'ready_to_ship' => $products['products_ready_to_ship'],
'products_quantity' => $product_info['products_quantity'],
'price_breaks' => $price_breaks_array,
'qtyBlocks' => $product_info['qtyBlocks'],
'products_min_order_qty' => $product_info['products_min_order_qty']);

//Add to cache
$pfs->addPriceFormatterData($product_id, $price_formatter_data);
} else { // data from product listing
//Compose cachable structure
$price_formatter_data = array(
'products_name' => (isset($listing['products_name']) ? $listing['products_name'] : ''),
'products_model' => (isset($listing['products_model']) ? $listing['products_model'] : ''),
'products_image' => (isset($listing['products_image']) ? $listing['products_image'] : ''),
'products_id' => (isset($listing['products_id']) ? $listing['products_id'] : ''),
'manufacturers_id' => (isset($listing['manufacturers_id']) ? $listing['manufacturers_id'] : ''),
'products_price' => (isset($listing['products_price']) ? $listing['products_price'] : ''),
'specials_new_products_price' => (isset($listing['specials_new_products_price']) ? $listing['specials_new_products_price'] : ''),
'products_tax_class_id' => (isset($listing['products_tax_class_id']) ? $listing['products_tax_class_id'] : ''),
'discount_categories_id' => (isset($listing['discount_categories_id']) ? $listing['discount_categories_id'] : ''),
'products_weight' => (isset($listing['products_weight']) ? $listing['products_weight'] : ''),
'products_length' => (isset($listing['products_length']) ? $listing['products_length'] : ''),
'products_width' => (isset($listing['products_width']) ? $listing['products_width'] : ''),
'products_height' => (isset($listing['products_height']) ? $listing['products_height'] : ''),
'products_ready_to_ship' => (isset($listing['products_ready_to_ship']) ? $listing['products_ready_to_ship'] : ''),
'products_quantity' => (isset($listing['products_quantity']) ? $listing['products_quantity'] : ''),
'price_breaks' => $price_breaks_from_listing,
'qtyBlocks' => (isset($listing['qtyBlocks']) ? $listing['qtyBlocks'] : ''),
'products_min_order_qty' => (isset($listing['products_min_order_qty']) ? $listing['products_min_order_qty'] : ''));
//Add to cache
$pfs->addPriceFormatterData($product_id, $price_formatter_data);
}
} // end if (!isset($price_formatter_data))

I did not get the results I wanted - the log.txt still is missing data for length, width...:
Array
(
[0] => Array
(
[id] => 50
[name] => Fun House Main Ramp
[model] => FunHouseMainRamp
[code] => FunHouseMainRamp
[image] => ramps/Funhousemain-3s.jpg
[discount_categories_id] =>
[price] => 129.0000
[quantity] => 1
[weight] => 1.000
[length] =>
[width] =>
[height] =>
[ready_to_ship] =>
[final_price] => 129
[tax_class_id] => 1
[products_ship_price] =>
[products_ship_price_two] =>
[products_ship_zip] =>
[attributes] =>
)

)

Is there a tutorial on inserting mods for QPBPP for SPCC? I'm going hunting for that now...

Thanks again!

pgmarshall
10-17-2012, 10:45 AM
Sorry - I forgot ... you will probably need to add this to catalog/includes/classes/PriceFormatterStore.php $sql query as well.

Regards.

JRR
10-17-2012, 11:20 AM
Ah, but I did add (at least to the only $sql query I could find) starting on line 53 (noted above):

//Collect required data - Added for Canada Post - p.products_length, p.products_width, p.products_height, p.products_ready_to_ship
$sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," .
" p.manufacturers_id, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_quantity," .
" p.products_qty_blocks as qtyBlocks, p.products_min_order_qty, p.products_tax_class_id," .
" NULL as specials_new_products_price," .
" ptdc.discount_categories_id from " . TABLE_PRODUCTS . " p left join (select products_id, discount_categories_id from " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . "" .
" where products_id = '" . (int)$product_id . "' and customers_group_id = '" . $this->cg_id . "') as ptdc on " .
" p.products_id = ptdc.products_id, " .
" " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1'" .
" and pd.products_id = p.products_id " .
" and p.products_id = '" . (int)$product_id . "'" .
" and pd.language_id = '". (int)$language_id ."'";

Or did I miss something?

Thanks!

ridexbuilder
10-17-2012, 12:45 PM
'products_weight' => $product_info['products_weight'],
'length' => $products['products_length'],
'width' => $products['products_width'],
'height' => $products['products_height'],
'ready_to_ship' => $products['products_ready_to_ship'],
'products_quantity' => $product_info['products_quantity'],

Without looking at other code, should that not read? ...

'products_weight' => $product_info['products_weight'],
'length' => $products_info['products_length'],
'width' => $products_info['products_width'],
'height' => $products_info['products_height'],
'ready_to_ship' => $products_info['products_ready_to_ship'],
'products_quantity' => $product_info['products_quantity'],

JRR
10-17-2012, 01:39 PM
Yes, you are quite correct (opps!), it should have had the "_info" included.

Done, tested, didn't work, re-read all notes above...

Urk, just noticed that I had not edited catalog/includes/classes/PriceFormatterStore.php $sql query, rather I had only edited catalog/includes/classes/PriceFormatter.php $sql query -

So, let's see what happens now...

IT WORKS!!! Dimensions are now passed as they should be!

Cool, thanks for your help!

I may be posting some edits in the osCmax docs later to reflect this info you shared with me so others may possibly find it.

Rats!

pgmarshall
10-17-2012, 02:00 PM
Why not post the changes into the wiki incase anyone else wants to install Canada Post ... or even post the changes into the bugtracker and we could look at adding it to the core code.

Glad you got it working ...

Regards.

JRR
10-17-2012, 02:28 PM
Well, once I get it fully functional I will add it to the Wiki (didn't think it was really a bug, so hadn't considered putting anything there) - so far I have the front end (customer side), next I have to figure out the backend issues (admin side).

Another problem is this module only works for people/businesses (like my company) that already have a Canada Post CP_CID account. They have changed their system so an API is required for any new people (companies) to join up, so no more CP_CIDs it seems. Canada Post has a developer site (https://www.canadapost.ca/cpo/mc/business/productsservices/developers/tour/forecommerce.jsf) and they have sample programs in both PHP and JAVA for something called REST (https://www.canadapost.ca/cpo/mc/business/productsservices/developers/codesamples.jsf) and SOAP (https://www.canadapost.ca/cpo/mc/business/productsservices/developers/soap/codesamples.jsf), however I know nothing about APIs, so (for now) am using the older Canada Post modules developed for osCommerce 2.0.x

More to come, so stay tuned!

JRR
10-17-2012, 02:57 PM
Quick question, I don't see a file in admin/includes/classes similar to the PriceFormatter ones, and I get distorted search tabs (actually they are stacked one on top of the other) on the top of the ship_canadapost module when it is used with orders.php.
I've been editing the following files to fit in the older version (for ship_canadapost.php's needs) to admin - it works (mostly) but needs some tuning:

catalog/admin/includes/functions/html_output.php
catalog/admin/includes/functions/general.php
catalog/admin/includes/filenames.php
catalog/admin/includes/languages/english/orders.php
catalog/admin/orders.php
catalog/admin/manufacturers.php
catalog/admin/includes/languages/english/manufacturers.php
catalog/admin/categories.php
catalog/admin/includes/classes/order.php
catalog/admin/includes/classes/shopping_cart.php

Is there a master file as there is using PriceFormatter?

Thanks!

pgmarshall
10-17-2012, 03:58 PM
You need to edit the admin files to use the osCmax header ... take a look at other admin files ... copy everuthing down to <body> - should work depending on module.

Regards,

JRR
10-17-2012, 10:15 PM
Thanks, I put:

<?php
require('includes/application_top.php');

if (isset($_GET['setasdefault'])) {
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $_GET['setasdefault'] . "' where configuration_key = 'INDEX_TAB'");
// Configuration Cache modification start
require ('includes/configuration_cache.php');
// Configuration Cache modification end
tep_redirect(tep_href_link(FILENAME_DEFAULT));
}

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/javascript/jquery-ui-1.8.2.custom.css">
<script type="text/javascript" src="includes/general.js"></script>
</head>
<body>
<?php

at the top of ship_canadapost.php as you suggested (that added bit is taken from /admin/index.php) and now the search tabs and search box look correct. On to the next problem...

JRR
10-18-2012, 10:38 AM
I was mistaken about Canada Post dropping the Sell Online system for Canadian small businesses/retailers. Just got this note from them:

Hello,

We are in fact still accepting new Sell Online customers and creating new retailer ID'S. The Sell Online program will also continue to be fully supported as it has been. The only change is the introduction of the Developer Program which supports several new API's using modern XML in SOAP and REST architecture. This allows for greater flexibility and customization as well as automating the creation of labels and adding tracking services directly on your website. Though this new program has been introduced and many ecommerce suppliers and platforms are moving to the Developer Program, the Sell Online program will continue to run and there have been no announcements regarding an end to support.

Regards,

Sell Online Helpdesk

1-866-511-0546

So with that cleared up I will indeed be happy to write up my adventures in adding the Canada Post module to osCmax 2.5.X once I have the bugs worked out.

John :-#)#

ridexbuilder
10-18-2012, 01:22 PM
..which supports several new API's using modern XML in SOAP and REST architecture.
SOAP is also used with some other modules, so these days including it in Apache builds is more commonplace.

As well as showing GD library as a prerequisite, we should display Imagemagik and SOAP as being desirable, during the osCmax installation, IMO

EJ

JRR
10-18-2012, 01:41 PM
Quite interesting, however I am not a programmer so can't do the implementation myself. At best I can modify code after I figure out what the offending/interesting section is. So, at the moment, I'll have to leave that to some smart person to do... and I know at least one person has been working on doing that for oscommerce 2.3.x, but I really do have enough projects on the fire with getting Canada Post working well enough to finish converting my store to 2.5.x.