Dumplie\Customer\Infrastructure\Doctrine\Dbal\Domain\DbalProducts::getBySku PHP Method

getBySku() public method

public getBySku ( SKU $sku ) : Product
$sku Dumplie\SharedKernel\Domain\Product\SKU
return Dumplie\Customer\Domain\Product
    public function getBySku(SKU $sku) : Product
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->select('sku', 'is_in_stock', 'price_amount', 'price_currency', 'price_precision')->from('dumplie_inventory_product')->where('sku = :sku')->setParameter('sku', (string) $sku);
        $result = $this->connection->fetchAssoc($queryBuilder->getSQL(), $queryBuilder->getParameters());
        if (!$result) {
            throw ProductNotFoundException::bySku($sku);
        }
        return new Product(new SKU($result['sku']), new Price((int) $result['price_amount'], $result['price_currency'], (int) $result['price_precision']), (bool) $result['is_in_stock']);
    }