/** * Lock collection from begin modified */ public function lock() { $this->ensureNotLocked(); global $objPage; $time = time(); $this->pageId = (int) $objPage->id; $this->language = (string) $GLOBALS['TL_LANGUAGE']; $this->createPrivateAddresses(); $this->updateDatabase(); // Add surcharges to the collection $sorting = 128; foreach ($this->getSurcharges() as $objSurcharge) { $objSurcharge->pid = $this->id; $objSurcharge->tstamp = $time; $objSurcharge->sorting = $sorting; $objSurcharge->save(); $sorting += 128; } // Add downloads from products to the collection foreach (ProductCollectionDownload::createForProductsInCollection($this) as $objDownload) { $objDownload->save(); } // Can't use model, it would not save as soon as it's locked \Database::getInstance()->query("UPDATE " . static::$strTable . " SET locked=" . $time . " WHERE id=" . $this->id); $this->arrData['locked'] = $time; // !HOOK: pre-process checkout if (isset($GLOBALS['ISO_HOOKS']['collectionLocked']) && is_array($GLOBALS['ISO_HOOKS']['collectionLocked'])) { foreach ($GLOBALS['ISO_HOOKS']['collectionLocked'] as $callback) { \System::importStatic($callback[0])->{$callback[1]}($this); } } $this->clearCache(); }
/** * Process the order checkout * @return boolean */ public function checkout() { if ($this->checkout_complete) { return true; } // !HOOK: pre-process checkout if (isset($GLOBALS['ISO_HOOKS']['preCheckout']) && is_array($GLOBALS['ISO_HOOKS']['preCheckout'])) { foreach ($GLOBALS['ISO_HOOKS']['preCheckout'] as $callback) { $objCallback = \System::importStatic($callback[0]); if ($objCallback->{$callback}[1]($this) === false) { \System::log('Callback ' . $callback[0] . '::' . $callback[1] . '() cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR); return false; } } } $this->createPrivateAddresses(); // 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); $this->lock(); \System::log('New order ID ' . $this->id . ' has been placed', __METHOD__, TL_ACCESS); // Add downloads from products to the collection /** @var ProductCollectionDownload[] $arrDownloads */ $arrDownloads = ProductCollectionDownload::createForProductsInCollection($this); foreach ($arrDownloads as $objDownload) { $objDownload->save(); } // 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 Order $objOrder */ foreach ($objOrders as $objOrder) { if (!$objOrder->isLocked()) { $objOrder->delete(); } } } // Generate tokens $arrTokens = $this->getNotificationTokens($this->nc_notification); // Send notification if ($this->nc_notification) { $blnNotificationError = true; 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; }