74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace KupShop\WarehouseBundle\Util;
|
|
|
|
use KupShop\WarehouseBundle\Entity\StoreItem;
|
|
use KupShop\WarehouseBundle\Event\WarehouseProductEvent;
|
|
use Query\Operator;
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
class StockInWorker extends \KupShop\CheckAppBundle\Util\StockInWorker
|
|
{
|
|
use \DatabaseCommunication;
|
|
/**
|
|
* @var StockInWorker
|
|
*/
|
|
private $storeItemWorker;
|
|
|
|
/**
|
|
* @var EventDispatcherInterface
|
|
*/
|
|
private $eventDispatcher;
|
|
|
|
public function __construct(StoreItemWorker $storeItemWorker)
|
|
{
|
|
$this->storeItemWorker = $storeItemWorker;
|
|
}
|
|
|
|
protected function getAdditionalData($id_product, $id_variation): array
|
|
{
|
|
$data = parent::getAdditionalData($id_product, $id_variation);
|
|
|
|
$warehouse_data = sqlQueryBuilder()
|
|
->select('GROUP_CONCAT(wpos.code) as positions')
|
|
->from('products_of_suppliers', 'pos')
|
|
->leftJoin('pos', 'warehouse_products', 'wp', '((wp.id_product=pos.id_product AND wp.id_variation IS NULL) OR (wp.id_product=pos.id_product AND wp.id_variation=pos.id_variation))')
|
|
->leftJoin('wp', 'warehouse_positions', 'wpos', 'wpos.id=wp.id_position')
|
|
->groupBy('pos.id_product, pos.id_variation')
|
|
->where(Operator::equalsNullable([
|
|
'pos.id_product' => $id_product,
|
|
'pos.id_variation' => $id_variation,
|
|
]))
|
|
->execute()->fetch();
|
|
|
|
if ($warehouse_data) {
|
|
$data = array_merge($data, $warehouse_data);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function storeIn($itemRow, int $inStoredPieces): void
|
|
{
|
|
$itemRow['product'] = new \Product($itemRow['id_product']);
|
|
$itemRow['quantity'] = $inStoredPieces;
|
|
|
|
$event = new WarehouseProductEvent();
|
|
$event->setStoreInItemRow($itemRow);
|
|
$event->setStoreItem(new StoreItem($itemRow));
|
|
$this->eventDispatcher->dispatch($event, WarehouseProductEvent::IN_STORE_PRODUCT);
|
|
|
|
if ($event->isStockInWeb()) {
|
|
$itemRow['product']->storeIn($itemRow['id_variation'], $inStoredPieces);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @required
|
|
*/
|
|
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
|
|
{
|
|
$this->eventDispatcher = $eventDispatcher;
|
|
}
|
|
}
|