Пример #1
0
 public function renderView($tpl = null)
 {
     if ($this->getLayout() !== 'modal') {
     }
     if ($this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     $db = JFactory::getDBO();
     $this->setLayout('view');
     $this->loadObject();
     if (!JeproshopTools::isLoadedObject($this->customer, 'customer_id')) {
         return;
     }
     $this->context->customer = $this->customer;
     $customer_stats = $this->customer->getStats();
     $query = "SELECT SUM(total_paid_real) FROM " . $db->quoteName('#__jeproshop_orders');
     $query .= " WHERE customer_id = " . (int) $this->customer->customer_id . " AND valid = 1";
     $db->setQuery($query);
     $total_customer = $db->loadResult();
     if ($total_customer) {
         $query = "SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM " . $db->quoteName('#__jeproshop_orders');
         $query .= " WHERE valid = 1 AND customer_id != " . (int) $this->customer->customer_id . " GROUP BY ";
         $query .= "customer_id HAVING SUM(total_paid_real) > " . (int) $total_customer;
         $db->setQuery($query);
         $db->loadResult();
         $count_better_customers = (int) $db->loadResult('SELECT FOUND_ROWS()') + 1;
     } else {
         $count_better_customers = '-';
     }
     $orders = JeproshopOrderModelOrder::getCustomerOrders($this->customer->customer_id, true);
     $total_orders = count($orders);
     for ($i = 0; $i < $total_orders; $i++) {
         $orders[$i]->total_paid_real_not_formated = $orders[$i]->total_paid_real;
         $orders[$i]->total_paid_real = JeproshopTools::displayPrice($orders[$i]->total_paid_real, new JeproshopCurrencyModelCurrency((int) $orders[$i]->currency_id));
     }
     $messages = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages((int) $this->customer->customer_id);
     $total_messages = count($messages);
     for ($i = 0; $i < $total_messages; $i++) {
         $messages[$i]->message = substr(strip_tags(html_entity_decode($messages[$i]->message, ENT_NOQUOTES, 'UTF-8')), 0, 75);
         $messages[$i]->date_add = Tools::displayDate($messages[$i]->date_add, null, true);
     }
     $groups = $this->customer->getGroups();
     $total_groups = count($groups);
     for ($i = 0; $i < $total_groups; $i++) {
         $group = new JeproshopGroupModelGroup($groups[$i]);
         $groups[$i] = array();
         $groups[$i]['group_id'] = $group->group_id;
         $groups[$i]['name'] = $group->name[$this->context->controller->default_form_language];
     }
     $total_ok = 0;
     $orders_ok = array();
     $orders_ko = array();
     foreach ($orders as $order) {
         if (!isset($order->order_state)) {
             $order->order_state = JText::_('COM_JEPROSHOP_THERE_IS_NO_STATUS_DEFINED_FOR_THIS_ORDER_MESSAGE');
         }
         if ($order->valid) {
             $orders_ok[] = $order;
             $total_ok += $order->total_paid_real_not_formated;
         } else {
             $orders_ko[] = $order;
         }
     }
     $products = $this->customer->getBoughtProducts();
     $carts = JeproshopCartModelCart::getCustomerCarts($this->customer->customer_id);
     $total_carts = count($carts);
     for ($i = 0; $i < $total_carts; $i++) {
         $cart = new JeproshopCartModelCart((int) $carts[$i]->cart_id);
         $this->context->cart = $cart;
         $summary = $cart->getSummaryDetails();
         $currency = new JeproshopCurrencyModelCurrency((int) $carts[$i]->currency_id);
         $carrier = new JeproshopCarrierModelCarrier((int) $carts[$i]->carrier_id);
         $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']);
         $carts[$i]['date_add'] = JeproshopValidator::displayDate($carts[$i]->date_add, null, true);
         $carts[$i]['total_price'] = Tools::displayPrice($summary->total_price, $currency);
         $carts[$i]->name = $carrier->name;
     }
     $query = "SELECT DISTINCT cart_product.product_id, cart.cart_id, cart.shop_id, cart_product.shop_id ";
     $query .= " AS cart_product_shop_id FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product";
     $query .= " JOIN " . $db->quoteName('#__jeproshop_cart') . " AS cart ON (cart.cart_id = cart_product.cart_id) ";
     $query .= "JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product.product_id = product.";
     $query .= "product_id) WHERE cart.customer_id = " . (int) $this->customer->customer_id . " AND cart_product.product_id";
     $query .= " NOT IN ( SELECT product_id FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord JOIN ";
     $query .= $db->quoteName('#__jeproshop_order_detail') . " AS ord_detail ON (ord.order_id = ord_detail.order_id ) WHERE ";
     $query .= "ord.valid = 1 AND ord.customer_id = " . (int) $this->customer->customer_id . ")";
     $db->setQuery($query);
     $interested = $db->loadObjectList();
     $total_interested = count($interested);
     for ($i = 0; $i < $total_interested; $i++) {
         $product = new JeproshopProductModelProduct($interested[$i]->product_id, false, $this->context->controller->default_form_language, $interested[$i]->shop_id);
         if (!Validate::isLoadedObject($product, 'product_id')) {
             continue;
         }
         $interested[$i]->url = $this->context->controller->getProductLink($product->product_id, $product->link_rewrite, JeproshopCategoryModelCategory::getLinkRewrite($product->default_category_id, $this->context->controller->default_form_language), null, null, $interested[$i]->cp_shop_id);
         $interested[$i]->product_id = (int) $product->product_id;
         $interested[$i]->name = htmlentities($product->name);
     }
     $connections = $this->customer->getLastConnections();
     if (!is_array($connections)) {
         $connections = array();
     }
     $total_connections = count($connections);
     for ($i = 0; $i < $total_connections; $i++) {
         $connections[$i]->http_referer = $connections[$i]->http_referer ? preg_replace('/^www./', '', parse_url($connections[$i]->http_referer, PHP_URL_HOST)) : JText::_('COM_JEPROSHOP_DIRECT_LINK_LABEL');
     }
     $referrers = JeproshopReferrerModelReferrer::getReferrers($this->customer->customer_id);
     $total_referrers = count($referrers);
     for ($i = 0; $i < $total_referrers; $i++) {
         $referrers[$i]->date_add = JeproshopTools::displayDate($referrers[$i]->date_add, null, true);
     }
     $customerLanguage = new JeproshopLanguageModelLanguage($this->customer->lang_id);
     $shop = new JeproshopShopModelShop($this->customer->shop_id);
     //$this->assignRef('customer', $customer);
     /*'gender' => $gender,
     		/*	'gender_image' => $gender_image,
     		// General information of the customer */
     $registration = JeproshopTools::displayDate($this->customer->date_add, null, true);
     $this->assignRef('registration_date', $registration);
     $this->assignRef('customer_stats', $customer_stats);
     $last_visit = JeproshopTools::displayDate($customer_stats->last_visit, null, true);
     $this->assignRef('last_visit', $last_visit);
     $this->assignRef('count_better_customers', $count_better_customers);
     $shop_feature_active = JeproshopShopModelShop::isFeaturePublished();
     $this->assignRef('shop_is_feature_active', $shop_feature_active);
     $this->assignRef('shop_name', $shop->shop_name);
     $customerBirthday = JeproshopTools::displayDate($this->customer->birthday);
     $this->assignRef('customer_birthday', $customerBirthday);
     $last_update = JeproshopTools::displayDate($this->customer->date_upd, null, true);
     $this->assignRef('last_update', $last_update);
     $customerExists = JeproshopCustomerModelCustomer::customerExists($this->customer->email);
     $this->assignRef('customer_exists', $customerExists);
     $this->assignRef('lang_id', $this->customer->lang_id);
     $this->assignRef('customerLanguage', $customerLanguage);
     // Add a Private note
     $customerNote = JeproshopTools::htmlentitiesUTF8($this->customer->note);
     $this->assignRef('customer_note', $customerNote);
     // Messages
     $this->assignRef('messages', $messages);
     // Groups
     $this->assignRef('groups', $groups);
     // Orders
     $this->assignRef('orders', $orders);
     $this->assignRef('orders_ok', $orders_ok);
     $this->assignRef('orders_ko', $orders_ko);
     $total_ok = JeproshopTools::displayPrice($total_ok, $this->context->currency->currency_id);
     $this->assignRef('total_ok', $total_ok);
     // Products
     $this->assignRef('products', $products);
     // Addresses
     $addresses = $this->customer->getAddresses($this->context->controller->default_form_language);
     $this->assignRef('addresses', $addresses);
     // Discounts
     $discounts = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->controller->default_form_language, $this->customer->customer_id, false, false);
     $this->assignRef('discounts', $discounts);
     // Carts
     $this->assignRef('carts', $carts);
     // Interested
     $this->assignRef('interested_products', $interested);
     // Connections
     $this->assignRef('connections', $connections);
     // Referrers
     $this->assignRef('referrers', $referrers);
     if ($this->getLayout() != 'modal') {
         $this->addToolBar();
         $this->sideBar = JHtmlSidebar::render();
     }
     parent::display($tpl);
 }
Пример #2
0
 public static function getProductProperties($lang_id, $row, JeproshopContext $context = null)
 {
     if (!$row->product_id) {
         return false;
     }
     if ($context == null) {
         $context = JeproshopContext::getContext();
     }
     // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it:
     // consider adding it in order to avoid unnecessary queries
     $row->allow_out_of_stock_ordering = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock);
     if (JeproshopCombinationModelCombination::isFeaturePublished() && (!isset($row->product_attribute_id) || !$row->product_attribute_id) && (isset($row->cache_default_attribute) && ($default_product_attribute_id = $row->cache_default_attribute) !== null || ($default_product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($row->product_id, !$row->allow_out_of_stock_ordering)))) {
         $row->product_attribute_id = $default_product_attribute_id;
     }
     if (!JeproshopCombinationModelCombination::isFeaturePublished() || !isset($row->product_attribute_id)) {
         $row->product_attribute_id = 0;
     }
     // Tax
     $useTax = JeproshopTaxModelTax::taxExcludedOption();
     $cache_key = $row->product_id . '_' . $row->product_attribute_id . '_' . $lang_id . '_' . (int) $useTax;
     if (isset($row->product_pack_id)) {
         $cache_key .= '_pack_' . $row->product_pack_id;
     }
     if (isset(self::$_productPropertiesCache[$cache_key])) {
         return JeproshopTools::updateObjectData($row, self::$_productPropertiesCache[$cache_key]);
     }
     // Datas
     $row->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $row->default_category_id, (int) $lang_id);
     $row->link = $context->controller->getProductLink((int) $row->product_id, $row->link_rewrite, $row->category, $row->ean13);
     $row->attribute_price = 0;
     if (isset($row->product_attribute_id) && $row->product_attribute_id) {
         $row->attribute_price = (double) JeproshopProductModelProduct::getProductAttributePrice($row->product_attribute_id);
     }
     $row->price_tax_exc = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED ? 2 : 6);
     if (self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) {
         $row->price_tax_exc = JeproshopTools::roundPrice($row->price_tax_exc, 2);
         $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, false);
     } else {
         $row->price = JeproshopTools::roundPrice(JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2), 2);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6, null, false, false);
     }
     $specific_prices = null;
     $row->reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, (bool) $useTax, (int) $row->product_attribute_id, 6, null, true, true, 1, true, null, null, null, $specific_prices);
     $row->specific_prices = $specific_prices;
     $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, 0, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     $row->quantity_all_versions = $row->quantity;
     if ($row->product_attribute_id) {
         $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, $row->product_attribute_id, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     }
     $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $lang_id);
     $row->features = JeproshopProductModelProduct::getFrontStaticFeatures((int) $lang_id, $row->product_id);
     $row->attachments = array();
     if (!isset($row->cache_has_attachments) || $row->cache_has_attachments) {
         $row->attachments = JeproshopProductModelProduct::getStaticAttachments((int) $lang_id, $row->product_id);
     }
     $row->virtual = !isset($row->is_virtual) || $row->is_virtual ? 1 : 0;
     // Pack management
     $row->pack = !isset($row->cache_is_pack) ? JeproshopProductPack::isPack($row->product_id) : (int) $row->cache_is_pack;
     $row->packItems = $row->pack ? JeproshopProductPack::getItemTable($row->product_id, $lang_id) : array();
     $row->no_pack_price = $row->pack ? JeproshopProductPack::noPackPrice($row->product_id) : 0;
     if ($row->pack && !JeproshopProductPack::isInStock($row->product_id)) {
         $row->quantity = 0;
     }
     $row->customization_required = false;
     if (isset($row->customizable) && $row->customizable && JeproshopCustomization::isFeaturePublished()) {
         if (count(JeproshopProductModelProduct::getStaticRequiredCustomizableFields((int) $row->product_id))) {
             $row->customization_required = true;
         }
     }
     $row = JeproshopProductModelProduct::getTaxesInformations($row, $context);
     self::$_productPropertiesCache[$cache_key] = $row;
     return self::$_productPropertiesCache[$cache_key];
 }
Пример #3
0
 public function __construct($product_id = NULL, $full = FALSE, $lang_id = NULL, $shop_id = NULL, JeproshopContext $context = NULL)
 {
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->getShopFromContext = FALSE;
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($product_id) {
         $cache_id = 'jeproshop_product_model_' . $product_id . '_' . $lang_id . '_' . $shop_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product') . " AS product ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON (product.product_id = product_lang.product_id AND product_lang.lang_id = " . (int) $lang_id . ") ";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where = " AND product_lang.shop_id = " . $this->shop_id;
                 }
             }
             /** Get shop informations **/
             if (JeproshopShopModelShop::isTableAssociated('product')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_product_shop') . " AS product_shop ON (";
                 $query .= "product.product_id = product_shop.product_id AND product_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $query .= " WHERE product.product_id = " . (int) $product_id . $where;
             $db->setQuery($query);
             $product_data = $db->loadObject();
             if ($product_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_lang');
                     $query .= " WHERE product_id = " . (int) $product_id;
                     $db->setQuery($query);
                     $product_lang_data = $db->loadObjectList();
                     if ($product_lang_data) {
                         foreach ($product_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'product_id') {
                                     if (!isset($product_data->{$key}) || !is_array($product_data->{$key})) {
                                         $product_data->{$key} = array();
                                     }
                                     $product_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $product_data);
             }
         } else {
             $product_data = JeproshopCache::retrieve($cache_id);
         }
         if ($product_data) {
             $product_data->product_id = $product_id;
             foreach ($product_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     if ($full && $this->product_id) {
         $this->isFullyLoaded = $full;
         $this->manufacturer_name = JeproshopManufacturerModelManufacturer::getNameById((int) $this->manufacturer_id);
         $this->supplier_name = JeproshopSupplierModelSupplier::getNameById((int) $this->supplier_id);
         if ($this->getType() == self::VIRTUAL_PRODUCT) {
             $this->developer_name = JeproshopDeveloperModelDeveloper::getNameById((int) $this->developer_id);
         }
         $address = NULL;
         if (is_object($context->cart) && $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')} != null) {
             $address = $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')};
         }
         $this->tax_rate = $this->getTaxesRate(new JeproshopAddressModelAddress($address));
         $this->is_new = $this->isNew();
         $this->base_price = $this->price;
         $this->price = JeproshopProductModelProduct::getStaticPrice((int) $this->product_id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specific_price);
         $this->unit_price = $this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0;
         if ($this->product_id) {
             $this->tags = JeproshopTagModelTag::getProductTags((int) $this->product_id);
         }
         $this->loadStockData();
     }
     if ($this->default_category_id) {
         $this->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $this->default_category_id, (int) $lang_id);
     }
 }