Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong box suggestion #415

Open
sinamaleki opened this issue Jan 31, 2023 · 1 comment
Open

wrong box suggestion #415

sinamaleki opened this issue Jan 31, 2023 · 1 comment

Comments

@sinamaleki
Copy link

sinamaleki commented Jan 31, 2023

Hello and thanks for this great class,

As I'm testing with our boxes and items I can see that class is suggesting C1 box when I'm going to use 1 as the qty and for 2 pieces it's going to suggest B1 box. I'm sure that everything is fine in this class and it's more like a configuration that I'm missing. so usually in our warehouse for this kind of shipments which we have 2 cap, we will ship it with two separate C1 boxes. now I' wondering that how can I change the settings to suggest two C1 box instead of one B1 box when I'm using 2 as qty.
here is our code :

`<?php
require DIR . '/vendor/autoload.php';

use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\Test\TestBox; // use your own Box implementation
use DVDoug\BoxPacker\Test\TestItem; // use your own Item implementation

$packer = new Packer();
$packer->setMaxBoxesToBalanceWeight(0);

/*

  • Add choices of box type - in this example the dimensions are passed in directly via constructor,
  • but for real code you would probably pass in objects retrieved from a database instead
    /
    /

    $packer->addBox(new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000));
    $packer->addBox(new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000));
    */
    //Reliance Boxes
    $packer->addBox(new TestBox('7700 Box', 12.12, 12.12, 3.3, 1, 12.12, 12.12, 3.3, 50));
    $packer->addBox(new TestBox('7736 Box', 12.48, 12.48, 33.07, 1, 12.48, 12.48, 33.07, 50));
    $packer->addBox(new TestBox('7800 Box', 11.63, 11.63, 33.7, 1, 11.63, 11.63, 33.7, 50));
    $packer->addBox(new TestBox('7900 Box', 6.87, 6.87, 46.02, 1, 6.87, 6.87, 46.02, 50));
    $packer->addBox(new TestBox('B1 Box', 9.76, 9.76, 28.19, 1, 9.76, 9.76, 28.19, 50));
    $packer->addBox(new TestBox('B2 Box', 14.88, 14.88, 27.68, 1, 14.88, 14.88, 27.68, 50));
    $packer->addBox(new TestBox('B7 Box', 6.61, 6.61, 33.07, 1, 6.61, 6.61, 33.07, 50));
    $packer->addBox(new TestBox('C1 Box', 7.38, 7.38, 8.19, 1, 7.38, 7.38, 8.19, 15));
    $packer->addBox(new TestBox('C2 Box', 13.39, 13.39, 7.95, 1, 13.39, 13.39, 7.95, 30));
    $packer->addBox(new TestBox('C3 Box', 9.88, 9.88, 4.69, 1, 9.88, 9.88, 4.69, 30));
    $packer->addBox(new TestBox('C5 Box', 8.39, 8.39, 7.32, 1, 8.39, 8.39, 7.32, 30));
    $packer->addBox(new TestBox('Pallet', 48, 48, 48, 62, 48, 48, 48, 1500));

/*

  • Add items to be packed - e.g. from shopping cart stored in user session. Again, the dimensional information
  • (and keep-flat requirement) would normally come from a DB
    */

$packer->addItem(new TestItem('cap', 7, 7, 7, 5, true), 2);

$packedBoxes = $packer->pack();

echo "These items fitted into " . count($packedBoxes) . " box(es)" . PHP_EOL;
foreach ($packedBoxes as $packedBox) {
$boxType = $packedBox->getBox(); // your own box object, in this case TestBox
echo "This box is a {$boxType->getReference()}, it is {$boxType->getOuterWidth()} IN wide, {$boxType->getOuterLength()} IN long and {$boxType->getOuterDepth()} IN high" . PHP_EOL;
echo "The combined weight of this box and the items inside it is {$packedBox->getWeight()}kg" . PHP_EOL;

echo "The items in this box are:" . PHP_EOL;
$packedItems = $packedBox->getItems();
foreach ($packedItems as $packedItem) { // $packedItem->getItem() is your own item object, in this case TestItem
    echo $packedItem->getItem()->getDescription() . PHP_EOL;
}

}

`

thank you so much for your kind help.

@dvdoug
Copy link
Owner

dvdoug commented Feb 5, 2023

Hi @sinamaleki

First, I just want to point out that the library uses integers for all of its dimension calculations, when you pass in floats PHP will silently truncate them (e.g. although you pass in 9.76, the library actually receives 9 from PHP). I recommend you multiply all of your values by 100 to avoid any future issues.

For your actual question - by default the library optimises for the fewest, smallest boxes it can. It can be configured to choose 2 smaller boxes instead of 1 big one if you want, the best way to do that though depends on why you want to - can you explain your reason a little more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants