/** * Save changes to the bundle to the database * * @param Bundle $bundle */ public function save(Bundle $bundle) { $this->_transaction->add("\n\t\t\tUPDATE\n\t\t\t\tdiscount_bundle\n\t\t\tSET\n\t\t\t\t`name` = :name?s,\n\t\t\t\tallow_codes = :allowsCodes?b,\n\t\t\t\tstart = :start?dn,\n\t\t\t\t`end` = :end?dn,\n\t\t\t\tupdated_at = :updatedAt?d,\n\t\t\t\tupdated_by = :updatedBy?i\n\t\t\tWHERE\n\t\t\t\tbundle_id = :bundleID?i\n\t\t", ['name' => $bundle->getName(), 'allowsCodes' => $bundle->allowsCodes(), 'start' => $bundle->getStart(), 'end' => $bundle->getEnd(), 'updatedAt' => new \DateTime(), 'updatedBy' => $this->_user->id, 'bundleID' => $bundle->getID()]); $this->_productCreate->save($bundle); $this->_priceCreate->setTransaction($this->_transaction); $this->_priceCreate->save($bundle); $this->_imageCreate->setTransaction($this->_transaction); $this->_imageCreate->save($bundle); $this->_commitTransaction(); }
public function validateAllowsCodes(Bundle $bundle, Order\Order $order) { if (false === $bundle->allowsCodes()) { foreach ($order->discounts as $discount) { if ($discount->getType() === Discount\OrderDiscountFactory::TYPE) { $this->_error('ms.discount.bundle.validation.codes', ['%name%' => $bundle->getName(), '%code%' => $discount->code]); } } } }
/** * Create a discount order entity to apply to the * * @param Order\Order $order * @param Bundle $bundle * * @return Order\Entity\Discount\Discount */ public function createOrderDiscount(Order\Order $order, Bundle $bundle) { $discount = new Order\Entity\Discount\Discount(); $type = $bundle->allowsCodes() ? self::CODES_ALLOWED : self::NO_CODES; $discount->setType($type); $discount->order = $order; $discount->amount = $this->_calculateAmount($order, $bundle); $discount->name = $bundle->getName(); $discount->description = 'Bundle ' . $bundle->getID() . ': ' . $bundle->getName(); $discount->order = $order; return $discount; }
/** * Save bundle to the database * * @param Bundle $bundle * * @return Bundle Return Bundle with ID and authorship details updated. */ public function save(Bundle $bundle) { if (!$bundle->getAuthorship()->createdAt()) { $bundle->getAuthorship()->create(new DateTimeImmutable(), $this->_user->id); } $result = $this->_query->run("\n\t\t\tINSERT INTO\n\t\t\t\tdiscount_bundle\n\t\t\t\t(\n\t\t\t\t\t`name`,\n\t\t\t\t\tallow_codes,\n\t\t\t\t\tstart,\n\t\t\t\t\t`end`,\n\t\t\t\t\tcreated_at,\n\t\t\t\t\tcreated_by\n\t\t\t\t)\n\t\t\tVALUES\n\t\t\t\t(\n\t\t\t\t\t:name?s,\n\t\t\t\t\t:allowsCodes?b,\n\t\t\t\t\t:start?dn,\n\t\t\t\t\t:end?dn,\n\t\t\t\t\t:createdAt?d,\n\t\t\t\t\t:createdBy?i\n\t\t\t\t)\n\t\t", ['name' => $bundle->getName(), 'allowsCodes' => $bundle->allowsCodes(), 'start' => $bundle->getStart(), 'end' => $bundle->getEnd(), 'createdAt' => new \DateTime(), 'createdBy' => $this->_user->id]); $bundle->setID($result->id()); $this->_bundleProductCreate->save($bundle); $this->_bundlePriceCreate->save($bundle); $this->_bundleImageCreate->save($bundle); return $bundle; }