dimanche 23 juin 2019

can I get cart content directly in order repository?

I'm dealing with design patterns and I found this piece of code from here:

    /**
     * Create the order
     *
     * @param array $params
     * @return Order
     * @throws OrderInvalidArgumentException
     */
    public function createOrder(array $params) : Order
    {
        try {
            $order = $this->create($params);
            $orderRepo = new OrderRepository($order);
            $orderRepo->buildOrderDetails(Cart::content());
            event(new OrderCreateEvent($order));
            return $order;
        } catch (QueryException $e) {
            throw new OrderInvalidArgumentException($e->getMessage(), 500, $e);
        }
    }

Does it break the rules? and what should I do if I want to pass products with an array from the design pattern point of view?

Aucun commentaire:

Enregistrer un commentaire