Skip to content

Commit

Permalink
feat(order): support digital stamp weight range option (#1035)
Browse files Browse the repository at this point in the history
INT-170
  • Loading branch information
EdieLemoine authored Oct 13, 2023
1 parent 4fade9a commit f9aeb23
Show file tree
Hide file tree
Showing 9 changed files with 1,277 additions and 1,314 deletions.
38 changes: 1 addition & 37 deletions src/Pdk/Plugin/Repository/PdkOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use MyParcelNL\Pdk\App\Order\Model\PdkOrder;
use MyParcelNL\Pdk\App\Order\Model\PdkOrderLine;
use MyParcelNL\Pdk\App\Order\Repository\AbstractPdkOrderRepository;
use MyParcelNL\Pdk\Base\Contract\WeightServiceInterface;
use MyParcelNL\Pdk\Base\Service\CountryService;
use MyParcelNL\Pdk\Base\Support\Collection;
use MyParcelNL\Pdk\Facade\Logger;
Expand Down Expand Up @@ -49,30 +48,22 @@ class PdkOrderRepository extends AbstractPdkOrderRepository
*/
private $wcOrderRepository;

/**
* @var \MyParcelNL\Pdk\Base\Contract\WeightServiceInterface
*/
private $weightService;

/**
* @param \MyParcelNL\Pdk\Storage\Contract\StorageInterface $storage
* @param \MyParcelNL\Pdk\App\Order\Contract\PdkProductRepositoryInterface $pdkProductRepository
* @param \MyParcelNL\WooCommerce\WooCommerce\Contract\WcOrderRepositoryInterface $wcOrderRepository
* @param \MyParcelNL\Pdk\Base\Service\CountryService $countryService
* @param \MyParcelNL\WooCommerce\Adapter\WcAddressAdapter $addressAdapter
* @param \MyParcelNL\Pdk\Base\Contract\WeightServiceInterface $weightService
*/
public function __construct(
StorageInterface $storage,
PdkProductRepositoryInterface $pdkProductRepository,
WeightServiceInterface $weightService,
WcOrderRepositoryInterface $wcOrderRepository,
CountryService $countryService,
WcAddressAdapter $addressAdapter
) {
parent::__construct($storage);
$this->pdkProductRepository = $pdkProductRepository;
$this->weightService = $weightService;
$this->wcOrderRepository = $wcOrderRepository;
$this->countryService = $countryService;
$this->addressAdapter = $addressAdapter;
Expand Down Expand Up @@ -153,7 +144,6 @@ private function createCustomsDeclaration(WC_Order $order, Collection $items): a
})
->toArray()
),
'weight' => $this->getItemsWeight($items),
];
}

Expand Down Expand Up @@ -195,9 +185,6 @@ private function getDataFromOrder(WC_Order $order): PdkOrder
]);
})
->all(),
'physicalProperties' => [
'weight' => $this->getItemsWeight($items),
],
'shippingAddress' => $shippingAddress,
'orderPrice' => $order->get_total(),
'orderPriceAfterVat' => (float) $order->get_total() + (float) $order->get_cart_tax(),
Expand All @@ -209,7 +196,7 @@ private function getDataFromOrder(WC_Order $order): PdkOrder
'orderDate' => $this->getDate($order->get_date_created()),
];

return new PdkOrder(array_replace($savedOrderData, $orderData));
return new PdkOrder(array_replace($orderData, $savedOrderData));
}

/**
Expand All @@ -226,29 +213,6 @@ private function getDate(?WC_DateTime $date): ?string
return $date->date('Y-m-d H:i:s');
}

/**
* @param \MyParcelNL\Pdk\Base\Support\Collection $items
*
* @return int
*/
private function getItemsWeight(Collection $items): int
{
$itemsWeight = $items
->where('product', '!=', null)
->reduce(static function (float $acc, $item) {
$quantity = $item['item']->get_quantity();
$weight = $item['product']->get_weight();

if (is_numeric($quantity) && is_numeric($weight)) {
$acc += $quantity * $weight;
}

return $acc;
}, 0);

return $this->weightService->convertToGrams($itemsWeight, '');
}

/**
* @param \WC_Order $order
*
Expand Down
Loading

0 comments on commit f9aeb23

Please sign in to comment.