first commit
This commit is contained in:
57
bundles/External/CykloSpecialityBundle/Util/DeliveryInfo.php
vendored
Normal file
57
bundles/External/CykloSpecialityBundle/Util/DeliveryInfo.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace External\CykloSpecialityBundle\Util;
|
||||
|
||||
use KupShop\CatalogBundle\ProductList\ProductCollection;
|
||||
use KupShop\KupShopBundle\Util\DateUtil;
|
||||
use KupShop\StoresBundle\Utils\StoresInStore;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
|
||||
class DeliveryInfo extends \KupShop\OrderingBundle\Util\Order\DeliveryInfo
|
||||
{
|
||||
private const DEFAULT_DELIVERY_TIME = 0;
|
||||
|
||||
#[Required]
|
||||
public StoresInStore $storesInStore;
|
||||
|
||||
protected function calculateCollectionDate(ProductCollection $productList, \Delivery $delivery, array &$cache): ?\DateTime
|
||||
{
|
||||
if ($delivery->isInPerson()) {
|
||||
return parent::calculateCollectionDate($productList, $delivery, $cache);
|
||||
}
|
||||
|
||||
$deliveryTime = 0;
|
||||
foreach ($productList as $product) {
|
||||
$productDeliveryTime = $this->getProductDeliveryTime($product);
|
||||
$deliveryTime = max($deliveryTime, $productDeliveryTime);
|
||||
}
|
||||
|
||||
return DateUtil::calcWorkingDays($deliveryTime);
|
||||
}
|
||||
|
||||
private function getProductDeliveryTime(\Product $product): int
|
||||
{
|
||||
$piecesOrdered = $product['piecesOrdered'] ?? 1;
|
||||
|
||||
// nactu sklady ktere maji pozadovane mnozstvi skladem
|
||||
$stores = $this->storesInStore->getProductInStores($product->id, $product->variationId ?? null);
|
||||
$storesWithSufficientStock = array_filter($stores, fn ($x) => $x >= $piecesOrdered);
|
||||
|
||||
// nactu data fyzickejch skladu
|
||||
$relevantStoresData = array_filter(
|
||||
array_intersect_key($this->storesInStore->getStores(), $storesWithSufficientStock),
|
||||
fn ($x) => $x['type'] === 0
|
||||
);
|
||||
|
||||
// vyberu nejnizsi deliveryTime
|
||||
$deliveryTimes = array_map(function ($storeData) {
|
||||
return empty($storeData['data']['deliveryTime']) ? self::DEFAULT_DELIVERY_TIME : $storeData['data']['deliveryTime'];
|
||||
}, $relevantStoresData);
|
||||
|
||||
if (empty($deliveryTimes)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return min($deliveryTimes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user