/** * Remove carts that have not been accessed for a given number of days (depending on store config) */ public function deleteOldCarts() { $this->import('Database'); $time = time() - $GLOBALS['TL_CONFIG']['iso_cartTimeout']; $objCarts = $this->Database->execute("SELECT id FROM tl_iso_cart WHERE tstamp<{$time}"); if ($objCarts->numRows) { $arrIds = array(); $objCart = new IsotopeCart(); foreach ($objCarts->fetchEach('id') as $id) { if ($objCart->findBy('id', $id)) { $objOrder = new IsotopeOrder(); if ($objOrder->findBy('cart_id', $objCart->id)) { if ($objOrder->status == '') { $objOrder->delete(); } } $objCart->delete(); $arrIds[] = $id; } } if (!empty($arrIds)) { $this->log('Purged ' . count($arrIds) . ' old guest carts', __METHOD__, TL_CRON); } } }
/** * Initialize the object */ public function __construct() { parent::__construct(); $this->import('Isotope'); }
/** * Return the PayPal form. * * @access public * @return string */ public function checkoutForm() { $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id)) { $this->redirect($this->addToUrl('step=failed', true)); } list($endTag, $startScript, $endScript) = IsotopeFrontend::getElementAndScriptTags(); $strBuffer = ' <h2>' . $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0] . '</h2> <p class="message">' . $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1] . '</p> <form id="payment_form" action="https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"' . $endTag . ' <input type="hidden" name="upload" value="1"' . $endTag . ' <input type="hidden" name="charset" value="UTF-8"' . $endTag . ' <input type="hidden" name="business" value="' . $this->paypal_account . '"' . $endTag . ' <input type="hidden" name="lc" value="' . strtoupper($GLOBALS['TL_LANGUAGE']) . '"' . $endTag; foreach ($this->Isotope->Cart->getProducts() as $objProduct) { $strOptions = ''; $arrOptions = $objProduct->getOptions(); if (is_array($arrOptions) && count($arrOptions)) { $options = array(); foreach ($arrOptions as $option) { $options[] = $option['label'] . ': ' . $option['value']; } $strOptions = ' (' . implode(', ', $options) . ')'; } $strBuffer .= ' <input type="hidden" name="item_number_' . ++$i . '" value="' . $objProduct->sku . '"' . $endTag . ' <input type="hidden" name="item_name_' . $i . '" value="' . $objProduct->name . $strOptions . '"' . $endTag . ' <input type="hidden" name="amount_' . $i . '" value="' . $objProduct->price . '"/> <input type="hidden" name="quantity_' . $i . '" value="' . $objProduct->quantity_requested . '"' . $endTag; } $fltDiscount = 0; foreach ($this->Isotope->Cart->getSurcharges() as $arrSurcharge) { if ($arrSurcharge['add'] === false) { continue; } // PayPal does only support one single discount item if ($arrSurcharge['total_price'] < 0) { $fltDiscount -= $arrSurcharge['total_price']; continue; } $strBuffer .= ' <input type="hidden" name="item_name_' . ++$i . '" value="' . $arrSurcharge['label'] . '"' . $endTag . ' <input type="hidden" name="amount_' . $i . '" value="' . $arrSurcharge['total_price'] . '"' . $endTag; } if ($fltDiscount > 0) { $strBuffer .= ' <input type="hidden" name="discount_amount_cart" value="' . $fltDiscount . '"' . $endTag; } $strBuffer .= ' <input type="hidden" name="no_shipping" value="1"' . $endTag . ' <input type="hidden" name="no_note" value="1"' . $endTag . ' <input type="hidden" name="currency_code" value="' . $this->Isotope->Config->currency . '"' . $endTag . ' <input type="hidden" name="button_subtype" value="services"' . $endTag . ' <input type="hidden" name="return" value="' . $this->Environment->base . IsotopeFrontend::addQueryStringToUrl('uid=' . $objOrder->uniqid, $this->addToUrl('step=complete')) . '"' . $endTag . ' <input type="hidden" name="cancel_return" value="' . $this->Environment->base . $this->addToUrl('step=failed') . '"' . $endTag . ' <input type="hidden" name="rm" value="1"' . $endTag . ' <input type="hidden" name="invoice" value="' . $objOrder->id . '"' . $endTag . ' <input type="hidden" name="address_override" value="' . ($this->debug ? '0' : '1') . '"' . $endTag . ' <input type="hidden" name="first_name" value="' . $this->Isotope->Cart->billingAddress['firstname'] . '"' . $endTag . ' <input type="hidden" name="last_name" value="' . $this->Isotope->Cart->billingAddress['lastname'] . '"' . $endTag . ' <input type="hidden" name="address1" value="' . $this->Isotope->Cart->billingAddress['street_1'] . '"' . $endTag . ' <input type="hidden" name="address2" value="' . $this->Isotope->Cart->billingAddress['street_2'] . '"' . $endTag . ' <input type="hidden" name="zip" value="' . $this->Isotope->Cart->billingAddress['postal'] . '"' . $endTag . ' <input type="hidden" name="city" value="' . $this->Isotope->Cart->billingAddress['city'] . '"' . $endTag . ' <input type="hidden" name="country" value="' . strtoupper($this->Isotope->Cart->billingAddress['country']) . '"' . $endTag . ' <input type="hidden" name="email" value="' . $this->Isotope->Cart->billingAddress['email'] . '"' . $endTag . ' <input type="hidden" name="night_phone_b" value="' . $this->Isotope->Cart->billingAddress['phone'] . '"' . $endTag . ' <input type="hidden" name="notify_url" value="' . $this->Environment->base . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id . '"' . $endTag . ' <input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynowCC_LG.gif:NonHosted"' . $endTag . ' <input type="' . (strlen($this->button) ? 'image" src="' . $this->button . '" border="0"' : 'submit" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]) . '"') . ' alt="PayPal - The safer, easier way to pay online!"' . $endTag . ' </form> ' . $startScript . ' window.addEvent( \'domready\' , function() { $(\'payment_form\').submit(); }); ' . $endScript; return $strBuffer; }
/** * Replaces Isotope-specific InsertTags in Frontend * @param string * @return mixed */ public function replaceIsotopeTags($strTag) { $arrTag = trimsplit('::', $strTag); if ($arrTag[0] == 'isotope') { switch ($arrTag[1]) { case 'cart_items': return $this->Isotope->Cart->items; break; case 'cart_products': return $this->Isotope->Cart->products; break; case 'cart_items_label': $intCount = $this->Isotope->Cart->items; if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['ISO']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['ISO']['productMultiple'] . ')', $intCount); break; case 'cart_products_label': $intCount = $this->Isotope->Cart->products; if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['ISO']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['ISO']['productMultiple'] . ')', $intCount); break; case 'cart_total': return $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->grandTotal); break; case 'cart_subtotal': return $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->subTotal); break; } return ''; } elseif ($arrTag[0] == 'isolabel') { return $this->Isotope->translate($arrTag[1], $arrTag[2]); } elseif ($arrTag[0] == 'order') { $objOrder = new IsotopeOrder(); if ($objOrder->findBy('uniqid', $this->Input->get('uid'))) { return $objOrder->{$arrTag[1]}; } return ''; } elseif ($arrTag[0] == 'product') { // 2 possible use cases: // {{product::attribute}} - gets the data of the current product (GET parameter "product") // {{product::attribute::product_id}} - gets the data of the specified product ID $objProduct = count($arrTag) == 3 ? self::getProduct($arrTag[2]) : self::getProductByAlias($this->Input->get('product')); return $objProduct !== null ? $objProduct->{$arrTag[1]} : ''; } return false; }
/** * Authorize or capture the payment * * @param int * @param float * @param array * @param bool * @access public * @return bool */ public function authCapturePayment($intOrderId, $fltOrderTotal, $blnCapture = false) { //Gather Order data and set IsotopeOrder object $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('id', $intOrderId)) { $objOrder->uniqid = uniqid($this->Isotope->Config->orderPrefix, true); $objOrder->cart_id = $this->Isotope->Cart->id; $objOrder->findBy('id', $objOrder->save()); } $strLineItems = ''; $arrBilling = array(); $arrShipping = array(); $arrProducts = array(); $arrPaymentInfo = array(); //grab any existing payment data. If this is an order where a prior auth was made and a new total greater than the original exists, //we need to re-auth. Otherwise we simply use the old auth with the <= order total. $arrOrderPaymentData = deserialize($objOrder->payment_data, true); //Gather product and address data depending on FE(Cart) or BE(Order) if (TL_MODE == 'FE') { $arrBilling = $this->Isotope->Cart->billingAddress; $arrShipping = $this->Isotope->Cart->shippingAddress; $arrProducts = $this->Isotope->Cart->getProducts(); } else { $arrBilling = $objOrder->billingAddress; $arrShipping = $objOrder->shippingAddress; $arrProducts = $objOrder->getProducts(); } if (count($arrProducts)) { foreach ($arrProducts as $objProduct) { $arrItemData = array(); $arrItemData = array($objProduct->id, $objProduct->name, substr($objProduct->description, 0, 100), $objProduct->quantity_requested, $objProduct->price, $objProduct->tax_class ? 'Y' : 'N'); $arrLineItems[] = implode('<|>', $arrItemData); } $strLineItems .= implode('&', $arrLineItems); } //Authorization type $strAuthType = $blnCapture ? 'PRIOR_AUTH_CAPTURE' : 'AUTH_ONLY'; //Get Address Data $arrBillingSubdivision = explode('-', $arrBilling['subdivision']); $arrShippingSubdivision = explode('-', $arrShipping['subdivision']); //Set up basic request fields required by all transactions $authnet_values_default = array("x_version" => '3.1', "x_login" => $this->authorize_login, "x_tran_key" => $this->authorize_trans_key, "x_type" => $strAuthType, "x_delim_char" => $this->authorize_delimiter, "x_delim_data" => "TRUE", "x_relay_response" => "FALSE", "x_amount" => $fltOrderTotal, "x_test_request" => $this->debug ? "TRUE" : "FALSE"); switch ($strAuthType) { case 'AUTH_ONLY': $authnet_values_authonly = array("x_url" => "FALSE", "x_description" => "Order Number " . $this->Isotope->Config->orderPrefix . $objOrder->order_id, "x_invoice_num" => $objOrder->order_id, "x_first_name" => $arrBilling['firstname'], "x_last_name" => $arrBilling['lastname'], "x_company" => $arrBilling['company'], "x_address" => $arrBilling['street_1'] . "\n" . $arrBilling['street_2'] . "\n" . $arrBilling['street_3'], "x_city" => $arrBilling['city'], "x_state" => $arrBillingSubdivision[1], "x_zip" => $arrBilling['postal'], "x_email_customer" => "FALSE", "x_email" => $arrBilling['email'], "x_country" => $arrBilling['country'], "x_phone" => $arrBilling['phone'], "x_ship_to_first_name" => $arrShipping['firstname'], "x_ship_to_last_name" => $arrShipping['lastname'], "x_ship_to_company" => $arrShipping['company'], "x_ship_to_address" => $arrShipping['street_1'] . "\n" . $arrShipping['street_2'] . "\n" . $arrShipping['street_3'], "x_ship_to_city" => $arrShipping['city'], "x_ship_to_state" => $arrShippingSubdivision[1], "x_ship_to_zip" => $arrShipping['postal'], "x_ship_to_country" => $arrShipping['country']); $authnet_values = array_merge($authnet_values_default, $authnet_values_authonly); break; case 'PRIOR_AUTH_CAPTURE': $arrTransactionData = deserialize($objOrder->payment_data, true); $authnet_values = array_merge($authnet_values_default, array("x_trans_id" => $arrTransactionData['transaction-id'])); break; default: break; } if (!$blnCapture) { $arrPaymentInput = $this->Input->post('payment'); unset($_POST['payment']); $authnet_values["x_method"] = "CC"; $authnet_values["x_card_num"] = $arrPaymentInput['card_accountNumber']; $authnet_values["x_exp_date"] = $arrPaymentInput['card_expirationMonth'] . substr($arrPaymentInput['card_expirationYear'], 2, 2); if ($this->requireCCV) { $authnet_values["x_card_code"] = $arrPaymentInput['card_cvNumber']; } $arrPaymentInfo["x_card_num"] = $this->maskCC($arrData['card_accountNumber']); //PCI COMPLIANCE - MASK THE CC DATA $arrPaymentInfo["x_card_type"] = $GLOBALS['ISO_LANG']['CCT'][$arrData['card_cardType']]; } foreach ($authnet_values as $key => $value) { $fields .= "{$key}=" . urlencode($value) . "&"; } $fieldsFinal = rtrim($fields, '&'); //new auth required if one has been sent and the value of that was less than our new value. if (!count($arrOrderPaymentData) || $arrOrderPaymentData['transaction-status'] != 'Approved' || $blnCapture || !$blnCapture && count($arrOrderPaymentData) && $fltOrderTotal > $arrOrderPaymentData['grand-total']) { $objRequest = new Request(); $objRequest->send('https://' . ($this->debug ? 'test' : 'secure') . '.authorize.net/gateway/transact.dll', $fieldsFinal, 'post'); $arrResponses = $this->handleResponse($objRequest->response); $arrResponseCodes = $this->getResponseCodes($objRequest->response); unset($arrPaymentInput); //clear all cc input foreach (array_keys($arrResponses) as $key) { $arrReponseLabels[standardize($key)] = $key; } $this->loadLanguageFile('payment'); $this->strStatus = $arrResponses['transaction-status']; $this->strReason = $GLOBALS['TL_LANG']['MSG']['authorizedotnet'][$arrResponseCodes['response_type']][$arrResponseCodes['response_code']]; } else { //otherwise, if this isn't a capture, simply bypass/return true. If it is, we need to do some additional work below. if (!$blnCapture) { return true; } } if (!$blnCapture) { switch ($arrResponses['transaction-status']) { case 'Approved': $objOrder->status = $this->new_order_status; $blnFail = false; break; default: $objOrder->status = 'on_hold'; $blnFail = true; break; } } //Update payment data AKA Response Data. Transaction ID will not be saved during test mode. $arrPaymentInfo = count($arrOrderPaymentData) ? array_merge($arrOrderPaymentData, $arrResponses) : $arrResponses; $objOrder->payment_data = serialize($arrPaymentInfo); $objOrder->save(); //unlock the payment submit $_SESSION['CHECKOUT_DATA']['payment']['request_lockout'] = false; if ($blnFail) { $this->log(sprintf("Transaction failure. Transaction Status: %s, Reason: %s", $this->strStatus, $this->strReason), 'PaymentAuthorizeDotNet capturePayment()', TL_ERROR); return false; } return true; }
/** * Generate the module * @return void */ protected function compile() { $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('uniqid', $this->Input->get('uid'))) { $this->Template = new FrontendTemplate('mod_message'); $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound']; return; } $arrOrder = $objOrder->getData(); $this->Template->setData($arrOrder); $this->import('Isotope'); $this->Isotope->overrideConfig($objOrder->config_id); // Article reader $arrPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($this->jumpTo)->fetchAssoc(); $arrAllDownloads = array(); $arrItems = array(); $arrProducts = $objOrder->getProducts(); foreach ($arrProducts as $i => $objProduct) { $arrDownloads = array(); $objDownloads = $this->Database->prepare("SELECT p.*, o.* FROM tl_iso_order_downloads o LEFT OUTER JOIN tl_iso_downloads p ON o.download_id=p.id WHERE o.pid=?")->execute($objProduct->cart_id); while ($objDownloads->next()) { $blnDownloadable = ($objOrder->status == 'complete' || intval($objOrder->date_paid) > 0 && intval($objOrder->date_paid) <= time()) && ($objDownloads->downloads_remaining === '' || $objDownloads->downloads_remaining > 0) ? true : false; // Send file to the browser if (strlen($this->Input->get('file')) && $this->Input->get('file') == $objDownloads->id && $blnDownloadable) { if (!$this->backend && $objDownloads->downloads_remaining !== '') { $this->Database->prepare("UPDATE tl_iso_order_downloads SET downloads_remaining=? WHERE id=?")->execute($objDownloads->downloads_remaining - 1, $objDownloads->id); } $this->sendFileToBrowser($objDownloads->singleSRC); } $arrDownload = array('raw' => $objDownloads->row(), 'title' => $objDownloads->title, 'href' => TL_MODE == 'FE' ? IsotopeFrontend::addQueryStringToUrl('file=' . $objDownloads->id) : '', 'remaining' => $objDownloads->downloads_allowed > 0 ? sprintf($GLOBALS['TL_LANG']['MSC']['downloadsRemaining'], intval($objDownloads->downloads_remaining)) : '', 'downloadable' => $blnDownloadable); $arrDownloads[] = $arrDownload; $arrAllDownloads[] = $arrDownload; } $arrItems[] = array('raw' => $objProduct->getData(), 'sku' => $objProduct->sku, 'name' => $objProduct->name, 'image' => $objProduct->images->main_image, 'product_options' => $objProduct->getOptions(), 'quantity' => $objProduct->quantity_requested, 'price' => $this->Isotope->formatPriceWithCurrency($objProduct->price), 'total' => $this->Isotope->formatPriceWithCurrency($objProduct->total_price), 'href' => $this->jumpTo ? $this->generateFrontendUrl($arrPage, '/product/' . $objProduct->alias) : '', 'tax_id' => $objProduct->tax_id, 'downloads' => $arrDownloads); } $this->Template->info = deserialize($objOrder->checkout_info, true); $this->Template->items = IsotopeFrontend::generateRowClass($arrItems, 'row', 'rowClass', 0, ISO_CLASS_COUNT | ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD); $this->Template->downloads = $arrAllDownloads; $this->Template->downloadsLabel = $GLOBALS['TL_LANG']['MSC']['downloadsLabel']; $this->Template->raw = $arrOrder; $this->Template->date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objOrder->date); $this->Template->time = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objOrder->date); $this->Template->datim = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objOrder->date); $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->order_id, $this->Template->datim); $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $GLOBALS['TL_LANG']['ORDER'][$objOrder->status]); $this->Template->orderStatusKey = $objOrder->status; $this->Template->subTotalPrice = $this->Isotope->formatPriceWithCurrency($objOrder->subTotal); $this->Template->grandTotal = $this->Isotope->formatPriceWithCurrency($objOrder->grandTotal); $this->Template->subTotalLabel = $GLOBALS['TL_LANG']['MSC']['subTotalLabel']; $this->Template->grandTotalLabel = $GLOBALS['TL_LANG']['MSC']['grandTotalLabel']; $this->Template->surcharges = IsotopeFrontend::formatSurcharges($objOrder->getSurcharges()); $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_address']; $this->Template->billing_address = $this->Isotope->generateAddressString($objOrder->billing_address, $this->Isotope->Config->billing_fields); if (strlen($objOrder->shipping_method)) { $arrShippingAddress = $objOrder->shipping_address; if (!is_array($arrShippingAddress) || $arrShippingAddress['id'] == -1) { $this->Template->has_shipping = false; $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_shipping_address']; } else { $this->Template->has_shipping = true; $this->Template->shipping_label = $GLOBALS['TL_LANG']['ISO']['shipping_address']; $this->Template->shipping_address = $this->Isotope->generateAddressString($arrShippingAddress, $this->Isotope->Config->shipping_fields); } } }
/** * Return the payment form. * * @access public * @return string */ public function checkoutForm() { $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id)) { $this->redirect($this->addToUrl('step=failed', true)); } $arrAddress = $this->Isotope->Cart->billingAddress; $strFailedUrl = $this->Environment->base . $this->addToUrl('step=failed'); $arrParam = array('PSPID' => $this->postfinance_pspid, 'orderID' => $objOrder->id, 'amount' => round($this->Isotope->Cart->grandTotal * 100), 'currency' => $this->Isotope->Config->currency, 'language' => $GLOBALS['TL_LANGUAGE'] . '_' . strtoupper($GLOBALS['TL_LANGUAGE']), 'CN' => $arrAddress['firstname'] . ' ' . $arrAddress['lastname'], 'EMAIL' => $arrAddress['email'], 'ownerZIP' => $arrAddress['postal'], 'owneraddress' => $arrAddress['street_1'], 'owneraddress2' => $arrAddress['street_2'], 'ownercty' => $arrAddress['country'], 'ownertown' => $arrAddress['city'], 'ownertelno' => $arrAddress['phone'], 'accepturl' => $this->Environment->base . IsotopeFrontend::addQueryStringToUrl('uid=' . $objOrder->uniqid, $this->addToUrl('step=complete')), 'declineurl' => $strFailedUrl, 'exceptionurl' => $strFailedUrl, 'paramplus' => 'mod=pay&id=' . $this->id); // SHA-1 must be generated on alphabetically sorted keys. Cant use ksort because it does not ignore key case. uksort($arrParam, 'strcasecmp'); $strSHASign = ''; foreach ($arrParam as $k => $v) { if ($v == '') { continue; } $strSHASign .= strtoupper($k) . '=' . $v . $this->postfinance_secret; } $arrParam['SHASign'] = sha1($strSHASign); $objTemplate = new FrontendTemplate('iso_payment_postfinance'); $objTemplate->action = 'https://e-payment.postfinance.ch/ncol/' . ($this->debug ? 'test' : 'prod') . '/orderstandard.asp'; $objTemplate->params = $arrParam; $objTemplate->slabel = $GLOBALS['TL_LANG']['MSC']['pay_with_cc'][2]; $objTemplate->id = $this->id; return $objTemplate->parse(); }
/** * Save the order * @return void */ protected function writeOrder() { $objOrder = new IsotopeOrder(); if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id)) { $objOrder->uniqid = uniqid($this->Isotope->Config->orderPrefix, true); $objOrder->cart_id = $this->Isotope->Cart->id; $objOrder->findBy('id', $objOrder->save()); } $objOrder->pid = FE_USER_LOGGED_IN === true ? $this->User->id : 0; $objOrder->date = time(); $objOrder->config_id = (int) $this->Isotope->Config->id; $objOrder->shipping_id = $this->Isotope->Cart->hasShipping ? $this->Isotope->Cart->Shipping->id : 0; $objOrder->payment_id = $this->Isotope->Cart->hasPayment ? $this->Isotope->Cart->Payment->id : 0; $objOrder->subTotal = $this->Isotope->Cart->subTotal; $objOrder->taxTotal = $this->Isotope->Cart->taxTotal; $objOrder->shippingTotal = $this->Isotope->Cart->shippingTotal; $objOrder->grandTotal = $this->Isotope->Cart->grandTotal; $objOrder->surcharges = $this->Isotope->Cart->getSurcharges(); $objOrder->checkout_info = $this->getCheckoutInfo(); $objOrder->status = ''; $objOrder->language = $GLOBALS['TL_LANGUAGE']; $objOrder->billing_address = $this->Isotope->Cart->billingAddress; $objOrder->shipping_address = $this->Isotope->Cart->shippingAddress; $objOrder->currency = $this->Isotope->Config->currency; $objOrder->iso_sales_email = $this->iso_sales_email ? $this->iso_sales_email : ($GLOBALS['TL_ADMIN_NAME'] != '' ? sprintf('%s <%s>', $GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) : $GLOBALS['TL_ADMIN_EMAIL']); $objOrder->iso_mail_admin = $this->iso_mail_admin; $objOrder->iso_mail_customer = $this->iso_mail_customer; $objOrder->iso_addToAddressbook = $this->iso_addToAddressbook; $objOrder->new_order_status = $this->Isotope->Cart->hasPayment ? $this->Isotope->Cart->Payment->new_order_status : 'pending'; $strCustomerName = ''; $strCustomerEmail = ''; if ($this->Isotope->Cart->billingAddress['email'] != '') { $strCustomerName = $this->Isotope->Cart->billingAddress['firstname'] . ' ' . $this->Isotope->Cart->billingAddress['lastname']; $strCustomerEmail = $this->Isotope->Cart->billingAddress['email']; } elseif ($this->Isotope->Cart->shippingAddress['email'] != '') { $strCustomerName = $this->Isotope->Cart->shippingAddress['firstname'] . ' ' . $this->Isotope->Cart->shippingAddress['lastname']; $strCustomerEmail = $this->Isotope->Cart->shippingAddress['email']; } elseif (FE_USER_LOGGED_IN === true && $this->User->email != '') { $strCustomerName = $this->User->firstname . ' ' . $this->User->lastname; $strCustomerEmail = $this->User->email; } if (trim($strCustomerName) != '') { $strCustomerEmail = sprintf('"%s" <%s>', IsotopeEmail::romanizeFriendlyName($strCustomerName), $strCustomerEmail); } $objOrder->iso_customer_email = $strCustomerEmail; $arrData = array_merge($this->arrOrderData, array('uniqid' => $objOrder->uniqid, 'items' => $this->Isotope->Cart->items, 'products' => $this->Isotope->Cart->products, 'subTotal' => $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->subTotal, false), 'taxTotal' => $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->taxTotal, false), 'shippingPrice' => $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->Shipping->price, false), 'paymentPrice' => $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->Payment->price, false), 'grandTotal' => $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->grandTotal, false), 'cart_text' => strip_tags($this->replaceInsertTags($this->Isotope->Cart->getProducts('iso_products_text'))), 'cart_html' => $this->replaceInsertTags($this->Isotope->Cart->getProducts('iso_products_html')))); $objOrder->email_data = $arrData; $objOrder->save(); }
/** * Button Callback for the MultipleShipping backend interface for label generation * * @access public * @param int * @return string */ public function backendInterfaceMultiple($intOrderId, $intPackageId = 0) { $objOrder = IsotopeOrder::findByPk($intOrderId); $strFormId = 'fedex_backend_interface'; //Check for valid order if ($objOrder === null) { \System::log('Invalid order id.', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } //Get the order's products $arrProducts = array(); $arrItems = (array) $objOrder->getItems(); foreach ($arrItems as $objItem) { $arrProducts[] = $objItem->getProduct(); } //Get the package data $objPackage = \Database::getInstance()->execute("SELECT * FROM tl_iso_packages WHERE id={$intPackageId}"); if (!$objPackage->numRows) { return '<p class="tl_gerror">' . $GLOBALS['TL_LANG']['ISO']['backendShippingNotFound'] . '</p>'; } //Build the initial compiled package data array $arrPackage = array('id' => $objPackage->id, 'address' => deserialize($objPackage->order_address, true), 'formattedaddress' => $objOrder->getShippingAddress()->generateText(), 'status' => $GLOBALS['TL_LANG']['ISO']['multipleshipping'][$objPackage->status], 'formid' => $strFormId . '_' . $objPackage->id); //Check for an existing label thumbnail and create one if it has not been created if ($objPackage->fedex_label) { //Set a cache name $strCacheName = 'system/tmp/fedex_label_' . $objOrder->document_number . '_' . $objPackage->id . substr(md5($arrPackage['formattedaddress']), 0, 8) . '.gif'; $arrPackage['label'] = $this->getShippingLabelImage($objPackage->fedex_label, $strCacheName, 75, 75, 'exact'); $arrPackage['labelLink'] = \Environment::get('request') . '&printLabel=' . $arrPackage['formid']; //Now that we have the label created check for request to output to PDF if (\Input::get('printLabel') == $arrPackage['formid']) { $this->printShippingLabel($strCacheName, 'order_' . $objOrder->document_number . '_' . $intPackageId, true); } } //Add tracking number if (strlen($objPackage->fedex_tracking_number)) { $arrPackage['tracking'] = $objPackage->fedex_tracking_number; } //Add package products $arrShipmentProducts = \Database::getInstance()->execute("SELECT product_id FROM tl_iso_product_collection_item WHERE package_id={$objPackage->id}")->fetchEach('product_id'); foreach ($arrProducts as $objProduct) { if (in_array($objProduct->id, $arrShipmentProducts)) { $arrPackage['products'][] = $objProduct; } } //Data has been submitted. Send request for tracking numbers and label if (\Input::post('FORM_SUBMIT') == $arrPackage['formid']) { $this->Shipment = $arrPackage; list($arrOrigin, $arrDestination, $arrShipment) = $this->buildShipment(); $objFEDEXAPI = new FedExAPIShipping($arrShipment, $arrOrigin, $arrOrigin, $arrDestination); $xmlShip = $objFEDEXAPI->buildRequest(); $arrResponse = $objFEDEXAPI->sendRequest($xmlShip); //Request was successful - add the new data to the package if ((int) $arrResponse['ShipmentAcceptResponse']['Response']['ResponseStatusCode'] == 1) { $objOrder->fedex_tracking_number = $arrResponse['ShipmentAcceptResponse']['ShipmentResults']['ShipmentIdentificationNumber']; $objOrder->fedex_label = $arrResponse['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']; $objOrder->save(); if (\Database::getInstance()->tableExists('tl_iso_packages') && $arrPackage['formid'] != $strFormId . '_' . 'order') { \Database::getInstance()->prepare("UPDATE tl_iso_packages SET fedex_tracking_number=?, fedex_label=?, status='shipped' WHERE id=?")->execute($objOrder->fedex_tracking_number, $objOrder->fedex_label, $arrPackage['id']); } $strCacheName = 'system/tmp/fedex_label_' . $objOrder->document_number . '_' . $objPackage->id . substr(md5($arrPackage['formattedaddress']), 0, 8) . '.gif'; $arrPackage['label'] = $this->getShippingLabelImage($objOrder->fedex_label, $strCacheName); $arrPackage['tracking'] = $objOrder->fedex_tracking_number; } else { //Request returned an error $strDescription = $arrResponse['ShipmentAcceptResponse']["Response"]["ResponseStatusDescription"]; $strError = $arrResponse['ShipmentAcceptResponse']["Response"]["Error"]["ErrorDescription"]; $_SESSION['TL_ERROR'][] = $strDescription . ' - ' . $strError; \System::log(sprintf('Error in shipping digest: %s - %s', $strDescription, $strError), __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } } //Set template data $objTemplate = new IsotopeTemplate('be_iso_fedex'); $objTemplate->setData($arrPackage); $objTemplate->labelHeader = $GLOBALS['TL_LANG']['MSC']['labelLabel']; $objTemplate->trackingHeader = $GLOBALS['TL_LANG']['MSC']['trackingNumberLabel']; $objTemplate->addressHeader = $GLOBALS['TL_LANG']['MSC']['shippingAddress']; $objTemplate->statusHeader = $GLOBALS['TL_LANG']['MSC']['shippingStatus']; $objTemplate->submitLabel = $objPackage->status != 'not_shipped' ? $GLOBALS['TL_LANG']['MSC']['re-ship'] : $GLOBALS['TL_LANG']['MSC']['ship']; return $objTemplate->parse(); }
/** * Execute the saveCollection hook when an order is saved * @param object * @return void */ public function executeSaveHook($dc) { $objOrder = new IsotopeOrder(); if ($objOrder->findBy('id', $dc->id)) { // HOOK for adding additional functionality when saving if (isset($GLOBALS['ISO_HOOKS']['saveCollection']) && is_array($GLOBALS['ISO_HOOKS']['saveCollection'])) { foreach ($GLOBALS['ISO_HOOKS']['saveCollection'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objOrder); } } } }