Skip to content

Commit

Permalink
fix(shipments): prevent mailbox when too heavy (#57)
Browse files Browse the repository at this point in the history
INT-313
  • Loading branch information
joerivanveen authored Dec 22, 2023
1 parent 77c33f1 commit 0ae4614
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/Service/Consignment/ConsignmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,19 @@ public function createConsignment(

$consignment->setLabelDescription($this->createLabelDescription($orderEntity, $shippingDate));

// Not in europe
if (!in_array($shippingAddress->getCountry()->getIso(),AbstractConsignment::EURO_COUNTRIES)) {
//Add weight of all items for international shipping
/** @var OrderLineItemEntity $lineItem */
foreach ($orderEntity->getLineItems() as $lineItem) {

$isRow = !in_array($shippingAddress->getCountry()->getIso(),AbstractConsignment::EURO_COUNTRIES);
$totalWeight = 0;
/** @var OrderLineItemEntity $lineItem */
foreach ($orderEntity->getLineItems() as $lineItem) {
if ($isRow) {
$customsItem = new MyParcelCustomsItem();
if ($lineItem->getProduct() && $lineItem->getProduct()->getWeight()) {
$customsItem->setWeight($lineItem->getProduct()->getWeight() * 1000);
if ($lineItem->getProduct()
&& $lineItem->getProduct()
->getWeight()) {
$customsItem->setWeight(
$lineItem->getProduct()
->getWeight() * 1000
);
} else {
$customsItem->setWeight(0.01);
}
Expand All @@ -261,7 +265,7 @@ public function createConsignment(
}
//Get custom field HS code
$customFields = $lineItem->getPayload()['customFields'];
$hsCode = $this->systemConfigService->getString('MyPaShopware.config.myParcelFallbackHSCode');
$hsCode = $this->systemConfigService->getString('MyPaShopware.config.myParcelFallbackHSCode');

if ($customFields && array_key_exists('myparcel_product_hs_code', $customFields)) {
$hsCode = $customFields['myparcel_product_hs_code'];
Expand All @@ -270,12 +274,18 @@ public function createConsignment(
throw new ConfigFieldValueMissingException();
}

$customsItem->setClassification(intval($hsCode));
$customsItem->setClassification((int) $hsCode);

$consignment->addItem($customsItem);

$totalWeight += $customsItem->getWeight() * $customsItem->getAmount();
} elseif ($lineItem->getProduct()) {
$totalWeight += $lineItem->getQuantity() * $lineItem->getProduct()->getWeight() * 1000;
}
}

$consignment->setTotalWeight(min($totalWeight, 30000));

if (
$shippingOptions->getDeliveryDate() !== null
&& is_int($shippingOptions->getDeliveryType())
Expand All @@ -300,21 +310,6 @@ public function createConsignment(
$consignment->setPackageType($packageType);
}

if ($consignment->getPackageType() == AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP) {

$totalWeight = 0;
$lineItems = $orderEntity->getLineItems();
if ($lineItems) {
foreach ($lineItems as $lineItem) {
$totalWeight += $lineItem->getProduct()->getWeight();
}
//Shopware uses KG for weight, MyParcel wants Grams
$totalWeight = $totalWeight * 1000;
}

$consignment->setTotalWeight($totalWeight);
}

if ($shippingOptions->getRequiresAgeCheck() !== null) {
if ($consignment instanceof DPDConsignment) {
$consignment->setAgeCheck(false);
Expand Down

0 comments on commit 0ae4614

Please sign in to comment.