Sylius\Behat\Context\Setup\OrderContext::customersHaveAddedProductsToTheCartForTotalOf PHP Method

customersHaveAddedProductsToTheCartForTotalOf() public method

public customersHaveAddedProductsToTheCartForTotalOf ( $numberOfCustomers, $total )
    public function customersHaveAddedProductsToTheCartForTotalOf($numberOfCustomers, $total)
    {
        $customers = $this->generateCustomers($numberOfCustomers);
        $sampleProductVariant = $this->sharedStorage->get('variant');
        $total = $this->getPriceFromString($total);
        for ($i = 0; $i < $numberOfCustomers; $i++) {
            $order = $this->createCart($customers[rand(0, $numberOfCustomers - 1)]);
            $price = $i === $numberOfCustomers - 1 ? $total : rand(1, $total);
            $total -= $price;
            $item = $this->orderItemFactory->createNew();
            $item->setVariant($sampleProductVariant);
            $item->setUnitPrice($price);
            $this->itemQuantityModifier->modify($item, 1);
            $order->addItem($item);
            $this->orderRepository->add($order);
        }
    }