Improve Packer class

Created on 29 September 2023, about 1 year ago
Updated 4 October 2023, about 1 year ago

Problem/Motivation

* The Packer class in this module utilizes the TestBox and TestItem classes in the library, which need to be included with Composer's --dev switch, and which are not auto-loaded
* There is no consideration for the unit type in the dimension and weight calculations

Proposed resolution

* Include copies of those two classes in this module, so the library can be required without the --dev switch and so they can be auto-loaded.

Remaining tasks

* Review code
* Test
* Commit

User interface changes

* This also includes the (modified) code changes for ✨ Implement configurable max weight per package Active , which provide an interface for handling the max weight

API changes

* The class name was changed from Packer to PackagePacker, due to constant "PHP Fatal error: Cannot declare class because the name is already in use" errors

Data model changes

* None

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oadaeh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @oadaeh
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States oadaeh

    Also, this patch makes this module compatible with Drupal 10.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    This looks good. Thanks for your work on this. The only thing I would like you to change is can you put your code in the existing Packer class rather than making a new PackagePacker class?

    On the site where I've used this module, I've extended the Packer class to add some client-specific logic. Since your class is different, I wasn't getting your updates automatically until I changed my custom class to subclass your new one. That seems unnecessary since your new code should be compatible with what we were doing before.

    Otherwise, this seems to work great in my testing.

  • πŸ‡ΊπŸ‡ΈUnited States oadaeh

    Shoot! The PackagePacker class was supposed to replace the Packer class, not add to it.
    I kept getting "PHP Fatal error: Cannot declare class Drupal\commerce_shipping_boxpacker\Packer\Packer because the name is already in use in /web/modules/contrib/commerce_shipping_boxpacker/src/Packer/Packer.php" until I renamed it.

  • πŸ‡ΊπŸ‡ΈUnited States oadaeh

    I figured it out. By adding the the library's Packer class in a use statement, I created a name conflict, so I removed the use statement and directly specified the class where necessary.

  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    Thanks! This looks good, but the new patch doesn't include the max weight per package feature. Can you either add that back in here or make another patch on ✨ Implement configurable max weight per package Active ? That part was good and I don't want to lose it.

  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States oadaeh

    The functionality is still there.

    The new `commerce_shipping_boxpacker.module` file is there.
    The new `config/schema/commerce_shipping_boxpacker.schema.yml` file is there.
    The additional $max_weight code in `src/Packer/Packer.php` is there.

    Is it not working for you?

    I'm also attaching an interdiff, which I should have done previously.

  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    Sorry. You're right. It's there. I must have made a mistake when I tested the second patch.

    I just committed the patch, and I'm going to create a new release now. Thanks so much for your work on this!

  • πŸ‡ΊπŸ‡ΈUnited States scottsawyer Atlanta

    FYI, I think you can avoid the name conflicts by changing:

    use DVDoug\BoxPacker\Packer;
    

    to

    use DVDoug\BoxPacker\Packer as BoxPacker;
    
  • πŸ‡ΊπŸ‡ΈUnited States oadaeh

    Oh, yes, that should work. I totally forgot about it. Thanks for the reminder.

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

Production build 0.71.5 2024