function uc_shipping_package_save in Ubercart 7.3
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_package_save()
- 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_package_save()
Saves a package.
3 calls to uc_shipping_package_save()
- uc_shipping_new_package_submit in shipping/
uc_shipping/ uc_shipping.admin.inc - Submit handler for uc_shipping_new_package().
- uc_shipping_package_edit_submit in shipping/
uc_shipping/ uc_shipping.admin.inc - Submit handler for uc_shipping_package_edit().
- uc_shipping_shipment_save in shipping/
uc_shipping/ uc_shipping.module - Saves a shipment.
File
- shipping/
uc_shipping/ uc_shipping.module, line 445 - Organizes ordered products into packages and sets them up for shipment. Shipping method modules may add functionality to generate shipping labels and tracking numbers.
Code
function uc_shipping_package_save($package) {
$package = (object) $package;
if (!isset($package->package_id)) {
$package->package_id = db_insert('uc_packages')
->fields(array(
'order_id' => $package->order_id,
))
->execute();
}
if (isset($package->products) && $package->products) {
$insert = db_insert('uc_packaged_products')
->fields(array(
'package_id',
'order_product_id',
'qty',
));
foreach ($package->products as $id => $product) {
$insert
->values(array(
'package_id' => $package->package_id,
'order_product_id' => $id,
'qty' => $product->qty,
));
$result = db_query("SELECT data FROM {uc_order_products} WHERE order_product_id = :id", array(
':id' => $id,
));
if ($order_product = $result
->fetchObject()) {
$order_product->data = unserialize($order_product->data);
$order_product->data['package_id'] = intval($package->package_id);
db_update('uc_order_products')
->fields(array(
'data' => serialize($order_product->data),
))
->condition('order_product_id', $id)
->execute();
}
}
db_delete('uc_packaged_products')
->condition('package_id', $package->package_id)
->execute();
$insert
->execute();
}
$fields = array(
'order_id' => $package->order_id,
'shipping_type' => $package->shipping_type,
);
if (isset($package->pkg_type)) {
$fields['pkg_type'] = $package->pkg_type;
}
if (isset($package->length) && isset($package->width) && isset($package->height) && isset($package->length_units)) {
$fields['length'] = $package->length;
$fields['width'] = $package->width;
$fields['height'] = $package->height;
$fields['length_units'] = $package->length_units;
}
if (isset($package->value)) {
$fields['value'] = $package->value;
}
if (isset($package->sid)) {
$fields['sid'] = $package->sid;
}
if (isset($package->tracking_number)) {
$fields['tracking_number'] = $package->tracking_number;
}
if (isset($package->label_image) && is_object($package->label_image)) {
$fields['label_image'] = $package->label_image->fid;
}
db_update('uc_packages')
->fields($fields)
->condition('package_id', $package->package_id)
->execute();
}