/** * Views an order list. */ function getOrders() { $result = ""; //SQL queries number optimization $orders =& $this->_fetched_orders; // : $customer_ids = array(); foreach ($orders as $order_info) { $customer_ids[] = $order_info['person_id']; } $customer_names = modApiFunc("Customer_Account", "__fetch_customer_names", $customer_ids); $customer_statuses = modApiFunc("Customer_Account", "__fetch_customer_statuses", $customer_ids); $customer_accounts = modApiFunc("Customer_Account", "__fetch_customer_accounts", $customer_ids); // 2008.06. "main store currency" "customer selected" . // "Main store currency" . "Customer selected" - // , "main store currency" ( ). // - - . // - , , // - . $last_pushed_currency_id = null; foreach ($this->_orders as $order_id) { // , , . // : //$order_currency_id = modApiFunc("Localization", "whichCurrencyToDisplayOrderIn", $order_id, $orders[$order_id]['order_currencies_list']); //$order_currency_code = modApiFunc("Localization", "getCurrencyCodeById", $order_currency_id); // - , . . // CUSTOMER_SELECTED $order_currency_code = $orders[$order_id]['order_currencies_list'][CURRENCY_TYPE_CUSTOMER_SELECTED]['currency_code']; $order_currency_id = modApiFunc("Localization", "getCurrencyIdByCode", $order_currency_code); $order_total = $orders[$order_id]['price_total'][$order_currency_code]['order_total']; if ($last_pushed_currency_id !== null && $last_pushed_currency_id != $order_currency_id) { modApiFunc("Localization", "popDisplayCurrency"); modApiFunc("Localization", "pushDisplayCurrency", $order_currency_id, $order_currency_id); $last_pushed_currency_id = $order_currency_id; } elseif ($last_pushed_currency_id === null) { modApiFunc("Localization", "pushDisplayCurrency", $order_currency_id, $order_currency_id); $last_pushed_currency_id = $order_currency_id; } else { // : . } $order = array(); $order["Date"] = modApiFunc("Localization", "SQL_date_format", $orders[$order_id]['order_date']); $order["Total"] = modApiFunc("Localization", "currency_format", $order_total); $order["IdInt"] = (int) $order_id; $order["Id"] = modApiFunc("Checkout", "outputOrderId", $order_id); $order["PaymentStatusId"] = $orders[$order_id]['payment_status_id']; $order["StatusId"] = $orders[$order_id]['status_id']; $order["PersonId"] = $orders[$order_id]['person_id']; loadClass('CCustomerInfo'); $order["PersonName"] = isset($customer_accounts[$orders[$order_id]['person_id']]) ? CCustomerInfo::getDisplayAccountNameExt($customer_accounts[$orders[$order_id]['person_id']], $customer_statuses[$orders[$order_id]['person_id']]) : ""; $order["PersonInfoName"] = isset($customer_names[$orders[$order_id]['person_id']]) ? htmlspecialchars($customer_names[$orders[$order_id]['person_id']]) : 'N/A'; $order['price_total'] = $orders[$order_id]['price_total']; $order['TotalInMainStoreCurrency'] = NULL; // "customer selected" // "main store currency" - . if ($orders[$order_id]['order_currencies_list'][CURRENCY_TYPE_MAIN_STORE_CURRENCY]['currency_code'] != $orders[$order_id]['order_currencies_list'][CURRENCY_TYPE_CUSTOMER_SELECTED]['currency_code']) { $_currency_code = $orders[$order_id]['order_currencies_list'][CURRENCY_TYPE_MAIN_STORE_CURRENCY]['currency_code']; $_currency_id = modApiFunc("Localization", "getCurrencyIdByCode", $_currency_code); $_total = $orders[$order_id]['price_total'][$_currency_code]['order_total']; // ( ), // . modApiFunc("Localization", "pushDisplayCurrency", $_currency_id, $_currency_id); $order['TotalInMainStoreCurrency'] = modApiFunc("Localization", "currency_format", $_total); modApiFunc("Localization", "popDisplayCurrency"); } $this->_order = $order; $result .= modApiFunc('TmplFiller', 'fill', "checkout/orders/", "item_result.tpl.html", array()); } modApiFunc("Localization", "popDisplayCurrency"); $this->_order = null; return $result; }
/** * The output of the Viewer * Params: the following optional params can be accepted * 0: product_id (use 0 to use default) * 1: container_template (use '' to use default) * 2: empty_template (use '' to use default) * 3: forbidden_template (use '' to use default) * 4: ip_used_template (use '' to use default) * 5: success_template (use '' to use default) * 6: error_template (use '' to use default) * 7: success_message_template (use '' to use default) * 8: error_message_template (use '' to use default) * 9: review_template (use '' to use default) * 10: rating_template (use '' to use default) * 11: rating_rate_template (use '' to use default) * 12: rating_header_template (use '' to use default) * 13: rating_rate_cell_template (use '' to use default) * Note: to use custom templates be sure to dedcribe them in * - avactis-system/admin/blocks_ini/product-add-review-form-block.ini * - getTemplateFormat() function of the class * * The following scheme of templates will be shown * case 1: adding review is disabled for the product * * will be shown: * empty_template (in any case) * * case 2: a new review has just been posted and * posting a new review is not available * (since multiple reviews from the same IP is disabled) * * will be shown: * success_message template * * case 3: an attempt to post a new review has just been done * while posting a new review is not available * (since multiple reviews from the same IP is disabled) * use case: several attempts was done from different windows * * will be shown: * error_message template * * case 3: multiple reviews from the same IP is disabled * and the review from the IP exists * * will be shown: * ip_used_template (in any case) * * case 4: authorization is needed to add review * * will be shown: * forbidden_template (in any case) * * case 5: review can be added * * will be shown: * container_template (in any case) * -> error_template (if any error) * as Local_ErrorMessage() tag * -> success_template (if any success message) * as Local_SuccessMessage() tag * -> rating_template (if rating is available) * -> rating_rate_template (for every rate) * -> rating_header_template (for every rate value) * as Local_RatingHeader() tag * -> rating_rate_cell_template (for every rate value) * as Local_RatingCells() tag * as Local_RatingData() tag * as Local_Rating tag * -> review_template (if review is available) * as Local_Review() tag */ function output() { global $application; $product_id = 0; if ($this->NoView) { return ''; } loadClass('CCustomerInfo'); // getting the product_id from the params if any if (func_num_args() > 0) { $product_id = func_get_arg(0); } // if no product_id trying to obtain it from the stack of tags if ($product_id <= 0) { $param = modApiFunc('tag_param_stack', 'find_first_param_by_priority', array(TAG_PARAM_PROD_ID)); if ($param !== PARAM_NOT_FOUND && $param['key'] == TAG_PARAM_PROD_ID) { $product_id = $param['value']; } } // if still no product_id trying to get it from Catalog class if ($product_id <= 0) { $product_id = modApiFunc('Catalog', 'getCurrentProductId'); } // if the number of params is more than 1 assume the other params // to be the names of template to show. Only non-empty names are // used so to use a default template please set '' (empty string) // for it the order in which the templates should be specified is // set in the mapping array. Please do not change the order to // avoid problems with existing pages. However you can extend // the array for your purposes // Note: be sure the template exists: // in the ProductAddReviewForm section of // the product-add-review-form-block.ini // in the getTemplateFormat function // in the $this -> _templates array $mapping = array('container', 'empty', 'forbidden', 'ip_used', 'success', 'error', 'success_message', 'review', 'rating', 'rating_rate', 'rating_header', 'rating_rate_cell'); for ($i = 0; $i < count($mapping); $i++) { if (func_num_args() > 1 + $i && func_get_arg(1 + $i) != '') { $this->_templates[$mapping[$i]] = func_get_arg(1 + $i); } } // getting the product data $this->_product_data = modApiFunc('Customer_Reviews', 'getBaseProductInfo', array('product_id' => $product_id)); // processing Session data if available $this->_data = array(); // checking if session data is available if (modApiFunc('Session', 'is_set', 'PostingReviewData')) { // getting session data $posting_data = modApiFunc('Session', 'get', 'PostingReviewData'); // if session data for the product is available // here we presume there can be several add_review forms on a page if (isset($posting_data[$product_id])) { // keeping the data for output $this->_data = $posting_data[$product_id]; // removing session data for the product from the session unset($posting_data[$product_id]); // storing the new data in the session if (empty($posting_data)) { modApiFunc('Session', 'un_set', 'PostingReviewData'); } else { modApiFunc('Session', 'set', 'PostingReviewData', $posting_data); } } } // if author is not set in the session while the customer is logged in // then sets it to the firstname + lastname of the current customer if (modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) { if (!isset($this->_data)) { $this->_data = array(); } if (!isset($this->_data['author']) || !$this->_data['author']) { $c_info = new CCustomerInfo(modApiFunc('Customer_Account', 'getCurrentSignedCustomer')); $this->_data['author'] = $c_info->getPersonInfo('FirstName', 'customer') . ' ' . $c_info->getPersonInfo('LastName', 'customer'); } } // getting setting for checkout type $checkout_type = modApiFunc('Customer_Account', 'getSettings'); $checkout_type = $checkout_type['CHECKOUT_TYPE']; // getting the store settings // if customer reviews are enabled $reviews_enable = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_ENABLE'); // if only registered customers can post the reviews $reviews_writing = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_WRITING'); // if multiple reviews from the same IP is enabled $reviews_multiple = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_MULTIPLE'); // the number of reviews for the product posted from the IP $ip_reviews = modApiFunc('Customer_Reviews', 'getReviewsCountForProductByIP', $product_id, $_SERVER['REMOTE_ADDR']); // is AJAX should be used for adding reviews $isAJAXActive = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_AJAX_ACTIVE'); // setting up the template engine $template_block = $application->getBlockTemplate('ProductAddReviewForm'); $this->mTmplFiller->setTemplate($template_block); // registering tags $_tags = array('Local_FormAction' => $_SERVER['PHP_SELF'], 'Local_ProductID' => $product_id, 'Local_ProductName' => $this->_product_data['product_name'], 'Local_ReturnURL' => prepareHTMLDisplay(modApiFunc('Request', 'selfURL')), 'Local_Error' => $this->outputError(), 'Local_Success' => $this->outputSuccess(), 'Local_Author' => prepareHTMLDisplay(@$this->_data['author']), 'Local_Rating' => $this->outputRating(), 'Local_Review' => $this->outputReview(), 'Local_isAJAXActive' => $isAJAXActive == 'YES' ? '1' : ''); $this->_Template_Contents = $_tags; $application->registerAttributes($this->_Template_Contents); // checking the settings and the result // if reviews are disabled -> show empty_template // if writing reviews is disabled -> show empty_template // if reviews are disabled for the product -> show empty_template // if checkout type = quick while writing reviews is available // for signed in customers -> show empty_template if ($reviews_enable == 'NO' || $reviews_writing == 'NONE' || !in_array($this->_product_data['product_cr'], array(5, 6, 7)) || $checkout_type == CHECKOUT_TYPE_QUICK && $reviews_writing == 'REGONLY' && !modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) { return $this->mTmplFiller->fill($this->_templates['empty']); } // if multiple reviews from the same IP is disabled // while a new review has just been posted if ($reviews_multiple == 'NO' && $ip_reviews > 0 && @$this->_data['success'] != '') { return $this->outputSuccessMessage(); } // if multiple reviews from the same IP is disabled // while an attempt to post a review has just been done if ($reviews_multiple == 'NO' && $ip_reviews > 0 && @$this->_data['error'] != '') { return $this->outputErrorMessage(); } // if multiple reviews from the same IP is disabled // while a review for the IP exists -> show ip_used template if ($reviews_multiple == 'NO' && $ip_reviews > 0) { return $this->outputIPUsed(); } // if the customer is anonymous while writing reviews is available // for signed in customers -> show forbidden_template if ($reviews_writing == 'REGONLY' && !modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) { return $this->outputForbidden(); } return $this->mTmplFiller->fill($this->_templates['container']); }
function out_CustomersRows() { global $application; $html_code = ''; loadClass('CCustomerInfo'); foreach ($this->customers as $customer_info) { $template_contents = array('CustomerIcon' => $customer_info['customer_status'] == 'B' ? 'not-reg' : ($customer_info['customer_status'] == 'R' ? 'reg-dp' : ($customer_info['customer_status'] == 'A' ? 'reg' : 'reg-na')), 'CustomerID' => $customer_info['customer_id'], 'CustomerAccount' => CCustomerInfo::getDisplayAccountNameExt($customer_info['customer_account'], $customer_info['customer_status']), 'CustomerName' => prepareHTMLDisplay($customer_info['name']), 'CustomerOrdersCount' => $customer_info['orders_count'], 'CustomerTotalFullyPaid' => modApiFunc('Localization', 'currency_format', $customer_info['fully_paid_amount']), 'CustomerTotalAmount' => modApiFunc('Localization', 'currency_format', $customer_info['total_amount']), 'CustomerMembership' => $this->out_CustomerMembershipDropdown($customer_info['customer_id'], $customer_info['group_id']), 'CustomerStatusMsg' => getMsg('CA', 'CUSTOMER_STATUS_' . $customer_info['customer_status']), 'CustomerStatusLongMsg' => getMsg('CA', 'CUSTOMER_STATUS_LONG_' . $customer_info['customer_status'])); $this->_Template_Contents = $template_contents; $application->registerAttributes($this->_Template_Contents); $this->mTmplFiller =& $application->getInstance('TmplFiller'); $html_code .= $this->mTmplFiller->fill("customer_account/customers_list/", "customer-row.tpl.html", array()); } if (count($this->customers) < 5) { for ($i = count($this->customers); $i < 5; $i++) { $html_code .= $this->mTmplFiller->fill("customer_account/customers_list/", "empty-row.tpl.html", array()); } } return $html_code; }
function doWork($data) { global $application; if ($data === null) { return null; } $filtered = array(); $obj = new CCustomerInfo($data['customer_account']); foreach ($this->_settings['attrs'] as $tag) { $output = ''; preg_match('/^customer(.+)/i', $tag, $m1); if (preg_match('/^(billing|shipping|orders)(.+)/i', $m1[1], $m2)) { $group = $m2[1]; $attr = $m2[2]; } else { $attr = $m1[1]; if (in_array(_ml_strtolower($attr), array('id', 'status'))) { $group = 'base'; } else { $group = 'Customer'; } } if (_ml_strtolower($attr) == 'accountname') { $output = $obj->getDisplayAccountName(); $filtered[$tag] = $output; continue; } if (_ml_strtolower($group) != 'orders') { $attr_value = $obj->getPersonInfo($attr, $group); switch (_ml_strtolower($attr)) { case 'status': $MR =& $application->getInstance('MessageResources', 'customer-account-messages', 'AdminZone'); $output = $MR->getMessage('CUSTOMER_STATUS_' . $attr_value); break; case 'country': $output = modApiFunc('Location', 'getCountry', $attr_value); break; case 'state': if (modApiFunc('Location', 'getStateCode', $attr_value) != '') { $output = modApiFunc('Location', 'getState', $attr_value); } else { $output = $attr_value; } break; default: $output = $attr_value; break; } } else { $filter = array('type' => 'quick', 'order_status' => ORDER_STATUS_ALL); $obj->setOrdersHistoryFilter($filter); switch (_ml_strtolower($attr)) { case 'quantity': $output = $obj->getOrdersCount(); break; case 'totalamount': $output = number_format($obj->getOrdersAmount(), 2, '.', ''); break; case 'totalfullypaidamount': $output = number_format($obj->getOrdersFullyPaidAmount(), 2, '.', ''); break; } } $filtered[$tag] = $output; } unset($obj); return $filtered; }