/** * Generates the full address text * @param is|JeproshopAddressModelAddress $address is an instantiate object of Address class * @param array $patternRules * @param is|string $newLine is a string containing the newLine format * @param is|string $separator is a string containing the separator format * @param array $style * @return string * @internal param is $patternPules a defined rules array to avoid some pattern */ public static function generateAddress(JeproshopAddressModelAddress $address, $patternRules = array(), $newLine = "\r\n", $separator = ' ', $style = array()) { $addressFields = JeproshopAddressFormatModelAddressFormat::getOrderedAddressFields($address->country_id); $addressFormattedValues = JeproshopAddressFormatModelAddressFormat::getFormattedAddressFieldsValues($address, $addressFields); $addressText = ''; foreach ($addressFields as $line) { if ($patternsList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)) { $tmpText = ''; foreach ($patternsList as $pattern) { if (!array_key_exists('avoid', $patternRules) || array_key_exists('avoid', $patternRules) && !in_array($pattern, $patternRules['avoid'])) { $tmpText .= isset($addressFormattedValues[$pattern]) && !empty($addressFormattedValues[$pattern]) ? (isset($style[$pattern]) ? sprintf($style[$pattern], $addressFormattedValues[$pattern]) : $addressFormattedValues[$pattern]) . $separator : ''; } } $tmpText = trim($tmpText); $addressText .= !empty($tmpText) ? $tmpText . $newLine : ''; } } $addressText = preg_replace('/' . preg_quote($newLine, '/') . '$/i', '', $addressText); $addressText = rtrim($addressText, $separator); return $addressText; }
/** * Assign address var to smarty */ protected function assignAddressFormat() { $addressItems = array(); $addressFormat = JeproshopAddressFormatModelAddressFormat::getOrderedAddressFields(JeproshopSettingModelSetting::getValue('default_country'), false, true); $requireFormFieldsList = JeproshopAddressFormatModelAddressFormat::$requireFormFieldsList; foreach ($addressFormat as $addressLine) { foreach (explode(' ', $addressLine) as $addressItem) { $addressItems[] = trim($addressItem); } } // Add missing require fields for a new user subscription form foreach ($requireFormFieldsList as $fieldName) { if (!in_array($fieldName, $addressItems)) { $addressItems[] = trim($fieldName); } } foreach (array('invoice', 'delivery') as $addressType) { $this->assignRef($addressType . '_address_fields', $addressFormat); $this->assignRef($addressType . '_all_fields', $addressItems); } }
/** * Returns address format by country if not defined using default country * * @param Integer PS_COUNTRY.id * @return String field address format */ public static function getAddressCountryFormat($country_id = 0) { $country_id = (int) $country_id; $tmp_obj = new JeproshopAddressFormatModelAddressFormat(); $tmp_obj->country_id = $country_id; $out = $tmp_obj->getFormat($tmp_obj->country_id); $tmp_obj = null; return $out; }
/** * Return useful informations for cart * * @param null $lang_id * @param bool $refresh * @return array Cart details */ public function getSummaryDetails($lang_id = null, $refresh = false) { $context = JeproshopContext::getContext(); $app = JFactory::getApplication(); if (!$lang_id) { $lang_id = $context->language->lang_id; } $delivery = new JeproshopAddressModelAddress((int) $this->address_delivery_id); $invoice = new JeproshopAddressModelAddress((int) $this->address_invoice_id); // New layout system with personalization fields $formatted_addresses = array('delivery' => JeproshopAddressFormatModelAddressFormat::getFormattedLayoutData($delivery), 'invoice' => JeproshopAddressFormatModelAddressFormat::getFormattedLayoutData($invoice)); $base_total_tax_inc = $this->getOrderTotal(true); $base_total_tax_exc = $this->getOrderTotal(false); $total_tax = $base_total_tax_inc - $base_total_tax_exc; if ($total_tax < 0) { $total_tax = 0; } $currency = new JeproshopCurrencyModelCurrency($this->currency_id); $products = $this->getProducts($refresh); $gift_products = array(); $cart_rules = $this->getCartRules(); $total_shipping = $this->getTotalShippingCost(); $total_shipping_tax_exc = $this->getTotalShippingCost(null, false); $total_products_wt = $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_PRODUCTS); $total_products = $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_PRODUCTS); $total_discounts = $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_DISCOUNTS); $total_discounts_tax_exc = $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_DISCOUNTS); // The cart content is altered for display foreach ($cart_rules as &$cart_rule) { // If the cart rule is automatic (without any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0 if ($cart_rule->free_shipping && (empty($cart_rule->code) || preg_match('/^' . JeproshopCartRuleModelCartRule::JEPROSHOP_BO_ORDER_CODE_PREFIX . '[0-9]+/', $cart_rule->code))) { $cart_rule->value_real -= $total_shipping; $cart_rule->value_tax_exc -= $total_shipping_tax_exc; $cart_rule->value_real = JeproshopValidator::roundPrice($cart_rule->value_real, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $cart_rule->value_tax_exc = JeproshopValidator::roundPrice($cart_rule->value_tax_exc, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); if ($total_discounts > $cart_rule->value_real) { $total_discounts -= $total_shipping; } if ($total_discounts_tax_exc > $cart_rule->value_tax_exc) { $total_discounts_tax_exc -= $total_shipping_tax_exc; } // Update total shipping $total_shipping = 0; $total_shipping_tax_exc = 0; } if ($cart_rule->gift_product) { foreach ($products as $key => &$product) { if (empty($product->gift) && $product->product_id == $cart_rule->gift_product && $product->product_attribute_id == $cart_rule->gift_product_attribute) { // Update total products $total_products_wt = JeproshopValidator::roundPrice($total_products_wt - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $total_products = JeproshopValidator::roundPrice($total_products - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update total discounts $total_discounts = JeproshopValidator::roundPrice($total_discounts - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $total_discounts_tax_exc = JeproshopValidator::roundPrice($total_discounts_tax_exc - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update cart rule value $cart_rule->value_real = JeproshopValidator::roundPrice($cart_rule->value_real - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $cart_rule->value_tax_exc = JeproshopValidator::roundPrice($cart_rule->value_tax_exc - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update product quantity $product->total_wt = JeproshopValidator::roundPrice($product->total_wt - $product->price_wt, (int) $currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $product->total = JeproshopValidator::roundPrice($product->total - $product->price, (int) $currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $product->cart_quantity--; if (!$product->cart_quantity) { unset($products[$key]); } // Add a new product line $gift_product = $product; $gift_product->cart_quantity = 1; $gift_product->price = 0; $gift_product->price_wt = 0; $gift_product->total_wt = 0; $gift_product->total = 0; $gift_product->gift = true; $gift_products[] = $gift_product; break; // One gift product per cart rule } } } } foreach ($cart_rules as $key => &$cart_rule) { if ($cart_rule->value_real == 0) { unset($cart_rules[$key]); } } $summary = new JObject(); $summary->set('delivery', $delivery); $summary->set('delivery_state', JeproshopStateModelState::getNameById($delivery->state_id)); $summary->set('invoice', $invoice); $summary->set('invoice_state', JeproshopStateModelState::getNameById($invoice->state_id)); $summary->set('formattedAddresses', $formatted_addresses); $summary->set('products', array_values($products)); $summary->set('gift_products', $gift_products); $summary->set('discounts', array_values($cart_rules)); $summary->set('is_virtual_cart', (int) $this->isVirtualCart()); $summary->set('total_discounts', $total_discounts); $summary->set('total_discounts_tax_exc', $total_discounts_tax_exc); $summary->set('total_wrapping', $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_WRAPPING)); $summary->set('total_wrapping_tax_exc', $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_WRAPPING)); $summary->set('total_shipping', $total_shipping); $summary->set('total_shipping_tax_exc', $total_shipping_tax_exc); $summary->set('total_products_wt', $total_products_wt); $summary->set('total_products', $total_products); $summary->set('total_price', $base_total_tax_inc); $summary->set('total_tax', $total_tax); $summary->set('total_price_without_tax', $base_total_tax_exc); $summary->set('is_multi_address_delivery', $this->isMultiAddressDelivery() || (int) $app->input->get('multi-shipping') == 1); $summary->set('free_ship', $total_shipping ? 0 : 1); $summary->set('carrier', new JeproshopCarrierModelCarrier($this->carrier_id, $lang_id)); return $summary; }
public function initOrderDetails() { $this->context->controller->init(); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); //$this->initContent(); $app = JFactory::getApplication(); $order_id = $app->input->get('order_id'); if (!$order_id || !JeproshopTools::isUnsignedInt($order_id)) { $this->errors[] = Tools::displayError('Order ID required'); } else { $order = new JeproshopOrderModelOrder($order_id); if (JeproshopTools::isLoadedObject($order, 'order_id') && $order->customer_id == $this->context->customer->customer_id) { $order_status_id = (int) $order->getCurrentState(); $carrier = new JeproshopCarrierModelCarrier((int) $order->carrier_id, (int) $order->lang_id); $invoiceAddress = new JeproshopAddressModelAddress((int) $order->address_invoice_id); $deliveryAddress = new JeproshopAddressModelAddress((int) $order->address_delivery_id); $invoice_address_fields = JeproshopAddressFormatModelAddressFormat::getOrderedAddressFields($invoiceAddress->country_id); $delivery_address_fields = JeproshopAddressFormatModelAddressFormat::getOrderedAddressFields($deliveryAddress->country_id); $invoiceAddressFormatValues = JeproshopAddressFormatModelAddressFormat::getFormattedAddressFieldsValues($invoiceAddress, $invoice_address_fields); $deliveryAddressFormatValues = JeproshopAddressFormatModelAddressFormat::getFormattedAddressFieldsValues($deliveryAddress, $delivery_address_fields); if ($order->total_discounts > 0) { $oldTotal = (double) ($order->total_paid - $order->total_discounts); $this->assignRef('old_total', $oldTotal); } $products = $order->getProducts(); /* DEPRECATED: customizedDatas @since 1.5 */ $customizedDatas = JeproshopProductModelProduct::getAllCustomizedDatas((int) $order->cart_id); JeproshopProductModelProduct::addCustomizationPrice($products, $customizedDatas); JeproshopOrderReturnModelOrderReturn::addReturnedQuantity($products, $order->order_id); $customer = new JeproshopCustomerModelCustomer($order->customer_id); $this->assignRef('order', $order); $isReturnable = (int) $order->isReturnable(); $this->assignRef('return_allowed', $isReturnable); $this->assignRef('currency', new JeproshopCurrencyModelCurrency($order->currency_id)); $order_status_id = (int) $order_status_id; $this->assignRef('order_status_id', $order_status_id); $invoiceAllowed = (int) JeproshopSettingModelSetting::getValue('invoice_allowed'); $this->assignRef('invoice_allowed', $invoiceAllowed); $invoice = JeproshopOrderStatusModelOrderStatus::invoiceAvailable($order_status_id) && count($order->getInvoicesCollection()); $this->assignRef('invoice', $invoice); $this->assignRef('order_history', $order->getHistory($this->context->language->lang_id, false, true)); $this->assignRef('products', $products); $this->assignRef('discounts', $order->getCartRules()); $this->assignRef('carrier', $carrier); $this->assignRef('invoice_address', $invoiceAddress); $this->assignRef('invoice_status', JeproshopTools::isLoadedObject($invoiceAddress, 'address_id') && $invoiceAddress->state_id ? new JeproshopStatusModelStatus($invoiceAddress->state_id) : false); $this->assignRef('delivery_address', $deliveryAddress); $this->assignRef('invoice_address_fields', $invoice_address_fields); $this->assignRef('delivery_address_fields', $delivery_address_fields); $this->assignRef('invoice_address_format_values', $invoiceAddressFormatValues); $this->assignRef('delivery_address_format_values', $deliveryAddressFormatValues); $this->assignRef('delivery_status', JeproshopTools::isLoadedObject($deliveryAddress, 'address_id') && $deliveryAddress->state_id ? new JeproshopStatusModelStatus($deliveryAddress->state_id) : false); $this->assignRef('messages', JeproshopCustomerMessageModelCustomerMessage::getMessagesByOrderId((int) $order->order_id, false)); $files = JeproshopProductModelProduct::CUSTOMIZE_FILE; $this->assignRef('CUSTOMIZE_FILE', $files); $text_fields = JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD; $this->assignRef('CUSTOMIZE_TEXT_FIELD', $text_fields); //$this->assignRef('isRecyclable', JeproshopSettingModelSetting::getValue('PS_RECYCLABLE_PACK')); $this->assignRef('use_tax', JeproshopSettingModelSetting::getValue('use_tax')); $group_use_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($customer->default_group_id) == COM_JEPROSHOP_TAX_INCLUDED; $this->assignRef('group_use_tax', $group_use_tax); $this->assignRef('display_price', JeproshopSettingModelSetting::getValue('display_price')); /* DEPRECATED: customizedDatas @since 1.5 */ $this->assignRef('customizedDatas', $customizedDatas); $reordering_allowed = (int) JeproshopSettingModelSetting::getValue('enable_history_reordering'); $this->assignRef('reordering_allowed', $reordering_allowed); /* $this->context->smarty->assign(array( 'deliveryState' => (Validate::isLoadedObject($addressDelivery) && $addressDelivery->state_id) ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => CustomerMessage::getMessagesByOrderId((int)($order->id), false), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXT_FIELD' => Product::CUSTOMIZE_TEXT_FIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => (Group::getPriceDisplayMethod($customer->default_group_id) == PS_TAX_INC), /* DEPRECATED: customizedDatas @since 1.5 * / 'customizedDatas' => $customizedDatas, /* DEPRECATED: customizedDatas @since 1.5 * / )); */ if ($carrier->url && $order->shipping_number) { $this->assignRef('followup', str_replace('@', $order->shipping_number, $carrier->url)); } /* $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Hook::exec('displayOrderDetail', array('order' => $order))); Hook::exec('actionOrderDetail', array('carrier' => $carrier, 'order' => $order)); */ unset($carrier, $addressInvoice, $addressDelivery); } else { $this->errors[] = Tools::displayError('This order cannot be found.'); } unset($order); } //$this->setTemplate(_PS_THEME_DIR_.'order-detail.tpl'); }
protected function displayValidFields() { $objectList = JeproshopAddressFormatModelAddressFormat::getLiableClass('JeproshopAddressModelAddress'); }
/** * Assign template vars related to address format */ protected function assignAddressFormat() { $country_id = is_null($this->address) ? 0 : (int) $this->address->country_id; $ordered_adr_fields = JeproshopAddressFormatModelAddressFormat::getOrderedAddressFields($country_id, true, true); $this->assignRef('ordered_address_fields', $ordered_adr_fields); }