public static function addSubscriptions(Order $objOrder, $arrTokens) { $strEmail = $objOrder->getBillingAddress()->email; $objAddress = $objOrder->getShippingAddress() ?: $objOrder->getBillingAddress(); $arrItems = $objOrder->getItems(); $objSession = \Session::getInstance(); if (!($intModule = $objSession->get('isotopeCheckoutModuleIdSubscriptions'))) { return true; } $objSession->remove('isotopeCheckoutModuleIdSubscriptions'); $objModule = \ModuleModel::findByPk($intModule); foreach ($arrItems as $item) { switch ($objModule->iso_direct_checkout_product_mode) { case 'product_type': $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product_type', Standard::findAvailableByIdOrAlias($item->product_id)->type); break; default: $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product', $item->product_id); break; } if ($objFieldpalette !== null && $objFieldpalette->iso_addSubscription) { if ($objFieldpalette->iso_subscriptionArchive && (!$objFieldpalette->iso_addSubscriptionCheckbox || \Input::post('subscribeToProduct_' . $item->product_id))) { $objSubscription = Subscription::findOneBy(array('email=?', 'pid=?', 'activation!=?', 'disable=?'), array($strEmail, $objFieldpalette->iso_subscriptionArchive, '', 1)); if (!$objSubscription) { $objSubscription = new Subscription(); } if ($objFieldpalette->iso_addActivation) { $strToken = md5(uniqid(mt_rand(), true)); $objSubscription->disable = true; $objSubscription->activation = $strToken; if (($objNotification = Notification::findByPk($objFieldpalette->iso_activationNotification)) !== null) { if ($objFieldpalette->iso_activationJumpTo && ($objPageRedirect = \PageModel::findByPk($objFieldpalette->iso_activationJumpTo)) !== null) { $arrTokens['link'] = \Environment::get('url') . '/' . \Controller::generateFrontendUrl($objPageRedirect->row()) . '?token=' . $strToken; } $objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']); } } $arrAddressFields = \Config::get('iso_addressFields'); if ($arrAddressFields === null) { $arrAddressFields = serialize(array_keys(static::getIsotopeAddressFields())); } foreach (deserialize($arrAddressFields, true) as $strName) { $objSubscription->{$strName} = $objAddress->{$strName}; } $objSubscription->email = $strEmail; $objSubscription->pid = $objFieldpalette->iso_subscriptionArchive; $objSubscription->tstamp = $objSubscription->dateAdded = time(); $objSubscription->quantity = \Input::post('quantity'); $objSubscription->order_id = $objOrder->id; $objSubscription->save(); } } } return true; }
/** * Generate the module */ protected function compile() { // Also check owner (see #126) if (($objOrder = Order::findOneBy('uniqid', (string) \Input::get('uid'))) === null || FE_USER_LOGGED_IN === true && $objOrder->member > 0 && \FrontendUser::getInstance()->id != $objOrder->member) { $this->Template = new \Isotope\Template('mod_message'); $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound']; return; } // Order belongs to a member but not logged in if (TL_MODE == 'FE' && $this->iso_loginRequired && $objOrder->member > 0 && FE_USER_LOGGED_IN !== true) { global $objPage; $objHandler = new $GLOBALS['TL_PTY']['error_403'](); $objHandler->generate($objPage->id); exit; } Isotope::setConfig($objOrder->getRelated('config_id')); $objTemplate = new \Isotope\Template($this->iso_collectionTpl); $objTemplate->linkProducts = true; $objOrder->addToTemplate($objTemplate, array('gallery' => $this->iso_gallery, 'sorting' => $objOrder->getItemsSortingCallable($this->iso_orderCollectionBy))); $this->Template->collection = $objOrder; $this->Template->products = $objTemplate->parse(); $this->Template->info = deserialize($objOrder->checkout_info, true); $this->Template->date = Format::date($objOrder->locked); $this->Template->time = Format::time($objOrder->locked); $this->Template->datim = Format::datim($objOrder->locked); $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->document_number, $this->Template->datim); $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $objOrder->getStatusLabel()); $this->Template->orderStatusKey = $objOrder->getStatusAlias(); }
/** * Get the order object in a postsale request * * @return IsotopeProductCollection|null */ public function getPostsaleOrder() { $data = $this->getRequestResource(); if (null === $data) { return null; } return Order::findByPk((int) $data['order_id']); }
/** * Remove orders that have not been completed for a given number of days */ public function deleteOldOrders() { $t = Order::getTable(); $objOrders = Order::findBy(array("{$t}.order_status=0", "{$t}.tstamp<?"), array(time() - $GLOBALS['TL_CONFIG']['iso_orderTimeout'])); if (($intPurged = $this->deleteOldCollections($objOrders)) > 0) { \System::log('Deleted ' . $intPurged . ' incomplete orders', __METHOD__, TL_CRON); } }
/** * Process checkout */ public function checkAbo(Order $objOrder, $arrTokens) { foreach ($objOrder->getItems() as $objItem) { $objProduct = $objItem->getProduct(); if ($objProduct->aboId && $objProduct->expiretime && $objOrder->member) { // set Abo $objAbo = new \Abo(); $objAbo->setAbo($objProduct->aboId); $objCurrentAbo = Database::getInstance()->prepare("SELECT * FROM tl_abo_order WHERE memberId = ? AND aboId = ?")->execute($objOrder->member, $objProduct->aboId); if (!$objCurrentAbo->numRows) { $objAbo->setMember($objOrder->member); $objAbo->start($objProduct->expiretime); } else { $objAbo->setMember($objOrder->member); $objAbo->renew($objProduct->expiretime); } } } return true; }
/** * Updates the counts on all bought products * @param Isotope\Model\ProductCollection * @param \stdClass * @param string * @param integer * @param mixed */ public function updateProductCount(\Isotope\Model\ProductCollection\Order $objOrder) { if (empty($objOrder->id)) { return false; } foreach ($objOrder->getItems() as $objItem) { $objProduct = NULL; $objProduct = $objItem->getProduct(true); if (!empty($objProduct->simple_erp_count) && $objProduct->simple_erp_count > 0) { // decrease available quantity $objProduct->simple_erp_count = $objProduct->simple_erp_count - $objItem->quantity; // set product suppressed if there is no quantity left and the option is checked if ($objProduct->simple_erp_disable_on_zero && $objProduct->simple_erp_count <= 0) { $objProduct->simple_erp_count = 0; $objProduct->published = 0; } // update product $objProduct->save(); } } }
/** * Generate the module * @return void */ protected function compile() { $arrOrders = array(); $objOrders = Order::findBy(array('order_status>0', 'member=?', 'config_id IN (?)'), array(\FrontendUser::getInstance()->id, implode("','", $this->iso_config_ids)), array('order' => 'locked DESC')); // No orders found, just display an "empty" message if (null === $objOrders) { $this->Template = new \Isotope\Template('mod_message'); $this->Template->type = 'empty'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['emptyOrderHistory']; return; } while ($objOrders->next()) { Isotope::setConfig($objOrders->current()->getRelated('config_id')); $arrOrders[] = array('collection' => $objOrders->current(), 'raw' => $objOrders->current()->row(), 'date' => Format::date($objOrders->current()->locked), 'time' => Format::time($objOrders->current()->locked), 'datime' => Format::datim($objOrders->current()->locked), 'grandTotal' => Isotope::formatPriceWithCurrency($objOrders->current()->getTotal()), 'status' => $objOrders->current()->getStatusLabel(), 'link' => $this->jumpTo ? \Haste\Util\Url::addQueryString('uid=' . $objOrders->current()->uniqid, $this->jumpTo) : '', 'class' => $objOrders->current()->getStatusAlias()); } RowClass::withKey('class')->addFirstLast()->addEvenOdd()->applyTo($arrOrders); $this->Template->orders = $arrOrders; }
/** * Replace known Isotope insert tags. * * @param string $insertTag * * @return string|bool */ public function replace($insertTag) { $tokens = trimsplit('::', $insertTag); switch ($tokens[0]) { case 'cart': return $this->getValueForCollectionTag(Isotope::getCart(), $tokens); case 'order': if (($order = Order::findOneBy('uniqid', \Input::get('uid'))) === null) { return ''; } return $this->getValueForCollectionTag($order, $tokens); case 'product': if (($product = $this->findCurrentProduct($tokens[2])) === null) { return ''; } return $this->getValueForProductTag($product, $tokens[1]); case 'isolabel': return $this->getValueForLabel($tokens[1], $tokens[2]); case 'isotope': case 'cache_isotope': return $this->getValueForIsotopeTag($tokens[1]); } return false; }
public static function updateStock(Order $objOrder, $objNewStatus) { // atm only for backend if (TL_MODE != 'BE') { return false; } // the order's config is used! $objConfig = Isotope::getConfig(); $arrStockIncreaseOrderStates = deserialize($objConfig->stockIncreaseOrderStates, true); // e.g. new -> cancelled => increase the stock based on the order item's setQuantity-values (no validation required, of course) if (!in_array($objOrder->order_status, $arrStockIncreaseOrderStates) && in_array($objNewStatus->id, $arrStockIncreaseOrderStates)) { foreach ($objOrder->getItems() as $objItem) { if (($objProduct = $objItem->getProduct()) !== null) { $intTotalQuantity = static::getTotalStockQuantity($objItem->quantity, $objProduct, null, $objItem->setQuantity); if ($intTotalQuantity) { $objProduct->stock += $intTotalQuantity; $objProduct->save(); } } } } elseif (in_array($objOrder->order_status, $arrStockIncreaseOrderStates) && !in_array($objNewStatus->id, $arrStockIncreaseOrderStates)) { foreach ($objOrder->getItems() as $objItem) { if (($objProduct = $objItem->getProduct()) !== null) { $blnSkipValidation = static::getOverridableStockProperty('skipStockValidation', $objProduct); // watch out: also in backend the current set quantity is used for validation! if (!$blnSkipValidation && !static::validateQuantity($objProduct, $objItem->quantity)) { // if the validation breaks for only one product collection item -> cancel the order status transition return true; } } } foreach ($objOrder->getItems() as $objItem) { if (($objProduct = $objItem->getProduct()) !== null) { $intTotalQuantity = static::getTotalStockQuantity($objItem->quantity, $objProduct); if ($intTotalQuantity) { $objProduct->stock -= $intTotalQuantity; if ($objProduct->stock <= 0 && !static::getOverridableStockProperty('skipExemptionFromShippingWhenStockEmpty', $objProduct)) { $objProduct->shipping_exempt = true; } $objProduct->save(); } } } } // don't cancel return false; }
public static function getOrders(\DataContainer $objDc) { $arrOptions = array(); if (($objSubscription = \Isotope\Model\Subscription::findByPk($objDc->activeRecord->id)) !== null) { if (($objOrders = \Isotope\Model\ProductCollection\Order::findByType('order')) !== null) { while ($objOrders->next()) { foreach ($objOrders->current()->getItems() as $objItem) { // the order needs to contain at least one item of the product type defined in the archive if (($objProduct = $objItem->getProduct()) !== null && $objProduct->type == $objSubscription->getRelated('pid')->productType) { $arrOptions[$objOrders->id] = $GLOBALS['TL_LANG']['MSC']['order'] . ' ' . $objOrders->document_number; break; } } } } // inverse asort arsort($arrOptions); } return $arrOptions; }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk(\Input::get('transactionId')); }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk(\Input::post('vads_order_id')); }
/** * Execute the saveCollection hook when a collection is saved * @param object * @return void */ public function executeSaveHook($dc) { if (($objOrder = Order::findByPk($dc->id)) !== null) { // !HOOK: add additional functionality when saving collection if (isset($GLOBALS['ISO_HOOKS']['saveCollection']) && is_array($GLOBALS['ISO_HOOKS']['saveCollection'])) { foreach ($GLOBALS['ISO_HOOKS']['saveCollection'] as $callback) { $objCallback = \System::importStatic($callback[0]); $objCallback->{$callback}[1]($objOrder); } } } }
/** * Prepare PSP params * * @param Order $objOrder * @param \Isotope\Module\Checkout $objModule * * @return array */ protected function preparePSPParams($objOrder, $objModule) { $objBillingAddress = $objOrder->getBillingAddress(); return array('PSPID' => $this->psp_pspid, 'ORDERID' => $objOrder->id, 'AMOUNT' => round($objOrder->getTotal() * 100), 'CURRENCY' => $objOrder->currency, 'LANGUAGE' => $GLOBALS['TL_LANGUAGE'] . '_' . strtoupper($GLOBALS['TL_LANGUAGE']), 'CN' => $objBillingAddress->firstname . ' ' . $objBillingAddress->lastname, 'EMAIL' => $objBillingAddress->email, 'OWNERZIP' => $objBillingAddress->postal, 'OWNERADDRESS' => $objBillingAddress->street_1, 'OWNERADDRESS2' => $objBillingAddress->street_2, 'OWNERCTY' => strtoupper($objBillingAddress->country), 'OWNERTOWN' => $objBillingAddress->city, 'OWNERTELNO' => $objBillingAddress->phone, 'ACCEPTURL' => \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder), 'DECLINEURL' => \Environment::get('base') . $objModule->generateUrlForStep('failed'), 'BACKURL' => \Environment::get('base') . $objModule->generateUrlForStep('review'), 'PARAMPLUS' => 'mod=pay&id=' . $this->id, 'TP' => $this->psp_dynamic_template ?: ''); }
/** * Initialize environment (language, objPage) for a given order * * @param Order $objOrder * @param string $strLanguage */ public static function loadOrderEnvironment(Order $objOrder, $strLanguage = null) { global $objPage; $strLanguage = $strLanguage ?: $objOrder->language; // Load page configuration if ($objOrder->pageId > 0 && (null === $objPage || $objPage->id != $objOrder->pageId)) { $objPage = \PageModel::findWithDetails($objOrder->pageId); $objPage = static::loadPageConfig($objPage); } // Set the current system to the language when the user placed the order. // This will result in correct e-mails and payment description. $GLOBALS['TL_LANGUAGE'] = $strLanguage; \System::loadLanguageFile('default', $strLanguage, true); Isotope::setConfig($objOrder->getRelated('config_id')); if (($objCart = $objOrder->getRelated('source_collection_id')) !== null && $objCart instanceof Cart) { Isotope::setCart($objCart); } }
/** * Return information or advanced features in the backend. * * Use this function to present advanced features or basic payment information for an order in the backend. * @param integer Order ID * @return string */ public function backendInterface($orderId) { if (($objOrder = Order::findByPk($orderId)) === null) { return parent::backendInterface($orderId); } $arrPayment = deserialize($objOrder->payment_data, true); if (!is_array($arrPayment['POSTSALE']) || empty($arrPayment['POSTSALE'])) { return parent::backendInterface($orderId); } $arrPayment = array_pop($arrPayment['POSTSALE']); ksort($arrPayment); $i = 0; $strBuffer = ' <div id="tl_buttons"> <a href="' . ampersand(str_replace('&key=payment', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . $this->name . ' (' . $GLOBALS['TL_LANG']['MODEL']['tl_iso_payment.paypal'][0] . ')' . '</h2> <div id="tl_soverview"> <div id="tl_messages"> <p class="tl_info"><a href="https://www.paypal.com/' . strtolower($arrPayment['residence_country']) . '/cgi-bin/webscr?cmd=_view-a-trans&id=' . $arrPayment['txn_id'] . '" target="_blank">' . $GLOBALS['TL_LANG']['MSC']['paypalTransactionOnline'] . '</a></p> </div> </div> <table class="tl_show"> <tbody>'; foreach ($arrPayment as $k => $v) { if (is_array($v)) { continue; } $strBuffer .= ' <tr> <td' . ($i % 2 ? '' : ' class="tl_bg"') . '><span class="tl_label">' . $k . ': </span></td> <td' . ($i % 2 ? '' : ' class="tl_bg"') . '>' . $v . '</td> </tr>'; ++$i; } $strBuffer .= ' </tbody></table> </div>'; return $strBuffer; }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk(\Input::post('user_variable_0')); }
/** * @param Product|\Model $product * @param ProductCollection\Order|\Model $order * * @return array */ private static function createStockChangeNotifictionTokens(Product $product, ProductCollection\Order $order) { $tokens = []; $tokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL']; /** @var Config|\Model $config */ $config = $order->getRelated('config_id'); foreach ($product->row() as $k => $v) { $tokens['product_' . $k] = $v; } foreach ($order->row() as $k => $v) { $tokens['order_' . $k] = $v; } foreach ($config->row() as $k => $v) { $tokens['config_' . $k] = $v; } return $tokens; }
/** * Get and update order draft for current cart or create one if it does not yet exist * * @return Order */ public function getDraftOrder() { if ($this->objDraftOrder === null) { $t = Order::getTable(); $objOrder = Order::findOneBy(array("{$t}.source_collection_id=?", "{$t}.locked=''"), array($this->id)); if ($objOrder === null) { $objOrder = Order::createFromCollection($this); } else { $objOrder->config_id = (int) $this->config_id; $objOrder->store_id = (int) $this->store_id; $objOrder->member = (int) $this->member; $objOrder->setShippingMethod($this->getShippingMethod()); $objOrder->setPaymentMethod($this->getPaymentMethod()); $objOrder->setShippingAddress($this->getShippingAddress()); $objOrder->setBillingAddress($this->getBillingAddress()); $objOrder->purge(); $arrItemIds = $objOrder->copyItemsFrom($this); $objOrder->updateDatabase(); // HOOK: order status has been updated if (isset($GLOBALS['ISO_HOOKS']['updateDraftOrder']) && is_array($GLOBALS['ISO_HOOKS']['updateDraftOrder'])) { foreach ($GLOBALS['ISO_HOOKS']['updateDraftOrder'] as $callback) { $objCallback = \System::importStatic($callback[0]); $objCallback->{$callback}[1]($objOrder, $this, $arrItemIds); } } } $this->objDraftOrder = $objOrder; } return $this->objDraftOrder; }
/** * Replaces Isotope-specific InsertTags in Frontend * @param string * @return mixed */ public function replaceIsotopeTags($strTag) { $arrTag = trimsplit('::', $strTag); if ($arrTag[0] == 'isotope' || $arrTag[0] == 'cache_isotope') { switch ($arrTag[1]) { case 'cart_items': return Isotope::getCart()->countItems(); break; case 'cart_quantity': return Isotope::getCart()->sumItemsQuantity(); break; case 'cart_items_label': $intCount = Isotope::getCart()->countItems(); if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); break; case 'cart_quantity_label': $intCount = Isotope::getCart()->sumItemsQuantity(); if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); break; case 'cart_subtotal': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getSubtotal()); break; case 'cart_taxfree_subtotal': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTaxFreeSubtotal()); break; case 'cart_total': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTotal()); break; case 'cart_taxfree_total': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTaxFreeTotal()); break; } return ''; } elseif ($arrTag[0] == 'isolabel') { return Translation::get($arrTag[1], $arrTag[2]); } elseif ($arrTag[0] == 'order') { if (($objOrder = Order::findOneByUniqid(\Input::get('uid'))) !== null) { return $objOrder->{$arrTag[1]}; } return ''; } elseif ($arrTag[0] == 'product') { // 2 possible use cases: // {{product::attribute}} - gets the data of the current product (Product::getActive() or GET parameter "product") // {{product::attribute::product_id}} - gets the data of the specified product ID if (count($arrTag) == 3) { $objProduct = Product::findAvailableByPk($arrTag[2]); } else { if (($objProduct = Product::getActive()) === null) { $objProduct = Product::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product', false, true)); } } return $objProduct !== null ? $objProduct->{$arrTag[1]} : ''; } return false; }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { if (!$this->getRequestData('orderID')) { return null; } return Order::findByPk($this->getRequestData('orderID')); }
/** * Generate module */ protected function compile() { $arrBuffer = array(); // Default template settings. Must be set at beginning so they can be overwritten later (eg. trough callback) $this->Template->action = ampersand(\Environment::get('request'), ENCODE_AMPERSANDS); $this->Template->formId = $this->strFormId; $this->Template->formSubmit = $this->strFormId; $this->Template->enctype = 'application/x-www-form-urlencoded'; $this->Template->previousLabel = specialchars($GLOBALS['TL_LANG']['MSC']['previousStep']); $this->Template->nextLabel = specialchars($GLOBALS['TL_LANG']['MSC']['nextStep']); $this->Template->nextClass = 'next'; $this->Template->showPrevious = true; $this->Template->showNext = true; $this->Template->showForm = true; $this->Template->steps = array(); // These steps are handled internally by the checkout module and are not in the config array switch ($this->strCurrentStep) { // Complete order after successful payment // At this stage, we do no longer use the client's cart but the order through UID in URL case 'complete': /** @var Order $objOrder */ if (($objOrder = Order::findOneBy('uniqid', (string) \Input::get('uid'))) === null) { // Order already completed (see #1441) if ($objOrder->checkout_complete || Isotope::getCart()->isEmpty()) { /** @type \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate((int) $GLOBALS['objPage']->id); exit; } else { static::redirectToStep('failed'); } } $strBuffer = $objOrder->hasPayment() ? $objOrder->getPaymentMethod()->processPayment($objOrder, $this) : true; // true means the payment is successful and order should be completed if ($strBuffer === true) { // If checkout is successful, complete order and redirect to confirmation page if ($objOrder->checkout() && $objOrder->complete()) { \Controller::redirect(\Haste\Util\Url::addQueryString('uid=' . $objOrder->uniqid, $this->orderCompleteJumpTo)); } // Checkout failed, show error message static::redirectToStep('failed'); } elseif ($strBuffer === false) { static::redirectToStep('failed'); } else { $this->Template->showNext = false; $this->Template->showPrevious = false; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); } break; // Process order and initiate payment method if necessary // Process order and initiate payment method if necessary case 'process': // canCheckout will override the template and show a message if (!$this->canCheckout()) { return; } $arrSteps = $this->getSteps(); // Make sure all steps have passed successfully foreach ($arrSteps as $step => $arrModules) { /** @type IsotopeCheckoutStep $objModule */ foreach ($arrModules as $objModule) { $objModule->generate(); if ($objModule->hasError()) { static::redirectToStep($step); } } } $objOrder = Isotope::getCart()->getDraftOrder(); $objOrder->checkout_info = $this->getCheckoutInfo($arrSteps); $objOrder->nc_notification = $this->nc_notification; $objOrder->iso_addToAddressbook = $this->iso_addToAddressbook; $objOrder->email_data = $this->getNotificationTokensFromSteps($arrSteps, $objOrder); // !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]($objOrder) === false) { \System::log('Callback ' . $callback[0] . '::' . $callback[1] . '() cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR); static::redirectToStep('failed'); } } } $objOrder->lock(); $strBuffer = $objOrder->hasPayment() ? $objOrder->getPaymentMethod()->checkoutForm($objOrder, $this) : false; if ($strBuffer === false) { static::redirectToStep('complete', $objOrder); } $this->Template->showForm = false; $this->doNotSubmit = true; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); break; // Checkout/payment has failed, show the review page again with an error message /** @noinspection PhpMissingBreakStatementInspection */ // Checkout/payment has failed, show the review page again with an error message /** @noinspection PhpMissingBreakStatementInspection */ case 'failed': $this->Template->mtype = 'error'; $this->Template->message = strlen(\Input::get('reason')) ? \Input::get('reason') : $GLOBALS['TL_LANG']['ERR']['orderFailed']; $this->strCurrentStep = 'review'; // no break // no break default: // canCheckout will override the template and show a message if (!$this->canCheckout()) { return; } $arrBuffer = $this->generateSteps($this->getSteps()); break; } RowClass::withKey('class')->addFirstLast()->applyTo($arrBuffer); $this->Template->fields = $arrBuffer; }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk((int) \Input::post('cartId')); }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk(\Input::post('reference')); }
/** * Return information or advanced features in the backend * @param integer * @return string */ public function backendInterface($orderId) { if (($objOrder = Order::findByPk($orderId)) === null) { return parent::backendInterface($orderId); } $arrPayment = deserialize($objOrder->payment_data, true); if (!is_array($arrPayment['POSTSALE']) || empty($arrPayment['POSTSALE'])) { return parent::backendInterface($orderId); } $arrPayment = array_pop($arrPayment['POSTSALE']); ksort($arrPayment); $i = 0; $strBuffer = ' <div id="tl_buttons"> <a href="' . ampersand(str_replace('&key=payment', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . $this->name . ' (' . $GLOBALS['TL_LANG']['MODEL']['tl_iso_payment.transferujpl'][0] . ')' . '</h2> <table class="tl_show"> <tbody>'; foreach ($arrPayment as $k => $v) { if (is_array($v)) { continue; } $strBuffer .= ' <tr> <td' . ($i % 2 ? '' : ' class="tl_bg"') . '><span class="tl_label">' . $k . ': </span></td> <td' . ($i % 2 ? '' : ' class="tl_bg"') . '>' . $v . '</td> </tr>'; ++$i; } $strBuffer .= ' </tbody></table> </div>'; return $strBuffer; }
/** * Get the order object in a postsale request * * @return IsotopeProductCollection|null */ public function getPostsaleOrder() { return Order::findByPk((int) \Input::get('orderid')); }
/** * Check XML data, add to log if debugging is enabled * * @param Order $objOrder * * @return bool */ private function validateXML(Order $objOrder) { if ($this->getPostValue('ACCOUNTID') != $this->saferpay_accountid) { \System::log('XML data wrong, possible manipulation (accountId validation failed)! See log files for further details.', __METHOD__, TL_ERROR); log_message(sprintf('XML data wrong, possible manipulation (accountId validation failed)! XML was: "%s". Order was: "%s"', $this->getPostValue('ACCOUNTID'), $this->saferpay_accountid), 'isotope_saferpay.log'); return false; } elseif ($this->getPostValue('AMOUNT') != round($objOrder->getTotal() * 100, 0)) { \System::log('XML data wrong, possible manipulation (amount validation failed)! See log files for further details.', __METHOD__, TL_ERROR); log_message(sprintf('XML data wrong, possible manipulation (amount validation failed)! XML was: "%s". Order was: "%s"', $this->getPostValue('AMOUNT'), $this->getTotal()), 'isotope_saferpay.log'); return false; } elseif ($this->getPostValue('CURRENCY') != $objOrder->currency) { \System::log('XML data wrong, possible manipulation (currency validation failed)! See log files for further details.', __METHOD__, TL_ERROR); log_message(sprintf('XML data wrong, possible manipulation (currency validation failed)! XML was: "%s". Order was: "%s"', $this->getPostValue('CURRENCY'), $this->currency), 'isotope_saferpay.log'); return false; } return true; }
/** * Generate module */ protected function compile() { $arrBuffer = array(); // Default template settings. Must be set at beginning so they can be overwritten later (eg. trough callback) $this->Template->action = ampersand(\Environment::get('request'), ENCODE_AMPERSANDS); $this->Template->formId = $this->strFormId; $this->Template->formSubmit = $this->strFormId; $this->Template->enctype = 'application/x-www-form-urlencoded'; $this->Template->previousLabel = specialchars($GLOBALS['TL_LANG']['MSC']['previousStep']); $this->Template->nextLabel = specialchars($GLOBALS['TL_LANG']['MSC']['nextStep']); $this->Template->nextClass = 'next'; $this->Template->showPrevious = true; $this->Template->showNext = true; $this->Template->showForm = true; $this->Template->steps = array(); // These steps are handled internally by the checkout module and are not in the config array switch ($this->strCurrentStep) { // Complete order after successful payment // At this stage, we do no longer use the client's cart but the order through UID in URL case 'complete': if (($objOrder = Order::findOneByUniqid((string) \Input::get('uid'))) === null) { static::redirectToStep('failed'); } $strBuffer = $objOrder->hasPayment() ? $objOrder->getPaymentMethod()->processPayment($objOrder, $this) : true; // true means the payment is successful and order should be completed if ($strBuffer === true) { // If checkout is successful, complete order and redirect to confirmation page if ($objOrder->checkout() && $objOrder->complete()) { \Controller::redirect(\Haste\Util\Url::addQueryString('uid=' . $objOrder->uniqid, $this->orderCompleteJumpTo)); } // Checkout failed, show error message static::redirectToStep('failed'); } elseif ($strBuffer === false) { static::redirectToStep('failed'); } else { $this->Template->showNext = false; $this->Template->showPrevious = false; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); } break; // Process order and initiate payment method if necessary // Process order and initiate payment method if necessary case 'process': $arrSteps = $this->getSteps(); // Make sure all steps have passed successfully foreach ($arrSteps as $step => $arrModules) { foreach ($arrModules as $objModule) { $objModule->generate(); if ($objModule->hasError()) { static::redirectToStep($step); } } } $objOrder = Order::createFromCollection(Isotope::getCart()); $objOrder->checkout_info = $this->getCheckoutInfo($arrSteps); $objOrder->nc_notification = $this->nc_notification; $objOrder->iso_addToAddressbook = $this->iso_addToAddressbook; $objOrder->email_data = $this->getNotificationTokensFromSteps($arrSteps, $objOrder); $objOrder->save(); $strBuffer = Isotope::getCart()->hasPayment() ? Isotope::getCart()->getPaymentMethod()->checkoutForm($objOrder, $this) : false; if ($strBuffer === false) { static::redirectToStep('complete', $objOrder); } $this->Template->showForm = false; $this->doNotSubmit = true; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); break; // Checkout/payment has failed, show the review page again with an error message // Checkout/payment has failed, show the review page again with an error message case 'failed': $this->Template->mtype = 'error'; $this->Template->message = strlen(\Input::get('reason')) ? \Input::get('reason') : $GLOBALS['TL_LANG']['ERR']['orderFailed']; $this->strCurrentStep = 'review'; // no break // no break default: // canCheckout will override the template and show a message if (!$this->canCheckout()) { return; } $arrBuffer = $this->generateSteps($this->getSteps()); break; } RowClass::withKey('class')->addFirstLast()->applyTo($arrBuffer); $this->Template->fields = $arrBuffer; }
/** * Get the order object in a postsale request * @return IsotopeProductCollection */ public function getPostsaleOrder() { return Order::findByPk(\Input::post('ORDER_NUMBER')); }