Hey All,
I'm trying to add a checkbox in the products page. Later at checkout I want to calculate shipping costs for when all products in the cart have that checkbox filled out.
So I'm trying to kinda copy the 'product is shippable' checkbox and it's functions here. I managed to get the checkbox into the products page, but it won't save the selection I make. I'm adjusting a test installation of UC.
I've added this in uc_product.module :
<?php
$form['base']['dimensions']['sizecheck'] = array(
'#type' => 'checkbox',
'#title' => t('Product is smaller than 35x23x3 cm.'),
'#default_value' => isset($node->sizecheck) ? $node->sizecheck : FALSE,
'#weight' => 9,
);
?>In uc_product.install :
<?php
//after $schema['uc_product_features'] = array(
'sizecheck' => array(
'description' => t('Boolean flag signifying that the product is small.'),
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
// wherever I saw a function with 'shippable' in it, I copied it to make it 'sizecheck' :
// Update to add the sizecheck column to the product table.
function uc_product_update_13() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_products} ADD sizecheck tinyint(2) NOT NULL default 0");
break;
case 'pgsql':
db_add_column($ret, 'uc_products', 'sizecheck', 'tinyint', array('not null' => TRUE, 'default' => 0));
break;
}
return $ret;
}
//added this to function uc_product_update_6000() {
db_change_field($ret, 'uc_products', 'sizecheck', 'sizecheck', array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
?>In uc_order.ca.inc I added this:
<?php
//in the function: function uc_order_ca_condition() {
$conditions['uc_order_condition_sizecheck'] = array(
'#title' => t('Check if all the products are categorised as small'),
'#category' => t('Order: Product'),
'#description' => t('Returns TRUE if all the products in the order are categorised as small.'),
'#callback' => 'uc_order_condition_sizecheck',
'#arguments' => array(
'order' => $order_arg,
),
);
//and separate:
function uc_order_condition_sizecheck($order, $settings) {
return uc_order_sizecheck($order);
}
?>That uc_order_sizecheck() function is located in uc_order.module:
<?php
//i tweaked it to this. In the 'shippable' function there was some other stuff going on that i didn't understand.
function uc_order_sizecheck($order) {
if (!is_array($order->products) || empty($order->products)) {
return FALSE;
}
foreach (
$order->products as $product) {
// Return FALSE if the product form specifies this as not checked.
if ($product->data['sizecheck'] == FALSE) {
$results[] = FALSE;
continue;
}
else{
$results[] = TRUE;
continue;
}
}
return !
in_array(FALSE, $results);
}
?>I also manually added a spot in the database for my 'sizecheck' data, right next to 'shippable'. It doesn't seem to connect to the DB yet, though.
And I don't understand how I'm suppost to know what variables i can call with that $product object. If this wasn't a function, I think i could figure out, but a function won't let me echo anything.
Any support is very appreciated !
Many thanks in advance.
Cheers,
Danny
Ps: I started to build this because I'm stuck with my other attempt as well: http://www.ubercart.org/forum/support/12504/flatrate_based_dimensions . All help is also very welcome there.


