public static function loginModuleOverride($arguments) { $smarty = $arguments[1]; $smarty->assign("loginoverride", ""); if (Session::isCustomerLoggedIn()) { $customer = Customer::getById(Session::getLoggedInCustomer()); $smarty->assign("loginoverride", "userpanel"); $smarty->assign("userRealName", $customer->getFirstname() . " " . $customer->getSurname()); } }
public function update() { $user = new Customer($this->db); if ($this->f3->exists('POST.update')) { $user->edit($this->f3->get('POST.id')); $this->f3->reroute('/customer'); } else { $user->getById($this->f3->get('PARAMS.id')); $this->f3->set('user', $user); $this->f3->set('page_head', 'Update Customer'); $this->f3->set('view', 'customer/update.htm'); } echo Template::instance()->render('layout.htm'); }
protected function runPage() { try { $id = WebRequest::getInt("id"); $hash = WebRequest::get("hash"); // data validation $customer = Customer::getById($id); if ($customer == null) { throw new NonexistantObjectException(); } $customer->confirmEmail($hash); // save $customer->save(); Session::setLoggedInCustomer($id); $this->mSmarty->assign("content", Message::getMessage("mail-confirmed")); } catch (NonexistantObjectException $ex) { global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}"; } }
protected function runPage() { $this->mBasePage = "book.tpl"; global $cWebPath; $this->mStyles[] = $cWebPath . '/style/jsDatePick_ltr.min.css'; $this->mScripts[] = $cWebPath . '/scripts/jsDatePick.full.1.3.js'; // set up the default values for the if (WebRequest::wasPosted()) { $this->mSmarty->assign("valQbCheckin", WebRequest::postString("qbCheckin")); $this->mSmarty->assign("valQbCheckout", WebRequest::postString("qbCheckout")); $this->mSmarty->assign("valQbAdults", WebRequest::postInt("qbAdults")); $this->mSmarty->assign("valQbChildren", WebRequest::postInt("qbChildren")); $this->mSmarty->assign("valQbPromoCode", WebRequest::postString("qbPromoCode")); } else { $this->mSmarty->assign("valQbCheckin", ""); $this->mSmarty->assign("valQbCheckout", ""); $this->mSmarty->assign("valQbAdults", ""); $this->mSmarty->assign("valQbChildren", ""); $this->mSmarty->assign("valQbPromoCode", ""); } if (Session::isCustomerLoggedIn()) { $customer = Customer::getById(Session::getLoggedInCustomer()); $this->mSmarty->assign("qbTitle", $customer->getTitle()); $this->mSmarty->assign("qbFirstname", $customer->getFirstname()); $this->mSmarty->assign("qbLastname", $customer->getSurname()); $this->mSmarty->assign("qbAddress", $customer->getAddress()->getLine1()); $this->mSmarty->assign("qbCity", $customer->getAddress()->getCity()); $this->mSmarty->assign("qbPostcode", $customer->getAddress()->getPostcode()); $this->mSmarty->assign("qbCountry", $customer->getAddress()->getCountry()); $this->mSmarty->assign("qbEmail", $customer->getEmail()); } else { $this->mSmarty->assign("qbTitle", ""); $this->mSmarty->assign("qbFirstname", ""); $this->mSmarty->assign("qbLastname", ""); $this->mSmarty->assign("qbAddress", ""); $this->mSmarty->assign("qbCity", ""); $this->mSmarty->assign("qbPostcode", ""); $this->mSmarty->assign("qbEmail", ""); $this->mSmarty->assign("qbCountry", " "); } }
protected function runPage() { if (Session::isCustomerLoggedIn()) { global $cWebPath; // redirect to main page $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/index.php"; return; } if (WebRequest::wasPosted()) { if (WebRequest::get("id") && WebRequest::get("hash")) { // setting password $id = WebRequest::get("id"); $hash = WebRequest::get("hash"); $customer = Customer::getById($id); try { if ($customer->getMailChecksum() != $hash) { throw new InvalidChecksumException(); } $suPassword = WebRequest::post("suPassword"); $suConfirm = WebRequest::post("suConfirm"); // validation if ($suPassword == "") { throw new CreateCustomerException("Password not specified"); } if ($suConfirm == "") { throw new CreateCustomerException("Confirmed password not specified"); } if ($suPassword != $suConfirm) { throw new CreateCustomerException("Password mismatch"); } // validation if ($suPassword != "" && $suPassword == $suConfirm) { $customer->setPassword($suPassword); } $customer->save(); // log them in Session::setLoggedInCustomer($id); // redirect to main page global $cWebPath; $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/index.php"; } catch (CreateCustomerException $ex) { $this->mBasePage = "changePassword.tpl"; $this->error($ex->getMessage()); } catch (InvalidChecksumException $ex) { $this->mBasePage = "changePassword.tpl"; $this->error($ex->getMessage()); } } else { // requesting try { $suEmail = WebRequest::post("suEmail"); // validation if ($suEmail == "") { throw new CreateCustomerException("Email not specified"); } $customer = Customer::getByEmail($suEmail); if ($customer == null) { throw new NonexistantObjectException(); } $customer->sendPasswordReset(); $this->mBasePage = "forgotpassword.tpl"; // TODO: show some confirmation, check email, etc } catch (CreateCustomerException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error($ex->getMessage()); } catch (NonexistantObjectException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error("nonexistant object"); } } } else { if (WebRequest::get("id") && WebRequest::get("hash")) { // show reset password form try { $id = WebRequest::get("id"); $hash = WebRequest::get("hash"); $customer = Customer::getById($id); if ($customer->getMailChecksum() != $hash) { throw new InvalidChecksumException(); } $this->mBasePage = "changePassword.tpl"; $this->mSmarty->assign("cpid", $id); $this->mSmarty->assign("cphash", $hash); } catch (InvalidChecksumException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error("invalid checksum"); } } else { // show request form $this->mBasePage = "forgottenpassword.tpl"; return; } } }
/** * Authenticate a Customer * * @global ADONewConnection $objDatabase Database connection object * @return boolean True if the Customer could be * authenticated successfully, * false otherwise. * @access private */ private static function _authenticate() { if (self::$objCustomer) { return true; } $objUser = \FWUser::getFWUserObject()->objUser; if ($objUser->login()) { self::$objCustomer = Customer::getById($objUser->getId()); if (self::$objCustomer) { // This is still required in confirm() (TODO: remove) $_SESSION['shop']['username'] = self::$objCustomer->username(); $_SESSION['shop']['email'] = self::$objCustomer->email(); //\DBG::log("Shop::_authenticate(): Success! (".self::$objCustomer->firstname().' '.self::$objCustomer->lastname().', '.self::$objCustomer->username().', email '.self::$objCustomer->email().")"); $_SESSION->cmsSessionUserUpdate(self::$objCustomer->id()); return true; } } //\DBG::log("Shop::_authenticate(): Failed!"); return false; }
/** * Send a confirmation e-mail with the order data * * Calls {@see Orders::getSubstitutionArray()}, which en route * creates User accounts for individual electronic Products by default. * Set $create_accounts to false when sending a copy. * @static * @param integer $order_id The order ID * @param boolean $create_accounts Create User accounts for electronic * Products it true * @return boolean The Customers' e-mail address * on success, false otherwise * @access private */ static function sendConfirmationMail($order_id, $create_accounts = true) { $arrSubstitution = Orders::getSubstitutionArray($order_id, $create_accounts); $customer_id = $arrSubstitution['CUSTOMER_ID']; $objCustomer = Customer::getById($customer_id); if (!$objCustomer) { //die("Failed to get Customer for ID $customer_id"); return false; } $arrSubstitution += $objCustomer->getSubstitutionArray() + self::getSubstitutionArray() + array('TIMESTAMP' => date(ASCMS_DATE_FORMAT_INTERNATIONAL_DATETIME, date_timestamp_get(date_create())), 'ROOT_URL' => \Cx\Core\Routing\Url::fromDocumentRoot()->toString()); //DBG::log("sendConfirmationMail($order_id, $create_accounts): Subs: ".var_dump($arrSubstitution, true)); if (empty($arrSubstitution)) { return false; } // Prepared template for order confirmation $arrMailTemplate = array('section' => 'Shop', 'key' => 'order_confirmation', 'lang_id' => $arrSubstitution['LANG_ID'], 'to' => $arrSubstitution['CUSTOMER_EMAIL'] . ',' . \Cx\Core\Setting\Controller\Setting::getValue('email_confirmation', 'Shop'), 'substitution' => &$arrSubstitution); //DBG::log("sendConfirmationMail($order_id, $create_accounts): Template: ".var_export($arrMailTemplate, true)); //DBG::log("sendConfirmationMail($order_id, $create_accounts): Substitution: ".var_export($arrSubstitution, true)); // NOTE: Creates some XML order file (for customizing) // $template = file_get_contents( // ASCMS_MODULE_PATH.'/Shop/View/Template/Backend/module_shop_export_orders.xml'); // \Cx\Core\MailTemplate\Controller\MailTemplate::substitute($template, $arrSubstitution, true); // // Strip leftover comments from blocks: "<!---->" or "<!-- -->" // $template = preg_replace('/<!--\s*-->/', '', $template); // $file = new Cx\Lib\FileSystem\File( // ASCMS_DOCUMENT_ROOT.'/orders/'.$order_id.'.xml'); // //$file->makeWritable(); // Fails on win32 // $file->write($template); /// if (!\Cx\Core\MailTemplate\Controller\MailTemplate::send($arrMailTemplate)) { return false; } return $arrSubstitution['CUSTOMER_EMAIL']; }
/** * 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 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; }
/** * Toggles the Customer status for the given ID * * If the Customer doesn't exist to begin with, returns null. * @param integer $id The Customer ID * @return boolean True on success, false on failure, * or null otherwise */ static function toggleStatusById($id) { $objCustomer = Customer::getById($id); if ($objCustomer === null) { return null; } $objCustomer->active(!$objCustomer->active()); return $objCustomer->store(); }
public function getCustomer() { return Customer::getById($this->customer); }
/** * View of this Orders' items * @global ADONewConnection $objDatabase * @global array $_ARRAYLANG * @param HTML_Template_Sigma $objTemplate The template * @param type $edit If true, items are editable * @param type $total_weight Initial value for the * total item weight, by * reference. * Usually empty or zero * @param type $i Initial value for the row * count, by reference. * Usually empty or zero. * @return float The net item sum on success, * false otherwise */ function view_items($objTemplate, $edit, &$total_weight = 0, $i = 0) { global $objDatabase, $_ARRAYLANG; // Order items // c_sp // Mind the custom price calculation $objCustomer = Customer::getById($this->customer_id); if (!$objCustomer) { \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_ORDER_ERROR_MISSING_CUSTOMER'], $this->customer_id)); $objCustomer = new Customer(); } $query = "\n SELECT `id`, `product_id`, `product_name`,\n `price`, `quantity`, `vat_rate`, `weight`\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_items`\n WHERE `order_id`=?"; $objResult = $objDatabase->Execute($query, array($this->id)); if (!$objResult) { return self::errorHandler(); } $arrProductOptions = $this->getOptionArray(); $total_vat_amount = 0; $total_net_price = 0; // Orders with Attributes cannot currently be edited // (this would spoil all the options!) // $have_option = false; while (!$objResult->EOF) { $item_id = $objResult->fields['id']; $name = $objResult->fields['product_name']; $price = $objResult->fields['price']; $quantity = $objResult->fields['quantity']; $vat_rate = $objResult->fields['vat_rate']; $product_id = $objResult->fields['product_id']; // Get missing product details $objProduct = Product::getById($product_id); if (!$objProduct) { \Message::warning(sprintf($_ARRAYLANG['TXT_SHOP_PRODUCT_NOT_FOUND'], $product_id)); $objProduct = new Product('', 0, $name, '', $price, 0, 0, 0, $product_id); } $code = $objProduct->code(); $distribution = $objProduct->distribution(); if (isset($arrProductOptions[$item_id])) { if ($edit) { // Edit options } else { //DBG::log("Order::view_items(): Item ID $item_id, Attributes: ".var_export($arrProductOptions[$item_id], true)); // Verify that options are properly shown foreach ($arrProductOptions[$item_id] as $attribute_id => $attribute) { //DBG::log("Order::view_items(): Added option, price: $options_price"); foreach ($attribute as $a) { $name .= '<i><br />- ' . $attribute_id . ': ' . $a['name'] . ' (' . $a['price'] . ')</i>'; $price += $a['price']; } } } } // c_sp $row_net_price = $price * $quantity; $row_price = $row_net_price; // VAT added later, if applicable $total_net_price += $row_net_price; // Here, the VAT has to be recalculated before setting up the // fields. If the VAT is excluded, it must be added here. // Note: the old Order.vat_amount field is no longer valid, // individual shop_order_items *MUST* have been UPDATEd by the // time PHP parses this line. // Also note that this implies that the vat_id and // country_id can be ignored, as they are considered when the // order is placed and the VAT is applied to the order // accordingly. // Calculate the VAT amount per row, included or excluded $row_vat_amount = Vat::amount($vat_rate, $row_net_price); //\DBG::log("$row_vat_amount = Vat::amount($vat_rate, $row_net_price)"); // and add it to the total VAT amount $total_vat_amount += $row_vat_amount; if (!Vat::isIncluded()) { // Add tax to price $row_price += $row_vat_amount; } //else { // VAT is disabled. // There shouldn't be any non-zero percentages in the order_items! // but if there are, there probably has been a change and we *SHOULD* // still treat them as if VAT had been enabled at the time the order // was placed! // That's why the else {} block is commented out. //} $weight = '-'; if ($distribution != 'download') { $weight = $objResult->fields['weight']; if (intval($weight) > 0) { $total_weight += $weight * $quantity; } } $itemHasOptions = !empty($arrProductOptions[$item_id]); $objTemplate->setVariable(array('SHOP_PRODUCT_ID' => $product_id, 'SHOP_ROWCLASS' => 'row' . (++$i % 2 + 1), 'SHOP_QUANTITY' => $quantity, 'SHOP_PRODUCT_NAME' => $name, 'SHOP_PRODUCT_PRICE' => Currency::formatPrice($price), 'SHOP_PRODUCT_SUM' => Currency::formatPrice($row_net_price), 'SHOP_P_ID' => $edit ? $item_id : $objResult->fields['product_id'], 'SHOP_PRODUCT_CODE' => $code, 'SHOP_PRODUCT_TAX_RATE' => $edit ? $vat_rate : Vat::format($vat_rate), 'SHOP_PRODUCT_TAX_AMOUNT' => Currency::formatPrice($row_vat_amount), 'SHOP_PRODUCT_WEIGHT' => Weight::getWeightString($weight), 'SHOP_ACCOUNT_VALIDITY' => \FWUser::getValidityString($weight))); // Get a product menu for each Product if $edit-ing. // Preselect the current Product ID. if ($edit) { if ($itemHasOptions && $objTemplate->blockExists('order_item_product_options_tooltip')) { $objTemplate->touchBlock('order_item_product_options_tooltip'); } $objTemplate->setVariable('SHOP_PRODUCT_IDS_MENU', Products::getMenuoptions($product_id, null, +$_ARRAYLANG['TXT_SHOP_PRODUCT_MENU_FORMAT'], false)); } $objTemplate->parse('order_item'); $objResult->MoveNext(); } return $total_net_price; }
/** * Store a customer * * Sets a Message according to the outcome. * Note that failure to send the e-mail with login data is not * considered an error and will only produce a warning. * @return integer The Customer ID on success, null otherwise * @author Reto Kohli <*****@*****.**> */ static function storeCustomerFromPost() { global $_ARRAYLANG; $username = trim(strip_tags(contrexx_input2raw($_POST['username']))); $password = trim(strip_tags(contrexx_input2raw($_POST['password']))); $company = trim(strip_tags(contrexx_input2raw($_POST['company']))); $gender = trim(strip_tags(contrexx_input2raw($_POST['gender']))); $firstname = trim(strip_tags(contrexx_input2raw($_POST['firstname']))); $lastname = trim(strip_tags(contrexx_input2raw($_POST['lastname']))); $address = trim(strip_tags(contrexx_input2raw($_POST['address']))); $city = trim(strip_tags(contrexx_input2raw($_POST['city']))); $zip = trim(strip_tags(contrexx_input2raw($_POST['zip']))); $country_id = intval($_POST['country_id']); $phone = trim(strip_tags(contrexx_input2raw($_POST['phone']))); $fax = trim(strip_tags(contrexx_input2raw($_POST['fax']))); $email = trim(strip_tags(contrexx_input2raw($_POST['email']))); $companynote = trim(strip_tags(contrexx_input2raw($_POST['companynote']))); $customer_active = intval($_POST['active']); $is_reseller = intval($_POST['customer_type']); $customer_group_id = intval($_POST['customer_group_id']); // $registerdate = trim(strip_tags(contrexx_input2raw($_POST['registerdate']))); $lang_id = isset($_POST['customer_lang_id']) ? intval($_POST['customer_lang_id']) : FRONTEND_LANG_ID; $customer_id = intval($_REQUEST['customer_id']); $objCustomer = Customer::getById($customer_id); if (!$objCustomer) { $objCustomer = new Customer(); } $objCustomer->gender($gender); $objCustomer->company($company); $objCustomer->firstname($firstname); $objCustomer->lastname($lastname); $objCustomer->address($address); $objCustomer->city($city); $objCustomer->zip($zip); $objCustomer->country_id($country_id); $objCustomer->phone($phone); $objCustomer->fax($fax); $objCustomer->email($email); $objCustomer->companynote($companynote); $objCustomer->active($customer_active); $objCustomer->is_reseller($is_reseller); // Set automatically: $objCustomer->setRegisterDate($registerdate); $objCustomer->group_id($customer_group_id); $objCustomer->username($username); if (isset($_POST['sendlogindata']) && $password == '') { $password = \User::make_password(); } if ($password != '') { $objCustomer->password($password); } $objCustomer->setFrontendLanguage($lang_id); if (!$objCustomer->store()) { foreach ($objCustomer->error_msg as $message) { \Message::error($message); } return null; } \Message::ok($_ARRAYLANG['TXT_DATA_RECORD_UPDATED_SUCCESSFUL']); if (isset($_POST['sendlogindata'])) { // TODO: Use a common sendLogin() method $lang_id = $objCustomer->getFrontendLanguage(); $arrSubs = $objCustomer->getSubstitutionArray(); $arrSubs['CUSTOMER_LOGIN'] = array(0 => array('CUSTOMER_USERNAME' => $username, 'CUSTOMER_PASSWORD' => $password)); //DBG::log("Subs: ".var_export($arrSubs, true)); // Select template for sending login data $arrMailTemplate = array('key' => 'customer_login', 'section' => 'Shop', 'lang_id' => $lang_id, 'to' => $email, 'substitution' => $arrSubs); if (!\Cx\Core\MailTemplate\Controller\MailTemplate::send($arrMailTemplate)) { \Message::warning($_ARRAYLANG['TXT_MESSAGE_SEND_ERROR']); return $objCustomer->id(); } \Message::ok(sprintf($_ARRAYLANG['TXT_EMAIL_SEND_SUCCESSFULLY'], $email)); } return $objCustomer->id(); }
private function showAccount() { if (WebRequest::wasPosted()) { try { // get variables $suTitle = WebRequest::post("suTitle"); $suFirstname = WebRequest::post("suFirstname"); $suLastname = WebRequest::post("suLastname"); $suAddress = WebRequest::post("suAddress"); $suCity = WebRequest::post("suCity"); $suPostcode = WebRequest::post("suPostcode"); $suCountry = WebRequest::post("suCountry"); $suEmail = WebRequest::post("suEmail"); $suPassword = WebRequest::post("suPassword"); $suConfirm = WebRequest::post("suConfirm"); $id = Session::getLoggedInCustomer(); // data validation if ($suTitle == "") { throw new CreateCustomerException("suTitle not specified"); } if ($suFirstname == "") { throw new CreateCustomerException("suFirstname not specified"); } if ($suLastname == "") { throw new CreateCustomerException("suLastname not specified"); } if ($suAddress == "") { throw new CreateCustomerException("suAddress not specified"); } if ($suCity == "") { throw new CreateCustomerException("suCity not specified"); } if ($suPostcode == "") { throw new CreateCustomerException("suPostcode not specified"); } if ($suCountry == "") { throw new CreateCustomerException("suCountry not specified"); } if ($suEmail == "") { throw new CreateCustomerException("suEmail not specified"); } $customer = Customer::getById($id); if ($customer == null) { throw new Exception("Custoemr does not exist"); } if ($suPassword != "" && $suPassword == $suConfirm) { $customer->setPassword($suPassword); } // set values $customer->setTitle($suTitle); $customer->setFirstname($suFirstname); $customer->setSurname($suLastname); $address = $customer->getAddress(); $address->setLine1($suAddress); $address->setCity($suCity); $address->setPostcode($suPostcode); $address->setCountry($suCountry); if ($customer->getEmail() != $suEmail) { $customer->setEmail($suEmail); $customer->sendMailConfirm(); } // save it $address->save(); $customer->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Account"; } catch (CreateCustomerException $ex) { $this->mBasePage = "account.tpl"; $this->error($ex->getMessage()); } } else { $this->mBasePage = "account.tpl"; $customer = Customer::getById(Session::getLoggedInCustomer()); if ($customer == null) { throw new Exception("Customer does not exist"); } $this->mSmarty->assign("custid", $customer->getId()); $this->mSmarty->assign("suTitle", $customer->getTitle()); $this->mSmarty->assign("suFirstname", $customer->getFirstName()); $this->mSmarty->assign("suLastname", $customer->getSurname()); $this->mSmarty->assign("suAddress", $customer->getAddress()->getLine1()); $this->mSmarty->assign("suCity", $customer->getAddress()->getCity()); $this->mSmarty->assign("suPostcode", $customer->getAddress()->getPostcode()); $this->mSmarty->assign("suCountry", $customer->getAddress()->getCountry()); $this->mSmarty->assign("suEmail", $customer->getEmail()); } }
private function doResendCustomerAction() { $cid = WebRequest::getInt("id"); if ($cid < 1) { throw new Exception("CustomerId too small"); } $customer = Customer::getById($cid); if ($customer == null) { throw new Exception("CustomerId does not exist"); } $customer->setEmail($customer->getEmail()); $customer->save(); $customer->sendMailConfirm(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Customers"; }