Replies: 2 comments 4 replies
-
Hi @gurji999 If you're still working out classes, this is probably going to be a little tough for you - the first question I would have is are you only packing batteries, or are you packing a mixture of batteries and not-batteries, as that will influence things a bit. BoxPacker works with To make the battery example work, it's not enough to use the You can write any kind of check you need, this is why BoxPacker works on the interfaces (templates) and not the actual classes, this gives people like you the ability to write the custom code you need to handle your particular scenarios. Only you know whether your particular item is a battery or has any other kind of hazard, and only you know how many can go into a box. |
Beta Was this translation helpful? Give feedback.
-
Following up on this. Is it possible to have multiple constrained items but with different limits? |
Beta Was this translation helpful? Give feedback.
-
Hey, I am trying to implement this. I have everything working the way I want, however, I can't quite figure out how to implement this: https://boxpacker.io/en/stable/custom-constraints.html
I run the packer with all the items in the shopping cart, and it returns the boxes with each of the items placed in their boxes. However, if I have batteries, I don't want more than 2 per box. I need the system to spread them across the boxes, and even add a box if needed.
But I am not sure exactly how to implement this. Keep in mind, I am relatively new with PHP, I have a good knowledge of it, but I haven't quite grasped how classes work yet. So please dumb it down for me a little.
This is a sample of what I am using right now. It is based on your docs.
`<?php
header("Content-Type:application/json; charset=utf-8");
require_once('vendor/autoload.php');
use DVDoug\BoxPacker\Rotation;
use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\Test\TestBox; // use your own
Box
implementationuse DVDoug\BoxPacker\Test\TestItem; // use your own
Item
implementation##################################################################
$packer->addBox(
new TestBox(
reference: 'Le petite box',
outerWidth: 300,
outerLength: 300,
outerDepth: 10,
emptyWeight: 10,
innerWidth: 296,
innerLength: 296,
innerDepth: 8,
maxWeight: 50
)
);
$packer->addBox(
new TestBox(
reference: 'Le grande box',
outerWidth: 3000,
outerLength: 3000,
outerDepth: 100,
emptyWeight: 10,
innerWidth: 2960,
innerLength: 2960,
innerDepth: 80,
maxWeight: 50
)
);
$packer->addItem(
item: new TestItem(
description: 'Item 1',
width: 0,
length: 0,
depth: 0,
weight: 27,
allowedRotation: Rotation::BestFit
),
qty: 2
);
$packer->addItem(
item: new TestItem(
description: 'Item 2',
width: 0,
length: 0,
depth: 0,
weight: 28,
allowedRotation: Rotation::BestFit
),
qty: 2
);
$packer->addItem(
item: new TestItem(
description: 'Item 3',
width: 0,
length: 0,
depth: 0,
weight: 26,
allowedRotation: Rotation::BestFit
),
qty: 1
);
###############################################
try {
$packedBoxes = $packer->pack();
} catch (NoBoxesAvailableException $e) {
$affectedItems = $e->getAffectedItems();
}
print_r($affectedItems);
########################HOW IT WAS PACKED########################################
echo "These items fitted into " . count($packedBoxes) . " box(es)" . PHP_EOL;
print_r($packedBoxes);
`
Beta Was this translation helpful? Give feedback.
All reactions