コード例 #1
0
    public function create(Discount $discount)
    {
        // Set create authorship data if not already set
        if (!$discount->authorship->createdAt()) {
            $discount->authorship->create(new DateTimeImmutable(), $this->_currentUser->id);
        }
        $result = $this->_query->run('
			INSERT INTO
				order_discount
			SET
				order_id    = :orderID?i,
				created_at  = :createdAt?d,
				created_by  = :createdBy?in,
				`type`      = :type?sn,
				code        = :code?sn,
				amount      = :amount?f,
				percentage  = :percentage?fn,
				`name`      = :name?sn,
				description = :description?sn
		', array('orderID' => $discount->order->id, 'createdAt' => $discount->authorship->createdAt(), 'createdBy' => $discount->authorship->createdBy(), 'type' => $discount->getType(), 'code' => $discount->code, 'amount' => $discount->amount, 'percentage' => $discount->percentage, 'name' => $discount->name, 'description' => $discount->description));
        if ($this->_query instanceof DB\Transaction) {
            return $discount;
        }
        return $this->_loader->getByID($result->id(), $discount->order);
    }