/** * Check in the payment processor after the payment is complete. * @return mixed For external payment methods: * The integer order ID, if known, upon success * For internal payment methods: * Boolean true, in order to make these skip the order * status update, as this has already been done. * If the order ID is unknown or upon failure: * Boolean false */ static function checkIn() { //DBG::log("PaymentProcessing::checkIn(): Entered"); //DBG::log("POST: ".var_export($_POST, true)); //DBG::log("GET: ".var_export($_GET, true)); $result = NULL; if (isset($_GET['result'])) { $result = abs(intval($_GET['result'])); if ($result == 0 || $result == 2) { return false; } } if (empty($_REQUEST['handler'])) { return false; } switch ($_REQUEST['handler']) { case 'paymill_cc': case 'paymill_elv': case 'paymill_iban': $arrShopOrder = array('order_id' => $_SESSION['shop']['order_id'], 'amount' => intval(bcmul($_SESSION['shop']['grand_total_price'], 100, 0)), 'currency' => Currency::getActiveCurrencyCode(), 'note' => $_SESSION['shop']['note']); $response = \PaymillHandler::processRequest($_REQUEST['paymillToken'], $arrShopOrder); \DBG::log(var_export($response, true)); if ($response['status'] === 'success') { return true; } else { \DBG::log("PaymentProcessing::checkIn(): WARNING: paymill: Payment verification failed; errors: " . var_export($response, true)); return false; } case 'saferpay': $arrShopOrder = array('ACCOUNTID' => \Cx\Core\Setting\Controller\Setting::getValue('saferpay_id', 'Shop')); $id = \Saferpay::payConfirm(); if (\Cx\Core\Setting\Controller\Setting::getValue('saferpay_finalize_payment', 'Shop')) { $arrShopOrder['ID'] = $id; $id = \Saferpay::payComplete($arrShopOrder); } //DBG::log("Transaction: ".var_export($transaction, true)); return (bool) $id; case 'paypal': if (empty($_POST['custom'])) { //DBG::log("PaymentProcessing::checkIn(): No custom parameter, returning NULL"); return NULL; } $order_id = \PayPal::getOrderId(); // if (!$order_id) { // $order_id = (isset($_SESSION['shop']['order_id']) // ? $_SESSION['shop']['order_id'] // : (isset ($_SESSION['shop']['order_id_checkin']) // ? $_SESSION['shop']['order_id_checkin'] // : NULL)); // } $order = Order::getById($order_id); $amount = $currency_id = $customer_email = NULL; if ($order) { $amount = $order->sum(); $currency_id = $order->currency_id(); $customer_id = $order->customer_id(); $customer = Customer::getById($customer_id); if ($customer) { $customer_email = $customer->email(); } } $currency_code = Currency::getCodeById($currency_id); return \PayPal::ipnCheck($amount, $currency_code, $order_id, $customer_email, \Cx\Core\Setting\Controller\Setting::getValue('paypal_account_email', 'Shop')); case 'yellowpay': $passphrase = \Cx\Core\Setting\Controller\Setting::getValue('postfinance_hash_signature_out', 'Shop'); return \Yellowpay::checkIn($passphrase); // if (\Yellowpay::$arrError || \Yellowpay::$arrWarning) { // global $_ARRAYLANG; // echo('<font color="red"><b>'. // $_ARRAYLANG['TXT_SHOP_PSP_FAILED_TO_INITIALISE_YELLOWPAY']. // '</b><br />'. // 'Errors:<br />'. // join('<br />', \Yellowpay::$arrError). // 'Warnings:<br />'. // join('<br />', \Yellowpay::$arrWarning). // '</font>'); // } // if (\Yellowpay::$arrError || \Yellowpay::$arrWarning) { // global $_ARRAYLANG; // echo('<font color="red"><b>'. // $_ARRAYLANG['TXT_SHOP_PSP_FAILED_TO_INITIALISE_YELLOWPAY']. // '</b><br />'. // 'Errors:<br />'. // join('<br />', \Yellowpay::$arrError). // 'Warnings:<br />'. // join('<br />', \Yellowpay::$arrWarning). // '</font>'); // } case 'payrexx': return \PayrexxProcessor::checkIn(); // Added 20100222 -- Reto Kohli // Added 20100222 -- Reto Kohli case 'mobilesolutions': // A return value of null means: Do not change the order status if (empty($_POST['state'])) { return null; } $result = \PostfinanceMobile::validateSign(); if ($result) { //DBG::log("PaymentProcessing::checkIn(): mobilesolutions: Payment verification successful!"); } else { DBG::log("PaymentProcessing::checkIn(): WARNING: mobilesolutions: Payment verification failed; errors: " . var_export(\PostfinanceMobile::getErrors(), true)); } return $result; // Added 20081117 -- Reto Kohli // Added 20081117 -- Reto Kohli case 'datatrans': return \Datatrans::validateReturn() && \Datatrans::getPaymentResult() == 1; // For the remaining types, there's no need to check in, so we // return true and jump over the validation of the order ID // directly to success! // Note: A backup of the order ID is kept in the session // for payment methods that do not return it. This is used // to cancel orders in all cases where false is returned. // For the remaining types, there's no need to check in, so we // return true and jump over the validation of the order ID // directly to success! // Note: A backup of the order ID is kept in the session // for payment methods that do not return it. This is used // to cancel orders in all cases where false is returned. case 'internal': case 'internal_creditcard': case 'internal_debit': case 'internal_lsv': return true; // Dummy payment. // Dummy payment. case 'dummy': $result = ''; if (isset($_REQUEST['result'])) { $result = $_REQUEST['result']; } // Returns the order ID on success, false otherwise return \Dummy::commit($result); default: break; } // Anything else is wrong. return false; }
/** * Returns the Coupon that was used with the Order with the given ID * * If a Coupon was used for that Order, returns it. * Returns false on error, null otherwise (if there is none). * Fails if either the Order or the Customer cannot be found, or if a * query fails. * @param integer $order_id The Order ID * @return Coupon The matching Coupon on success, * false on error, or null otherwise * @static */ static function getByOrderId($order_id) { global $objDatabase; $order_id = intval($order_id); if (!$order_id) { //DBG::log("Coupon::getByOrderId($order_id): Invalid Order ID $order_id"); return false; } $objOrder = Order::getById($order_id); if (!$objOrder) { //DBG::log("Coupon::getByOrderId($order_id): Failed to get Order ID $order_id"); return false; } $customer_id = $objOrder->customer_id(); if (!$customer_id) { //DBG::log("Coupon::getByOrderId($order_id): Invalid Customer ID $customer_id"); return false; } $query = "\n SELECT `coupon`.`code`, `coupon`.`payment_id`,\n `coupon`.`start_time`, `coupon`.`end_time`,\n `coupon`.`minimum_amount`,\n `coupon`.`discount_rate`, `coupon`.`discount_amount`,\n `coupon`.`uses`, `coupon`.`global`,\n `coupon`.`customer_id`, `coupon`.`product_id`\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_discount_coupon` AS `coupon`\n JOIN `" . DBPREFIX . "module_shop_rel_customer_coupon` AS `relation`\n ON `coupon`.`code`=`relation`.`code`\n WHERE `order_id`={$order_id}"; $objResult = $objDatabase->Execute($query); // Failure or none found if (!$objResult) { \DBG::log("Coupon::getByOrderId({$order_id}): ERROR: Query failed"); return self::errorHandler(); } if ($objResult->EOF) { //DBG::log("Coupon::getByOrderId($order_id): No Coupon for Order ID $order_id found"); return null; } $objCoupon = new Coupon(); $objCoupon->code($objResult->fields['code']); $objCoupon->payment_id($objResult->fields['payment_id']); $objCoupon->start_time($objResult->fields['start_time']); $objCoupon->end_time($objResult->fields['end_time']); $objCoupon->minimum_amount($objResult->fields['minimum_amount']); $objCoupon->discount_rate($objResult->fields['discount_rate']); $objCoupon->is_global($objResult->fields['global']); $objCoupon->customer_id($objResult->fields['customer_id']); $objCoupon->product_id($objResult->fields['product_id']); // Subtract the number of times the Coupon has been used $objCoupon->uses($objResult->fields['uses']); if ($objCoupon->uses < 1000000000.0) { $objCoupon->uses($objCoupon->uses - $objCoupon->getUsedCount($customer_id)); } // Subtract the amount used with the Coupon $objCoupon->discount_amount($objResult->fields['discount_amount']); if ($objCoupon->uses < 1000000000.0) { $objCoupon->uses($objCoupon->uses - $objCoupon->getUsedCount($customer_id)); } //DBG::log("Coupon::getByOrderId($order_id): Found ".(var_export($objCoupon, true))); return $objCoupon; }
/** * Restores the Cart from the Order ID given * * Redirects to the login when nobody is logged in. * Redirects to the history overview when the Order cannot be loaded, * or when it does not belong to the current Customer. * When $editable is true, redirects to the detail view of the first * Item for editing. Editing will be disabled otherwise. * @global array $_ARRAYLANG * @param integer $order_id The Order ID * @param boolean $editable Items in the Cart are editable iff true */ static function from_order($order_id, $editable = false) { global $_ARRAYLANG; $objCustomer = Shop::customer(); if (!$objCustomer) { \Message::information($_ARRAYLANG['TXT_SHOP_ORDER_LOGIN_TO_REPEAT']); \Cx\Core\Csrf\Controller\Csrf::redirect(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'login') . '?redirect=' . base64_encode(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'cart') . '?order_id=' . $order_id)); } $customer_id = $objCustomer->getId(); $order = Order::getById($order_id); if (!$order || $order->customer_id() != $customer_id) { \Message::warning($_ARRAYLANG['TXT_SHOP_ORDER_INVALID_ID']); \Cx\Core\Csrf\Controller\Csrf::redirect(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'history')); } // Optional! self::destroy(); $_SESSION['shop']['shipperId'] = $order->shipment_id(); $_SESSION['shop']['paymentId'] = $order->payment_id(); $order_attributes = $order->getOptionArray(); $count = null; $arrAttributes = Attributes::getArray($count, 0, -1, null, array()); // Find an Attribute and option IDs for the reprint type $attribute_id_reprint = $option_id_reprint = NULL; if (!$editable) { //DBG::log("Cart::from_order(): Checking for reprint..."); foreach ($arrAttributes as $attribute_id => $objAttribute) { if ($objAttribute->getType() == Attribute::TYPE_EZS_REPRINT) { //DBG::log("Cart::from_order(): TYPE reprint"); $options = $objAttribute->getOptionArray(); if ($options) { $option_id_reprint = current(array_keys($options)); $attribute_id_reprint = $attribute_id; //DBG::log("Cart::from_order(): Found reprint Attribute $attribute_id_reprint, option $option_id_reprint"); break; } } } } foreach ($order->getItems() as $item) { $item_id = $item['item_id']; $attributes = $order_attributes[$item_id]; $options = array(); foreach ($attributes as $attribute_id => $attribute) { // foreach (array_keys($attribute['options']) as $option_id) { foreach ($attribute['options'] as $option_id => $option) { //DBG::log("Cart::from_order(): Option: ".var_export($option, true)); switch ($arrAttributes[$attribute_id]->getType()) { case Attribute::TYPE_TEXT_OPTIONAL: case Attribute::TYPE_TEXT_MANDATORY: case Attribute::TYPE_TEXTAREA_OPTIONAL: case Attribute::TYPE_TEXTAREA_MANDATORY: case Attribute::TYPE_EMAIL_OPTIONAL: case Attribute::TYPE_EMAIL_MANDATORY: case Attribute::TYPE_URL_OPTIONAL: case Attribute::TYPE_URL_MANDATORY: case Attribute::TYPE_DATE_OPTIONAL: case Attribute::TYPE_DATE_MANDATORY: case Attribute::TYPE_NUMBER_INT_OPTIONAL: case Attribute::TYPE_NUMBER_INT_MANDATORY: case Attribute::TYPE_NUMBER_FLOAT_OPTIONAL: case Attribute::TYPE_NUMBER_FLOAT_MANDATORY: case Attribute::TYPE_EZS_ACCOUNT_3: case Attribute::TYPE_EZS_ACCOUNT_4: case Attribute::TYPE_EZS_IBAN: case Attribute::TYPE_EZS_IN_FAVOR_OF: case Attribute::TYPE_EZS_REFERENCE: case Attribute::TYPE_EZS_CLEARING: case Attribute::TYPE_EZS_DEPOSIT_FOR_6: case Attribute::TYPE_EZS_DEPOSIT_FOR_2L: case Attribute::TYPE_EZS_DEPOSIT_FOR_2H: case Attribute::TYPE_EZS_PURPOSE_35: case Attribute::TYPE_EZS_PURPOSE_50: $options[$attribute_id][] = $option['name']; break; case Attribute::TYPE_EZS_REDPLATE: case Attribute::TYPE_EZS_CONFIRMATION: if (!$attribute_id_reprint) { //DBG::log("Cart::from_order(): No reprint, adding option {$option['name']}"); $options[$attribute_id][] = $option_id; } break; case Attribute::TYPE_EZS_REPRINT: // Automatically added below when appropriate break; default: // case Attribute::TYPE_EZS_ZEWOLOGO: // case Attribute::TYPE_EZS_EXPRESS: // case Attribute::TYPE_EZS_PURPOSE_BOLD: $options[$attribute_id][] = $option_id; break; } //DBG::log("Cart::from_order(): Added option: ".var_export($options, true)); } } if ($attribute_id_reprint) { $options[$attribute_id_reprint][] = $option_id_reprint; //DBG::log("Cart::from_order(): Item has reprint Attribute, added $attribute_id_reprint => ($option_id_reprint)"); } self::add_product(array('id' => $item['product_id'], 'quantity' => $item['quantity'], 'options' => $options)); } if ($attribute_id_reprint) { // Mark the Cart as being unchanged since the restore, so the // additional cost for some Attributes won't be added again. self::restored_order_id($order_id); } \Message::information($_ARRAYLANG['TXT_SHOP_ORDER_RESTORED']); // Enable for production \Cx\Core\Csrf\Controller\Csrf::redirect(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'cart')); }
/** * Returns an array with all placeholders and their values to be * replaced in any shop mailtemplate for the given order ID. * * You only have to set the 'substitution' index value of your MailTemplate * array to the array returned. * Customer data is not included here. See {@see Customer::getSubstitutionArray()}. * Note that this method is now mostly independent of the current session. * The language of the mail template is determined by the browser * language range stored with the order. * @access private * @static * @param integer $order_id The order ID * @param boolean $create_accounts If true, creates User accounts * and Coupon codes. Defaults to true * @return array The array with placeholders as keys * and values from the order on success, * false otherwise */ static function getSubstitutionArray($order_id, $create_accounts = true) { global $_ARRAYLANG; /* $_ARRAYLANG['TXT_SHOP_URI_FOR_DOWNLOAD'].":\r\n". 'http://'.$_SERVER['SERVER_NAME']. "/index.php?section=download\r\n"; */ $objOrder = Order::getById($order_id); if (!$objOrder) { // Order not found return false; } $lang_id = $objOrder->lang_id(); if (!intval($lang_id)) { $lang_id = \FWLanguage::getLangIdByIso639_1($lang_id); } $status = $objOrder->status(); $customer_id = $objOrder->customer_id(); $customer = Customer::getById($customer_id); $payment_id = $objOrder->payment_id(); $shipment_id = $objOrder->shipment_id(); $arrSubstitution = array('CUSTOMER_COUNTRY_ID' => $objOrder->billing_country_id(), 'LANG_ID' => $lang_id, 'NOW' => date(ASCMS_DATE_FORMAT_DATETIME), 'TODAY' => date(ASCMS_DATE_FORMAT_DATE), 'ORDER_ID' => $order_id, 'ORDER_ID_CUSTOM' => ShopLibrary::getCustomOrderId($order_id), 'ORDER_DATE' => date(ASCMS_DATE_FORMAT_DATE, strtotime($objOrder->date_time())), 'ORDER_TIME' => date(ASCMS_DATE_FORMAT_TIME, strtotime($objOrder->date_time())), 'ORDER_STATUS_ID' => $status, 'ORDER_STATUS' => $_ARRAYLANG['TXT_SHOP_ORDER_STATUS_' . $status], 'MODIFIED' => date(ASCMS_DATE_FORMAT_DATETIME, strtotime($objOrder->modified_on())), 'REMARKS' => $objOrder->note(), 'ORDER_SUM' => sprintf('% 9.2f', $objOrder->sum()), 'CURRENCY' => Currency::getCodeById($objOrder->currency_id())); $arrSubstitution += $customer->getSubstitutionArray(); if ($shipment_id) { $arrSubstitution += array('SHIPMENT' => array(0 => array('SHIPMENT_NAME' => sprintf('%-40s', Shipment::getShipperName($shipment_id)), 'SHIPMENT_PRICE' => sprintf('% 9.2f', $objOrder->shipment_amount()))), 'SHIPPING_ADDRESS' => array(0 => array('SHIPPING_COMPANY' => $objOrder->company(), 'SHIPPING_TITLE' => $_ARRAYLANG['TXT_SHOP_' . strtoupper($objOrder->gender())], 'SHIPPING_FIRSTNAME' => $objOrder->firstname(), 'SHIPPING_LASTNAME' => $objOrder->lastname(), 'SHIPPING_ADDRESS' => $objOrder->address(), 'SHIPPING_ZIP' => $objOrder->zip(), 'SHIPPING_CITY' => $objOrder->city(), 'SHIPPING_COUNTRY_ID' => $objOrder->country_id(), 'SHIPPING_COUNTRY' => \Cx\Core\Country\Controller\Country::getNameById($objOrder->country_id()), 'SHIPPING_PHONE' => $objOrder->phone()))); } if ($payment_id) { $arrSubstitution += array('PAYMENT' => array(0 => array('PAYMENT_NAME' => sprintf('%-40s', Payment::getNameById($payment_id)), 'PAYMENT_PRICE' => sprintf('% 9.2f', $objOrder->payment_amount())))); } $arrItems = $objOrder->getItems(); if (!$arrItems) { \Message::warning($_ARRAYLANG['TXT_SHOP_ORDER_WARNING_NO_ITEM']); } // Deduct Coupon discounts, either from each Product price, or // from the items total. Mind that the Coupon has already been // stored with the Order, but not redeemed yet. This is done // in this method, but only if $create_accounts is true. $coupon_code = NULL; $coupon_amount = 0; $objCoupon = Coupon::getByOrderId($order_id); if ($objCoupon) { $coupon_code = $objCoupon->code(); } $orderItemCount = 0; $total_item_price = 0; // Suppress Coupon messages (see Coupon::available()) \Message::save(); foreach ($arrItems as $item) { $product_id = $item['product_id']; $objProduct = Product::getById($product_id); if (!$objProduct) { //die("Product ID $product_id not found"); continue; } //DBG::log("Orders::getSubstitutionArray(): Item: Product ID $product_id"); $product_name = substr($item['name'], 0, 40); $item_price = $item['price']; $quantity = $item['quantity']; // TODO: Add individual VAT rates for Products // $orderItemVatPercent = $objResultItem->fields['vat_percent']; // Decrease the Product stock count, // applies to "real", shipped goods only $objProduct->decreaseStock($quantity); $product_code = $objProduct->code(); // Pick the order items attributes $str_options = ''; // Any attributes? if ($item['attributes']) { $str_options = ' '; // '['; $attribute_name_previous = ''; foreach ($item['attributes'] as $attribute_name => $arrAttribute) { //DBG::log("Attribute /$attribute_name/ => ".var_export($arrAttribute, true)); // NOTE: The option price is optional and may be left out foreach ($arrAttribute as $arrOption) { $option_name = $arrOption['name']; $option_price = $arrOption['price']; $item_price += $option_price; // Recognize the names of uploaded files, // verify their presence and use the original name $option_name_stripped = ShopLibrary::stripUniqidFromFilename($option_name); $path = Order::UPLOAD_FOLDER . $option_name; if ($option_name != $option_name_stripped && \File::exists($path)) { $option_name = $option_name_stripped; } if ($attribute_name != $attribute_name_previous) { if ($attribute_name_previous) { $str_options .= '; '; } $str_options .= $attribute_name . ': ' . $option_name; $attribute_name_previous = $attribute_name; } else { $str_options .= ', ' . $option_name; } // TODO: Add proper formatting with sprintf() and language entries if ($option_price != 0) { $str_options .= ' ' . Currency::formatPrice($option_price) . ' ' . Currency::getActiveCurrencyCode(); } } } // $str_options .= ']'; } // Product details $arrProduct = array('PRODUCT_ID' => $product_id, 'PRODUCT_CODE' => $product_code, 'PRODUCT_QUANTITY' => $quantity, 'PRODUCT_TITLE' => $product_name, 'PRODUCT_OPTIONS' => $str_options, 'PRODUCT_ITEM_PRICE' => sprintf('% 9.2f', $item_price), 'PRODUCT_TOTAL_PRICE' => sprintf('% 9.2f', $item_price * $quantity)); //DBG::log("Orders::getSubstitutionArray($order_id, $create_accounts): Adding article: ".var_export($arrProduct, true)); $orderItemCount += $quantity; $total_item_price += $item_price * $quantity; if ($create_accounts) { // Add an account for every single instance of every Product for ($instance = 1; $instance <= $quantity; ++$instance) { $validity = 0; // Default to unlimited validity // In case there are protected downloads in the cart, // collect the group IDs $arrUsergroupId = array(); if ($objProduct->distribution() == 'download') { $usergroupIds = $objProduct->usergroup_ids(); if ($usergroupIds != '') { $arrUsergroupId = explode(',', $usergroupIds); $validity = $objProduct->weight(); } } // create an account that belongs to all collected // user groups, if any. if (count($arrUsergroupId) > 0) { // The login names are created separately for // each product instance $username = self::usernamePrefix . "_{$order_id}_{$product_id}_{$instance}"; $userEmail = $username . '-' . $arrSubstitution['CUSTOMER_EMAIL']; $userpass = \User::make_password(); $objUser = new \User(); $objUser->setUsername($username); $objUser->setPassword($userpass); $objUser->setEmail($userEmail); $objUser->setAdminStatus(false); $objUser->setActiveStatus(true); $objUser->setGroups($arrUsergroupId); $objUser->setValidityTimePeriod($validity); $objUser->setFrontendLanguage(FRONTEND_LANG_ID); $objUser->setBackendLanguage(FRONTEND_LANG_ID); $objUser->setProfile(array('firstname' => array(0 => $arrSubstitution['CUSTOMER_FIRSTNAME']), 'lastname' => array(0 => $arrSubstitution['CUSTOMER_LASTNAME']), 'company' => array(0 => $arrSubstitution['CUSTOMER_COMPANY']), 'address' => array(0 => $arrSubstitution['CUSTOMER_ADDRESS']), 'zip' => array(0 => $arrSubstitution['CUSTOMER_ZIP']), 'city' => array(0 => $arrSubstitution['CUSTOMER_CITY']), 'country' => array(0 => $arrSubstitution['CUSTOMER_COUNTRY_ID']), 'phone_office' => array(0 => $arrSubstitution['CUSTOMER_PHONE']), 'phone_fax' => array(0 => $arrSubstitution['CUSTOMER_FAX']))); if (!$objUser->store()) { \Message::error(implode('<br />', $objUser->getErrorMsg())); return false; } if (empty($arrProduct['USER_DATA'])) { $arrProduct['USER_DATA'] = array(); } $arrProduct['USER_DATA'][] = array('USER_NAME' => $username, 'USER_PASS' => $userpass); } //echo("Instance $instance"); if ($objProduct->distribution() == 'coupon') { if (empty($arrProduct['COUPON_DATA'])) { $arrProduct['COUPON_DATA'] = array(); } //DBG::log("Orders::getSubstitutionArray(): Getting code"); $code = Coupon::getNewCode(); //DBG::log("Orders::getSubstitutionArray(): Got code: $code, calling Coupon::addCode($code, 0, 0, 0, $item_price)"); Coupon::storeCode($code, 0, 0, 0, $item_price, 0, 0, 10000000000.0, true); $arrProduct['COUPON_DATA'][] = array('COUPON_CODE' => $code); } } // Redeem the *product* Coupon, if possible for the Product if ($coupon_code) { $objCoupon = Coupon::available($coupon_code, $item_price * $quantity, $customer_id, $product_id, $payment_id); if ($objCoupon) { $coupon_code = NULL; $coupon_amount = $objCoupon->getDiscountAmount($item_price, $customer_id); if ($create_accounts) { $objCoupon->redeem($order_id, $customer_id, $item_price * $quantity); } } //\DBG::log("Orders::getSubstitutionArray(): Got Product Coupon $coupon_code"); } } if (empty($arrSubstitution['ORDER_ITEM'])) { $arrSubstitution['ORDER_ITEM'] = array(); } $arrSubstitution['ORDER_ITEM'][] = $arrProduct; } $arrSubstitution['ORDER_ITEM_SUM'] = sprintf('% 9.2f', $total_item_price); $arrSubstitution['ORDER_ITEM_COUNT'] = sprintf('% 4u', $orderItemCount); // Redeem the *global* Coupon, if possible for the Order if ($coupon_code) { $objCoupon = Coupon::available($coupon_code, $total_item_price, $customer_id, null, $payment_id); if ($objCoupon) { $coupon_amount = $objCoupon->getDiscountAmount($total_item_price, $customer_id); if ($create_accounts) { $objCoupon->redeem($order_id, $customer_id, $total_item_price); } } } \Message::restore(); // Fill in the Coupon block with proper discount and amount if ($objCoupon) { $coupon_code = $objCoupon->code(); //\DBG::log("Orders::getSubstitutionArray(): Coupon $coupon_code, amount $coupon_amount"); } if ($coupon_amount) { //\DBG::log("Orders::getSubstitutionArray(): Got Order Coupon $coupon_code"); $arrSubstitution['DISCOUNT_COUPON'][] = array('DISCOUNT_COUPON_CODE' => sprintf('%-40s', $coupon_code), 'DISCOUNT_COUPON_AMOUNT' => sprintf('% 9.2f', -$coupon_amount)); } else { //\DBG::log("Orders::getSubstitutionArray(): No Coupon for Order ID $order_id"); } Products::deactivate_soldout(); if (Vat::isEnabled()) { //DBG::log("Orders::getSubstitutionArray(): VAT amount: ".$objOrder->vat_amount()); $arrSubstitution['VAT'] = array(0 => array('VAT_TEXT' => sprintf('%-40s', Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL']), 'VAT_PRICE' => $objOrder->vat_amount())); } return $arrSubstitution; }
/** * Set up the detail view of the selected order * @access public * @param \Cx\Core\Html\Sigma $objTemplate The Template, by reference * @param boolean $edit Edit if true, view otherwise * @global ADONewConnection $objDatabase Database connection object * @global array $_ARRAYLANG Language array * @return boolean True on success, * false otherwise * @static * @author Reto Kohli <*****@*****.**> (parts) * @version 3.1.0 */ static function view_detail(&$objTemplate = null, $edit = false) { global $objDatabase, $_ARRAYLANG, $objInit; $backend = $objInit->mode == 'backend'; if ($objTemplate->blockExists('order_list')) { $objTemplate->hideBlock('order_list'); } $have_option = false; // The order total -- in the currency chosen by the customer $order_sum = 0; // recalculated VAT total $total_vat_amount = 0; $order_id = intval($_REQUEST['order_id']); if (!$order_id) { return \Message::error($_ARRAYLANG['TXT_SHOP_ORDER_ERROR_INVALID_ORDER_ID']); } if (!$objTemplate) { $template_name = $edit ? 'module_shop_order_edit.html' : 'module_shop_order_details.html'; $objTemplate = new \Cx\Core\Html\Sigma(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseModulePath() . '/Shop/View/Template/Backend'); //DBG::log("Orders::view_list(): new Template: ".$objTemplate->get()); $objTemplate->loadTemplateFile($template_name); //DBG::log("Orders::view_list(): loaded Template: ".$objTemplate->get()); } $objOrder = Order::getById($order_id); if (!$objOrder) { //DBG::log("Shop::shopShowOrderdetails(): Failed to find Order ID $order_id"); return \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_ORDER_NOT_FOUND'], $order_id)); } // lsv data $query = "\n SELECT `holder`, `bank`, `blz`\n FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_lsv\n WHERE order_id={$order_id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return self::errorHandler(); } if ($objResult->RecordCount() == 1) { $objTemplate->setVariable(array('SHOP_ACCOUNT_HOLDER' => contrexx_raw2xhtml($objResult->fields['holder']), 'SHOP_ACCOUNT_BANK' => contrexx_raw2xhtml($objResult->fields['bank']), 'SHOP_ACCOUNT_BLZ' => contrexx_raw2xhtml($objResult->fields['blz']))); } $customer_id = $objOrder->customer_id(); if (!$customer_id) { //DBG::log("Shop::shopShowOrderdetails(): Invalid Customer ID $customer_id"); \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_INVALID_CUSTOMER_ID'], $customer_id)); } $objCustomer = Customer::getById($customer_id); if (!$objCustomer) { //DBG::log("Shop::shopShowOrderdetails(): Failed to find Customer ID $customer_id"); \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_CUSTOMER_NOT_FOUND'], $customer_id)); $objCustomer = new Customer(); // No editing allowed! $have_option = true; } Vat::is_reseller($objCustomer->is_reseller()); Vat::is_home_country(\Cx\Core\Setting\Controller\Setting::getValue('country_id', 'Shop') == $objOrder->country_id()); $objTemplate->setGlobalVariable($_ARRAYLANG + array('SHOP_CURRENCY' => Currency::getCurrencySymbolById($objOrder->currency_id()))); //DBG::log("Order sum: ".Currency::formatPrice($objOrder->sum())); $objTemplate->setVariable(array('SHOP_CUSTOMER_ID' => $customer_id, 'SHOP_ORDERID' => $order_id, 'SHOP_DATE' => date(ASCMS_DATE_FORMAT_INTERNATIONAL_DATETIME, strtotime($objOrder->date_time())), 'SHOP_ORDER_STATUS' => $edit ? Orders::getStatusMenu($objOrder->status(), false, null, 'swapSendToStatus(this.value)') : $_ARRAYLANG['TXT_SHOP_ORDER_STATUS_' . $objOrder->status()], 'SHOP_SEND_MAIL_STYLE' => $objOrder->status() == Order::STATUS_CONFIRMED ? 'display: inline;' : 'display: none;', 'SHOP_SEND_MAIL_STATUS' => $edit ? $objOrder->status() != Order::STATUS_CONFIRMED ? \Html::ATTRIBUTE_CHECKED : '' : '', 'SHOP_ORDER_SUM' => Currency::formatPrice($objOrder->sum()), 'SHOP_DEFAULT_CURRENCY' => Currency::getDefaultCurrencySymbol(), 'SHOP_GENDER' => $edit ? Customer::getGenderMenu($objOrder->billing_gender(), 'billing_gender') : $_ARRAYLANG['TXT_SHOP_' . strtoupper($objOrder->billing_gender())], 'SHOP_COMPANY' => $objOrder->billing_company(), 'SHOP_FIRSTNAME' => $objOrder->billing_firstname(), 'SHOP_LASTNAME' => $objOrder->billing_lastname(), 'SHOP_ADDRESS' => $objOrder->billing_address(), 'SHOP_ZIP' => $objOrder->billing_zip(), 'SHOP_CITY' => $objOrder->billing_city(), 'SHOP_COUNTRY' => $edit ? \Cx\Core\Country\Controller\Country::getMenu('billing_country_id', $objOrder->billing_country_id()) : \Cx\Core\Country\Controller\Country::getNameById($objOrder->billing_country_id()), 'SHOP_PHONE' => $objOrder->billing_phone(), 'SHOP_FAX' => $objOrder->billing_fax(), 'SHOP_EMAIL' => $objOrder->billing_email(), 'SHOP_SHIP_GENDER' => $edit ? Customer::getGenderMenu($objOrder->gender(), 'shipPrefix') : $_ARRAYLANG['TXT_SHOP_' . strtoupper($objOrder->gender())], 'SHOP_SHIP_COMPANY' => $objOrder->company(), 'SHOP_SHIP_FIRSTNAME' => $objOrder->firstname(), 'SHOP_SHIP_LASTNAME' => $objOrder->lastname(), 'SHOP_SHIP_ADDRESS' => $objOrder->address(), 'SHOP_SHIP_ZIP' => $objOrder->zip(), 'SHOP_SHIP_CITY' => $objOrder->city(), 'SHOP_SHIP_COUNTRY' => $edit ? \Cx\Core\Country\Controller\Country::getMenu('shipCountry', $objOrder->country_id()) : \Cx\Core\Country\Controller\Country::getNameById($objOrder->country_id()), 'SHOP_SHIP_PHONE' => $objOrder->phone(), 'SHOP_PAYMENTTYPE' => Payment::getProperty($objOrder->payment_id(), 'name'), 'SHOP_CUSTOMER_NOTE' => $objOrder->note(), 'SHOP_COMPANY_NOTE' => $objCustomer->companynote(), 'SHOP_SHIPPING_TYPE' => $objOrder->shipment_id() ? Shipment::getShipperName($objOrder->shipment_id()) : ' ')); if ($backend) { $objTemplate->setVariable(array('SHOP_CUSTOMER_IP' => $objOrder->ip() ? '<a href="index.php?cmd=NetTools&tpl=whois&address=' . $objOrder->ip() . '" title="' . $_ARRAYLANG['TXT_SHOW_DETAILS'] . '">' . $objOrder->ip() . '</a>' : ' ', 'SHOP_CUSTOMER_HOST' => $objOrder->host() ? '<a href="index.php?cmd=NetTools&tpl=whois&address=' . $objOrder->host() . '" title="' . $_ARRAYLANG['TXT_SHOW_DETAILS'] . '">' . $objOrder->host() . '</a>' : ' ', 'SHOP_CUSTOMER_LANG' => \FWLanguage::getLanguageParameter($objOrder->lang_id(), 'name'), 'SHOP_CUSTOMER_BROWSER' => $objOrder->browser() ? $objOrder->browser() : ' ', 'SHOP_LAST_MODIFIED' => $objOrder->modified_on() && $objOrder->modified_on() != '0000-00-00 00:00:00' ? $objOrder->modified_on() . ' ' . $_ARRAYLANG['TXT_EDITED_BY'] . ' ' . $objOrder->modified_by() : $_ARRAYLANG['TXT_ORDER_WASNT_YET_EDITED'])); } else { // Frontend: Order history ONLY. Repeat the Order, go to cart $objTemplate->setVariable(array('SHOP_ACTION_URI_ENCODED' => \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'cart'))); } $ppName = ''; $psp_id = Payment::getPaymentProcessorId($objOrder->payment_id()); if ($psp_id) { $ppName = PaymentProcessing::getPaymentProcessorName($psp_id); } $objTemplate->setVariable(array('SHOP_SHIPPING_PRICE' => $objOrder->shipment_amount(), 'SHOP_PAYMENT_PRICE' => $objOrder->payment_amount(), 'SHOP_PAYMENT_HANDLER' => $ppName, 'SHOP_LAST_MODIFIED_DATE' => $objOrder->modified_on())); if ($edit) { // edit order $strJsArrShipment = Shipment::getJSArrays(); $objTemplate->setVariable(array('SHOP_SEND_TEMPLATE_TO_CUSTOMER' => sprintf($_ARRAYLANG['TXT_SEND_TEMPLATE_TO_CUSTOMER'], $_ARRAYLANG['TXT_ORDER_COMPLETE']), 'SHOP_SHIPPING_TYP_MENU' => Shipment::getShipperMenu($objOrder->country_id(), $objOrder->shipment_id(), "calcPrice(0);"), 'SHOP_JS_ARR_SHIPMENT' => $strJsArrShipment, 'SHOP_PRODUCT_IDS_MENU_NEW' => Products::getMenuoptions(null, null, $_ARRAYLANG['TXT_SHOP_PRODUCT_MENU_FORMAT']), 'SHOP_JS_ARR_PRODUCT' => Products::getJavascriptArray($objCustomer->group_id(), $objCustomer->is_reseller()))); } $options = $objOrder->getOptionArray(); if (!empty($options[$order_id])) { $have_option = true; } // Order items $total_weight = $i = 0; $total_net_price = $objOrder->view_items($objTemplate, $edit, $total_weight, $i); // Show VAT with the individual products: // If VAT is enabled, and we're both in the same country // ($total_vat_amount has been set above if both conditions are met) // show the VAT rate. // If there is no VAT, the amount is 0 (zero). //if ($total_vat_amount) { // distinguish between included VAT, and additional VAT added to sum $tax_part_percentaged = Vat::isIncluded() ? $_ARRAYLANG['TXT_TAX_PREFIX_INCL'] : $_ARRAYLANG['TXT_TAX_PREFIX_EXCL']; $objTemplate->setVariable(array('SHOP_TAX_PRICE' => Currency::formatPrice($total_vat_amount), 'SHOP_PART_TAX_PROCENTUAL' => $tax_part_percentaged)); //} else { // No VAT otherwise // remove it from the details overview if empty //$objTemplate->hideBlock('taxprice'); //$tax_part_percentaged = $_ARRAYLANG['TXT_NO_TAX']; //} // Parse Coupon if applicable to this product // Coupon $objCoupon = Coupon::getByOrderId($order_id); if ($objCoupon) { $discount = $objCoupon->discount_amount() != 0 ? $objCoupon->discount_amount() : $total_net_price / 100 * $objCoupon->discount_rate(); $objTemplate->setVariable(array('SHOP_COUPON_NAME' => $_ARRAYLANG['TXT_SHOP_DISCOUNT_COUPON_CODE'], 'SHOP_COUPON_CODE' => $objCoupon->code(), 'SHOP_COUPON_AMOUNT' => Currency::formatPrice(-$discount))); $total_net_price -= $discount; //DBG::log("Order::view_detail(): Coupon: ".var_export($objCoupon, true)); } $objTemplate->setVariable(array('SHOP_ROWCLASS_NEW' => 'row' . (++$i % 2 + 1), 'SHOP_TOTAL_WEIGHT' => Weight::getWeightString($total_weight), 'SHOP_NET_PRICE' => Currency::formatPrice($total_net_price))); $objTemplate->setVariable(array('TXT_PRODUCT_ID' => $_ARRAYLANG['TXT_ID'], 'TXT_TAX_RATE' => Vat::isIncluded() ? $_ARRAYLANG['TXT_TAX_PREFIX_INCL'] : $_ARRAYLANG['TXT_TAX_PREFIX_EXCL'], 'TXT_SHOP_ACCOUNT_VALIDITY' => $_ARRAYLANG['TXT_SHOP_VALIDITY'])); // Disable the "edit" button when there are Attributes if ($backend && !$edit) { if ($have_option) { if ($objTemplate->blockExists('order_no_edit')) { $objTemplate->touchBlock('order_no_edit'); } } else { if ($objTemplate->blockExists('order_edit')) { $objTemplate->touchBlock('order_edit'); } } } return true; }