I have tried to implement a shipping module that utilizes the packaging module, but I haven't been very successful. Packaging returns only a single PackagingPackage object without weight or volume. I would expect a number of packages returned considering the products being passed using

$packages = packaging_package_products($context, $products);

This is what is returned

Array
(
    [0] => PackagingPackage Object
        (
            [quantity:protected] => 0
            [price:protected] => 0
            [weight:protected] => 0
            [weight_units:protected] => KG
            [volume:protected] => 0
            [length_units:protected] => IN
            [shipweight:protected] => 0
            [products:protected] => Array
                (
                )
        )
)
CommentFileSizeAuthor
#2 packaging_commerce-2598334-2.patch1.06 KBjcherbert
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcherbert created an issue. See original summary.

jcherbert’s picture

I found that none of the product object keys are being passed for Commerce Products. This is evident in classes/products.inc in function constructFromCommerceProduct

See attached patch which I believe fixes this issue.

The packaging algorithms can then be invoked using something like:

  $context = new PackagingContext();
  $context->setMaximumPackageWeight(25);
  $context->setMaximumPackageVolume($default_package_volume);
  $context->setDefaultWeightUnits('KG');
  $context->setDefaultLengthUnits('CM');
  $strategy = packaging_get_instance('allinone');
  $context->setStrategy($strategy);
  $products = array();
  foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
    $line_item_weight = commerce_physical_product_line_item_weight($line_item_wrapper->value());
    $line_item_dimensions = commerce_physical_product_line_item_dimensions($line_item_wrapper->value());
    $product = new PackagingProduct();
    $product->setPrice($line_item_wrapper->commerce_unit_price->amount->value());
    $product->setWeight($line_item_weight['weight'] / $line_item_wrapper->quantity->value());
    $product->setWeightUnits(strtoupper($line_item_weight['unit']));
    $product->setDimensions($line_item_dimensions);
    $product->setLengthUnits(strtoupper($line_item_dimensions['unit']));
    $product->setPackageQuantity(1);
    $product->setQuantity($line_item_wrapper->quantity->value());
    $products[] = $product;
 }
 $packages = packaging_package_products($context, $products);  

  • jcherbert committed 54bc881 on 7.x-1.x
    Issue #2598334 by jcherbert: Allow interface with Drupal Commerce by...
jcherbert’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.