/** * Callback for checkout Hook. Transfer active rules to usage table. */ public function writeRuleUsages($objOrder) { $objCart = Cart::findByPk($objOrder->source_collection_id); $objRules = Rule::findActiveWitoutCoupons(); $arrRules = null === $objRules ? array() : $objRules->fetchEach('id'); $arrCoupons = deserialize($objCart->coupons); if (is_array($arrCoupons) && !empty($arrCoupons)) { $blnError = false; foreach ($arrCoupons as $k => $code) { $objRule = Rule::findOneByCouponCode($code, $objCart->getItems()); if (null === $objRule) { Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['couponCodeDropped'], $code)); unset($arrCoupons[$k]); $blnError = true; } else { $arrRules[] = $objRule->id; } } if ($blnError) { $objCart->coupons = $arrCoupons; return false; } } if (!empty($arrRules)) { $time = time(); \Database::getInstance()->query("INSERT INTO tl_iso_rule_usage (pid,tstamp,order_id,config_id,member_id) VALUES (" . implode(", {$time}, {$objOrder->id}, " . (int) Isotope::getConfig()->id . ", {$objOrder->member}), (", $arrRules) . ", {$time}, {$objOrder->id}, " . (int) Isotope::getConfig()->id . ", {$objOrder->member})"); } return true; }
/** * Process the order checkout * * @return bool */ public function checkout() { if ($this->isCheckoutComplete()) { return true; } // Finish and lock the order // (do this now, because otherwise surcharges etc. will not be loaded form the database) $this->checkout_complete = true; $this->generateDocumentNumber($this->getRelated('config_id')->orderPrefix, (int) $this->getRelated('config_id')->orderDigits); if (!$this->isLocked()) { $this->lock(); } \System::log('New order ID ' . $this->id . ' has been placed', __METHOD__, TL_ACCESS); // Delete cart after migrating to order if (($objCart = Cart::findByPk($this->source_collection_id)) !== null) { $objCart->delete(); } // Delete all other orders that relate to the current cart if (($objOrders = static::findSiblingsBy('source_collection_id', $this)) !== null) { /** @var static $objOrder */ foreach ($objOrders as $objOrder) { if (!$objOrder->isCheckoutComplete()) { $objOrder->delete(true); } } } // Generate tokens $arrTokens = $this->getNotificationTokens($this->nc_notification); // Send notification if ($this->nc_notification) { $blnNotificationError = true; /** @type Notification $objNotification */ if (($objNotification = Notification::findByPk($this->nc_notification)) !== null) { $arrResult = $objNotification->send($arrTokens, $this->language); if (!empty($arrResult) && !in_array(false, $arrResult)) { $blnNotificationError = false; } } if ($blnNotificationError === true) { \System::log('Error sending new order notification for order ID ' . $this->id, __METHOD__, TL_ERROR); } } else { \System::log('No notification for order ID ' . $this->id, __METHOD__, TL_ERROR); } // Set order status only if a payment module has not already set it if ($this->order_status == 0) { $this->updateOrderStatus($this->getRelated('config_id')->orderstatus_new); } // !HOOK: post-process checkout if (isset($GLOBALS['ISO_HOOKS']['postCheckout']) && is_array($GLOBALS['ISO_HOOKS']['postCheckout'])) { foreach ($GLOBALS['ISO_HOOKS']['postCheckout'] as $callback) { $objCallback = \System::importStatic($callback[0]); $objCallback->{$callback}[1]($this, $arrTokens); } } return true; }