32 lines
1010 B
PHP
32 lines
1010 B
PHP
<?php
|
|
|
|
namespace KupShop\POSBundle\Util;
|
|
|
|
use KupShop\GraphQLBundle\ApiPos\Types\Warehouse\PosStoreItem;
|
|
use KupShop\GraphQLBundle\ApiPos\Types\Warehouse\PosStoreItemCollection;
|
|
|
|
class PosStoreUtil
|
|
{
|
|
public function getStoresCollection(\Product|\Variation $product, ?int $forceVariationId = null): ?PosStoreItemCollection
|
|
{
|
|
if (!findModule(\Modules::STORES)) {
|
|
return null;
|
|
}
|
|
|
|
if ($forceVariationId) {
|
|
$storesInStore = $product->storesInStoreByVariations[$forceVariationId] ?? [];
|
|
} elseif ($product instanceof \Variation) {
|
|
$storesInStore = $product->storesInStoreByVariations[$product->variationId] ?? [];
|
|
} else {
|
|
$storesInStore = $product->storesInStore ?? [];
|
|
}
|
|
|
|
$stores = [];
|
|
foreach ($storesInStore as $idStore => $store) {
|
|
$stores[] = new PosStoreItem($idStore, $store['name'], $store['in_store']);
|
|
}
|
|
|
|
return new PosStoreItemCollection($stores);
|
|
}
|
|
}
|