Example #1
0
" >
                    <td>
                        <strong class="dark">
                            <?php 
                if (isset($message->elastname) && $message->elastname) {
                    echo $message->efirstname . ' ' . $message->elastname;
                } elseif ($message->clastname) {
                    echo $message->cfirstname . ' ' . $message->clastname;
                } else {
                    echo $this->shop_name;
                }
                ?>
                        </strong>
                        <br />
                        <?php 
                echo JeproshopValidator::dateFormat($message->date_add, true);
                ?>
                    </td>
                    <td><?php 
                echo nl2br($message->message);
                ?>
</td>
                </tr>
            <?php 
            }
            ?>
            </tbody>
        </table>
    </div>
<?php 
        }
Example #2
0
 /**
  * Return manufacturers
  *
  * @param boolean $get_nb_products [optional] return products numbers for each
  * @param int $lang_id
  * @param bool $published
  * @param int $p
  * @param int $n
  * @param bool $all_group
  * @return array Manufacturers
  */
 public static function getManufacturers($get_nb_products = false, $lang_id = 0, $published = true, $p = false, $n = false, $all_group = false, $group_by = false)
 {
     if (!$lang_id) {
         $lang_id = (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     if (!JeproshopGroupModelGroup::isFeaturePublished()) {
         $all_group = true;
     }
     $db = JFactory::getDBO();
     $query = "SELECT manufacturer.*, manufacturer_lang." . $db->quoteName('description') . ", manufacturer_lang.";
     $query .= $db->quoteName('short_description') . " FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS ";
     $query .= "manufacturer " . JeproshopShopModelShop::addSqlAssociation('manufacturer') . " INNER JOIN ";
     $query .= $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang ON (manufacturer.";
     $query .= $db->quoteName('manufacturer_id') . " = manufacturer_lang." . $db->quoteName('manufacturer_id');
     $query .= " AND manufacturer_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
     $query .= $published ? " WHERE manufacturer." . $db->quoteName('published') . " = 1" : "";
     $query .= ($group_by ? " GROUP BY manufacturer." . $db->quoteName('manufacturer_id') : "") . " ORDER BY ";
     $query .= "manufacturer." . $db->quoteName('name') . " ASC " . ($p ? " LIMIT " . ((int) $p - 1) * (int) $n . ", " . (int) $n : "");
     $db->setQuery($query);
     $manufacturers = $db->loadObjectList();
     if ($manufacturers === false) {
         return false;
     }
     /*
     if ($get_nb_products)
     {
     	$sql_groups = '';
     	if (!$all_group)
     	{
     		$groups = FrontController::getCurrentCustomerGroups();
     		$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
     	}
     	
     	foreach ($manufacturers as $key => $manufacturer)
     	{
     		$manufacturers[$key]['nb_products'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
     		SELECT COUNT(DISTINCT p.`id_product`)
     		FROM `'._DB_PREFIX_.'product` p
     		'.Shop::addSqlAssociation('product', 'p').'
     		WHERE p.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].'
     		AND product_shop.`visibility` NOT IN ("none")
     		'.($active ? ' AND product_shop.`active` = 1 ' : '').'
     		'.($all_group ? '' : ' AND p.`id_product` IN (
     			SELECT cp.`id_product`
     			FROM `'._DB_PREFIX_.'category_group` cg
     			LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
     			WHERE cg.`id_group` '.$sql_groups.'
     		)'));
     	}
     }	
     */
     $total_manufacturers = count($manufacturers);
     $rewrite_settings = (int) JeproshopSettingModelSetting::getValue('rewrite_settings');
     for ($i = 0; $i < $total_manufacturers; $i++) {
         $manufacturers[$i]->link_rewrite = $rewrite_settings ? JeproshopValidator::link_rewrite($manufacturers[$i]->name) : 0;
     }
     return $manufacturers;
 }
Example #3
0
 public function getDeliveryOptionList(JeproshopCountryModelCountry $default_country = null, $flush = false)
 {
     static $cache = null;
     if ($cache !== null && !$flush) {
         return $cache;
     }
     $delivery_option_list = array();
     $carriers_price = array();
     $carrier_collection = array();
     $package_list = $this->getPackageList();
     // Foreach addresses
     foreach ($package_list as $address_id => $packages) {
         // Initialize vars
         $delivery_option_list[$address_id] = array();
         $carriers_price[$address_id] = array();
         $common_carriers = null;
         $best_price_carriers = array();
         $best_grade_carriers = array();
         $carriers_instance = array();
         // Get country
         if ($address_id) {
             $address = new JeproshopAddressModelAddress($address_id);
             $country = new JeproshopCountryModelCountry($address->country_id);
         } else {
             $country = $default_country;
         }
         // Foreach packages, get the carriers with best price, best position and best grade
         foreach ($packages as $package_id => $package) {
             // No carriers available
             if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0) {
                 $cache = array();
                 return $cache;
             }
             $carriers_price[$address_id][$package_id] = array();
             // Get all common carriers for each packages to the same address
             if (is_null($common_carriers)) {
                 $common_carriers = $package['carrier_list'];
             } else {
                 $common_carriers = array_intersect($common_carriers, $package['carrier_list']);
             }
             $best_price = null;
             $best_price_carrier = null;
             $best_grade = null;
             $best_grade_carrier = null;
             // Foreach carriers of the package, calculate his price, check if it the best price, position and grade
             foreach ($package['carrier_list'] as $carrier_id) {
                 if (!isset($carriers_instance[$carrier_id])) {
                     $carriers_instance[$carrier_id] = new JeproshopCarrierModelCarrier($carrier_id);
                 }
                 $price_with_tax = $this->getPackageShippingCost($carrier_id, true, $country, $package['product_list']);
                 $price_without_tax = $this->getPackageShippingCost($carrier_id, false, $country, $package['product_list']);
                 if (is_null($best_price) || $price_with_tax < $best_price) {
                     $best_price = $price_with_tax;
                     $best_price_carrier = $carrier_id;
                 }
                 $carriers_price[$address_id][$package_id][$carrier_id] = array('without_tax' => $price_without_tax, 'with_tax' => $price_with_tax);
                 $grade = $carriers_instance[$carrier_id]->grade;
                 if (is_null($best_grade) || $grade > $best_grade) {
                     $best_grade = $grade;
                     $best_grade_carrier = $carrier_id;
                 }
             }
             $best_price_carriers[$package_id] = $best_price_carrier;
             $best_grade_carriers[$package_id] = $best_grade_carrier;
         }
         // Reset $best_price_carrier, it's now an array
         $best_price_carrier = array();
         $key = '';
         // Get the delivery option with the lower price
         foreach ($best_price_carriers as $package_id => $carrier_id) {
             $key .= $carrier_id . ',';
             if (!isset($best_price_carrier[$carrier_id])) {
                 $best_price_carrier[$carrier_id] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array());
             }
             $best_price_carrier[$carrier_id]['price_with_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax'];
             $best_price_carrier[$carrier_id]['price_without_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax'];
             $best_price_carrier[$carrier_id]['package_list'][] = $package_id;
             $best_price_carrier[$carrier_id]['product_list'] = array_merge($best_price_carrier[$carrier_id]['product_list'], $packages[$package_id]['product_list']);
             $best_price_carrier[$carrier_id]['instance'] = $carriers_instance[$carrier_id];
         }
         // Add the delivery option with best price as best price
         $delivery_option_list[$address_id][$key] = array('carrier_list' => $best_price_carrier, 'is_best_price' => true, 'is_best_grade' => false, 'unique_carrier' => count($best_price_carrier) <= 1);
         // Reset $best_grade_carrier, it's now an array
         $best_grade_carrier = array();
         $key = '';
         // Get the delivery option with the best grade
         foreach ($best_grade_carriers as $package_id => $carrier_id) {
             $key .= $carrier_id . ',';
             if (!isset($best_grade_carrier[$carrier_id])) {
                 $best_grade_carrier[$carrier_id] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array());
             }
             $best_grade_carrier[$carrier_id]['price_with_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax'];
             $best_grade_carrier[$carrier_id]['price_without_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax'];
             $best_grade_carrier[$carrier_id]['package_list'][] = $package_id;
             $best_grade_carrier[$carrier_id]['product_list'] = array_merge($best_grade_carrier[$carrier_id]['product_list'], $packages[$package_id]['product_list']);
             $best_grade_carrier[$carrier_id]['instance'] = $carriers_instance[$carrier_id];
         }
         // Add the delivery option with best grade as best grade
         if (!isset($delivery_option_list[$address_id][$key])) {
             $delivery_option_list[$address_id][$key] = array('carrier_list' => $best_grade_carrier, 'is_best_price' => false, 'unique_carrier' => count($best_grade_carrier) <= 1);
         }
         $delivery_option_list[$address_id][$key]['is_best_grade'] = true;
         // Get all delivery options with a unique carrier
         foreach ($common_carriers as $carrier_id) {
             $key = '';
             $package_list = array();
             $product_list = array();
             $price_with_tax = 0;
             $price_without_tax = 0;
             foreach ($packages as $package_id => $package) {
                 $key .= $carrier_id . ',';
                 $price_with_tax += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax'];
                 $price_without_tax += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax'];
                 $package_list[] = $package_id;
                 $product_list = array_merge($product_list, $package['product_list']);
             }
             if (!isset($delivery_option_list[$address_id][$key])) {
                 $delivery_option_list[$address_id][$key] = array('is_best_price' => false, 'is_best_grade' => false, 'unique_carrier' => true, 'carrier_list' => array($carrier_id => array('price_with_tax' => $price_with_tax, 'price_without_tax' => $price_without_tax, 'instance' => $carriers_instance[$carrier_id], 'package_list' => $package_list, 'product_list' => $product_list)));
             } else {
                 $delivery_option_list[$address_id][$key]['unique_carrier'] = count($delivery_option_list[$address_id][$key]['carrier_list']) <= 1;
             }
         }
     }
     $cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules(JeproshopContext::getContext()->cookie->lang_id, JeproshopContext::getContext()->cookie->customer_id, true, true, false, $this);
     $free_carriers_rules = array();
     foreach ($cart_rules as $cart_rule) {
         if ($cart_rule->free_shipping && $cart_rule->carrier_restriction) {
             $cartRule = new JeproshopCartRuleModelCartRule((int) $cart_rule->cart_rule_id);
             if (JeproshopValidator::isLoadedObject($cartRule, 'cart_rule_id')) {
                 $carriers = $cart_rule->getAssociatedRestrictions('carrier', true, false);
                 if (is_array($carriers) && count($carriers) && isset($carriers['selected'])) {
                     foreach ($carriers['selected'] as $carrier) {
                         if (isset($carrier->carrier_id) && $carrier->carrier_id) {
                             $free_carriers_rules[] = (int) $carrier->carrier_id;
                         }
                     }
                 }
             }
         }
     }
     // For each delivery options :
     //    - Set the carrier list
     //    - Calculate the price
     //    - Calculate the average position
     foreach ($delivery_option_list as $address_id => $delivery_option) {
         foreach ($delivery_option as $key => $value) {
             $total_price_with_tax = 0;
             $total_price_without_tax = 0;
             $position = 0;
             foreach ($value['carrier_list'] as $carrier_id => $data) {
                 $total_price_with_tax += $data['price_with_tax'];
                 $total_price_without_tax += $data['price_without_tax'];
                 $total_price_without_tax_with_rules = in_array($carrier_id, $free_carriers_rules) ? 0 : $total_price_without_tax;
                 if (!isset($carrier_collection[$carrier_id])) {
                     $carrier_collection[$carrier_id] = new Carrier($carrier_id);
                 }
                 $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['instance'] = $carrier_collection[$carrier_id];
                 if (file_exists(_PS_SHIP_IMG_DIR_ . $carrier_id . '.jpg')) {
                     $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['logo'] = _THEME_SHIP_DIR_ . $carrier_id . '.jpg';
                 } else {
                     $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['logo'] = false;
                 }
                 $position += $carrier_collection[$carrier_id]->position;
             }
             $delivery_option_list[$address_id][$key]['total_price_with_tax'] = $total_price_with_tax;
             $delivery_option_list[$address_id][$key]['total_price_without_tax'] = $total_price_without_tax;
             $delivery_option_list[$address_id][$key]['is_free'] = !$total_price_without_tax_with_rules ? true : false;
             $delivery_option_list[$address_id][$key]['position'] = $position / count($value['carrier_list']);
         }
     }
     // Sort delivery option list
     foreach ($delivery_option_list as &$array) {
         uasort($array, array('Cart', 'sortDeliveryOptionList'));
     }
     $cache = $delivery_option_list;
     return $delivery_option_list;
 }
Example #4
0
 private function init()
 {
     $app = JFactory::getApplication();
     $category_id = $app->input->get('category_id');
     if (!$category_id || !JeproshopValidator::isUnsignedInt($category_id)) {
     }
     $this->category = new JeproshopCategoryModelCategory($category_id, $this->context->language->lang_id);
     $this->context->controller->init();
     if (!$this->category->published) {
         header('HTTP/1.1 4O4 Not Found');
         header('Status: 404 Not Found');
     }
     //check if category can be accessible by current customer and return 403 if not
     if (!$this->category->checkAccess($this->context->customer->customer_id)) {
         header('HTTP/1.1 403 Forbidden');
         header('Status: 403 Forbidden');
         $this->errors[] = JText::_('You do not have access to this category.');
         $this->customer_access = false;
     }
     $this->context->controller->init();
 }
Example #5
0
 /**
  * Marked as deprecated but should not throw any "deprecated" message
  * This function is used in order to keep front office backward compatibility 14 -> 1.5
  * (Order History)
  *
  * @deprecated
  */
 public function setProductPrices(&$row)
 {
     $tax_calculator = JeproshopOrderDetailModelOrderDetail::getStaticTaxCalculator((int) $row->order_detail_id);
     $row->tax_calculator = $tax_calculator;
     $row->tax_rate = $tax_calculator->getTotalRate();
     $row->product_price = JeproshopValidator::roundPrice($row->unit_price_tax_excl, 2);
     $row->product_price_with_tax = JeproshopValidator::roundPrice($row->unit_price_tax_incl, 2);
     $group_reduction = 1;
     if ($row->group_reduction > 0) {
         $group_reduction = 1 - $row->group_reduction / 100;
     }
     $row->product_price_with_tax_but_ecotax = $row->product_price_with_tax - $row->ecotax;
     $row->total_with_tax = $row->total_price_tax_incl;
     $row->total_price = $row->total_price_tax_excl;
 }
Example #6
0
        ?>
<th><?php 
        echo ucfirst(JText::_('COM_JEPROSHOP_SHOP_LABEL'));
        ?>
</th> <?php 
    }
    ?>
				</tr>
			</thead>
			<tbody>
				<?php 
    foreach ($this->referrers as $referrer) {
        ?>
				<tr>
					<td><?php 
        echo JeproshopValidator::dateFormat($this->order->date_add, false);
        ?>
</td>
					<td><?php 
        echo $referrer->name;
        ?>
</td>
					<?php 
        if ($this->shop_is_feature_active) {
            ?>
<td><?php 
            echo $referrer->shop_name;
            ?>
</td><?php 
        }
        ?>
Example #7
0
 /**
  * Check customer informations and return customer validity
  *
  * @since 1.5.0
  * @param boolean $with_guest
  * @return boolean customer validity
  */
 public function isLogged($with_guest = false)
 {
     if (!$with_guest && $this->is_guest == 1) {
         return false;
     }
     /* Customer is valid only if it can be load and if object password is the same as database one */
     if ($this->logged == 1 && $this->customer_id && JeproshopValidator::isUnsignedInt($this->customer_id) && JeproshopCustomerModelCustomer::checkPassword($this->customer_id, $this->passwd)) {
         return true;
     }
     return false;
 }
Example #8
0
checked="checked"<?php 
    }
    ?>
 />
                        <label for="gift">
                            <?php 
    echo JText::_('COM_JEPROSHOP_I_WOULD_LIKE_MY_ORDER_TO_BE_GIFT_WRAPPED_LABEL');
    if ($this->gift_wrapping_price > 0) {
        echo '&nbsp;<i>(' . JText::_('COM_JEPROSHOP_ADDITIONAL_COST_OF_LABEL');
        ?>
                            <span class="price" id="jform_gift_price" >
                                <?php 
        if ($this->display_price == 1) {
            echo JeproshopValidator::convertPrice($total_wrapping_tax_exc_cost);
        } else {
            echo JeproshopValidator::convertPrice($total_wrapping_cost);
        }
        ?>
				            </span>
                                <?php 
        if ($this->use_taxes && $this->display_tax_label) {
            if ($this->display_price == 1) {
                echo JText::_('COM_JEPROSHOP_TAX_EXCLUDED_LABEL') . ')';
            } else {
                echo JText::_('COM_JEPROSHOP_TAX_INCLUDED_LABEL') . ')';
            }
        }
        echo ')</i> ';
    }
    ?>
                        </label>
Example #9
0
 public static function autoRemoveFromCart($context = null)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     if (!JeproshopCartRuleModelCartRule::isFeaturePublished() || !JeproshopValidator::isLoadedObject($context->cart, 'cart_id')) {
         return array();
     }
     static $errors = array();
     foreach ($context->cart->getCartRules() as $cart_rule) {
         if ($error = $cart_rule['obj']->checkValidity($context, true)) {
             $context->cart->removeCartRule($cart_rule['obj']->cart_rule_id);
             $context->cart->update();
             $errors[] = $error;
         }
     }
     return $errors;
 }
Example #10
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);
 }
Example #11
0
    /**
     * Return suppliers
     *
     * @param bool $get_nb_products
     * @param int $lang_id
     * @param bool $published
     * @param bool $p
     * @param bool $n
     * @param bool $all_groups
     * @return array Suppliers
     */
    public static function getSuppliers($get_nb_products = false, $lang_id = 0, $published = true, $p = false, $n = false, $all_groups = false)
    {
        if (!$lang_id) {
            $lang_id = JeproshopSettingModelSetting::getValue('default_lang');
        }
        if (!JeproshopGroupModelGroup::isFeaturePublished()) {
            $all_groups = true;
        }
        $db = JFactory::getDBO();
        $query = "SELECT supplier.*, supplier_lang." . $db->quoteName('description') . " FROM " . $db->quoteName('#__jeproshop_supplier');
        $query .= " AS supplier LEFT JOIN " . $db->quoteName('#__jeproshop_supplier_lang') . " AS supplier_lang ON(supplier.";
        $query .= $db->quoteName('supplier_id') . " = supplier_lang." . $db->quoteName('supplier_id') . " AND supplier_lang.";
        $query .= $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlAssociation('supplier') . ")";
        $query .= ($published ? " WHERE supplier." . $db->quoteName('published') . " = 1" : "") . " ORDER BY supplier.";
        $query .= $db->quoteName('name') . " ASC " . ($p && $n ? " LIMIT " . $n . ", " . ($p - 1) * $n : "");
        //. " GROUP BY supplier" . $db->quoteName('supplier_id');
        $db->setQuery($query);
        $suppliers = $db->loadObjectList();
        if ($suppliers === false) {
            return false;
        }
        if ($get_nb_products) {
            $sql_groups = '';
            if (!$all_groups) {
                $groups = FrontController::getCurrentCustomerGroups();
                $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
            }
            foreach ($suppliers as $key => $supplier) {
                $sql = '
					SELECT DISTINCT(ps.`id_product`)
					FROM `' . _DB_PREFIX_ . 'product_supplier` ps
					JOIN `' . _DB_PREFIX_ . 'product` p ON (ps.`id_product`= p.`id_product`)
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE ps.`id_supplier` = ' . (int) $supplier['id_supplier'] . '
					AND ps.id_product_attribute = 0' . ($active ? ' AND product_shop.`active` = 1' : '') . ' AND product_shop.`visibility` NOT IN ("none")' . ($all_groups ? '' : '
					AND ps.`id_product` IN (
						SELECT cp.`id_product`
						FROM `' . _DB_PREFIX_ . 'category_group` cg
						LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE cg.`id_group` ' . $sql_groups . '
					)');
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
                $suppliers[$key]['nb_products'] = count($result);
            }
        }
        $nb_suppliers = count($suppliers);
        $rewrite_settings = (int) JeproshopSettingModelSetting::getValue('rewrite_settings');
        for ($i = 0; $i < $nb_suppliers; $i++) {
            $suppliers[$i]->link_rewrite = $rewrite_settings ? JeproshopValidator::link_rewrite($suppliers[$i]->name) : 0;
        }
        return $suppliers;
    }
Example #12
0
 public static function applyRuleToProduct($rule_id, $product_id, $product_attribute_id = null)
 {
     $rule = new JeproshopSpecificPriceRuleModelSpecificPriceRule((int) $rule_id);
     if (!JeproshopValidator::isLoadedObject($rule, 'specific-price_rule_id') || !$product_id) {
         return false;
     }
     $specific_price = new JeproshopSpecificPriceModelSpecificPrice();
     $specific_price->specific_price_rule_id = (int) $rule->specific_price_rule_id;
     $specific_price->product_id = (int) $product_id;
     $specific_price->product_attribute_id = (int) $product_attribute_id;
     $specific_price->customer_id = 0;
     $specific_price->shop_id = (int) $rule->shop_id;
     $specific_price->country_id = (int) $rule->country_id;
     $specific_price->currency_id = (int) $rule->currency_id;
     $specific_price->group_id = (int) $rule->group_id;
     $specific_price->from_quantity = (int) $rule->from_quantity;
     $specific_price->price = (double) $rule->price;
     $specific_price->reduction_type = $rule->reduction_type;
     $specific_price->reduction = $rule->reduction_type == 'percentage' ? $rule->reduction / 100 : (double) $rule->reduction;
     $specific_price->from = $rule->from;
     $specific_price->to = $rule->to;
     return $specific_price->add();
 }
Example #13
0
 /**
  * Check delivery prices for a given order
  *
  * @param id_carrier
  * @param float $orderTotal Order total to pay
  * @param integer $zone_id Zone id (for customer delivery address)
  * @param integer $currency_id
  * @return float Delivery price
  */
 public static function checkDeliveryPriceByPrice($carrier_id, $orderTotal, $zone_id, $currency_id = null)
 {
     $cache_key = $carrier_id . '_' . $orderTotal . '_' . $zone_id . '_' . $currency_id;
     if (!isset(self::$price_by_price2[$cache_key])) {
         if (!empty($currency_id)) {
             $orderTotal = JeproshopValidator::convertPrice($orderTotal, $currency_id, false);
         }
         $db = JFactory::getDBO();
         $query = "SELECT d." . $db->quoteName('price') . " FROM " . $db->quoteName('#__jeproshop_delivery') . " AS delivery LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_range_price') . " AS price_range ON delivery." . $db->quoteName('range_price_id') . " = range_price.";
         $query .= $db->quoteName('range_price_id') . " WHERE delivery." . $db->quoteName('zone_id') . " = " . (int) $zone_id . " AND " . (double) $orderTotal;
         $query .= " >= price_range." . $db->quoteName('delimiter1') . " AND " . (double) $orderTotal . " < price_range." . $db->quoteName('delimiter2');
         $query .= " AND delivery." . $db->quoteName('carrier_id') . " = " . (int) $carrier_id . JeproshopCarrierModelCarrier::sqlDeliveryRangeShop('range_price');
         $query .= " ORDER BY price_range." . $db->quoteName('delimiter1') . " ASC";
         $db->setQuery($query);
         $result = $db->loadObject();
         self::$price_by_price2[$cache_key] = isset($result->price);
     }
     return self::$price_by_price2[$cache_key];
 }
Example #14
0
                    echo JeproshopValidator::convertPrice($product->price);
                } else {
                    echo JeproshopValidator::convertPrice($product->price_tax_exc);
                }
                ?>
						</span>
                        <meta itemprop="priceCurrency" content="<?php 
                echo $this->currency->iso_code;
                ?>
" />
                        <?php 
                if (isset($product->specific_prices) && $product->specific_prices && isset($product->specific_prices->reduction) && $product->specific_prices->reduction > 0) {
                    //{hook h="displayProductPriceBlock" product=$product type="old_price"}
                    ?>
                        <span class="old-price product-price"><?php 
                    echo JeproshopValidator::displayWtPrice($product->price_without_reduction);
                    ?>
</span>
                        <?php 
                    //{hook h="displayProductPriceBlock" id_product=$product.id_product type="old_price"}
                    ?>
                        <?php 
                    if ($product->specific_prices->reduction_type == 'percentage') {
                        ?>
                        <span class="price-percent-reduction">-<?php 
                        echo $product->specific_prices->reduction * 100;
                        ?>
%</span>
                        <?php 
                    }
                }
Example #15
0
 public static function indexation($full = false, $product_id = false)
 {
     $db = JFactory::getDBO();
     if ($product_id) {
         $full = false;
     }
     if ($full) {
         $db->execute('TRUNCATE ' . $db->quoteName('#__jeproshop_search_index'));
         $db->execute('TRUNCATE ' . $db->quoteName('#__jeproshop_search_word'));
         self::updateMultishopTable('Product', array('indexed' => 0));
     } else {
         // Do it even if you already know the product id in order to be sure that it exists and it needs to be indexed
         $query = "SELECT product.product_id FROM " . $db->quoteName('#__jeproshop_product') . " AS product ";
         $query .= JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_shop.visibility IN (\"both\", \"search\") ";
         $query .= " AND product_shop." . $db->quoteName('published') . " = 1 AND ";
         $query .= $product_id ? "product.product_id = " . (int) $product_id : "product_shop.indexed = 0";
         $db->setQuery($query);
         $products = $db->loadObjectList();
         $ids = array();
         if ($products) {
             foreach ($products as $product) {
                 $ids[] = (int) $product->product_id;
             }
         }
         if (count($ids)) {
             $query = "DELETE FROM " . $db->quoteName('#__jeproshop_search_index') . " WHERE product_id IN (" . implode(',', $ids) . ")";
             $db->setQuery($query);
             $db->query();
             $data = " SET product." . $db->quoteName('indexed') . " = 0";
             $where = ' WHERE product.product_id IN (' . implode(',', $ids) . ')';
             JeproshopProductModelProduct::updateMultishopTable($data, $where, '', true);
         }
     }
     // Every fields are weighted according to the configuration in the backend
     $weight_array = array('product_name' => JeproshopSettingModelSetting::getValue('search_weight_product_name'), 'reference' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'product_attribute_reference' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'ean13' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'upc' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'short_description' => JeproshopSettingModelSetting::getValue('search_weight_short_description'), 'description' => JeproshopSettingModelSetting::getValue('search_weight_description'), 'category_name' => JeproshopSettingModelSetting::getValue('search_weight_category_name'), 'manufacture_name' => JeproshopSettingModelSetting::getValue('search_weight_manufacturer_name'), 'tag' => JeproshopSettingModelSetting::getValue('search_weight_tag'), 'attributes' => JeproshopSettingModelSetting::getValue('search_weight_attribute'), 'features' => JeproshopSettingModelSetting::getValue('search_weight_feature'));
     // Those are kind of global variables required to save the processed data in the database every X occurrences, in order to avoid overloading MySQL
     $count_words = 0;
     $query_array3 = array();
     // Every indexed words are cached into a PHP array
     $query = "SELECT word_id, word, lang_id, shop_id FROM " . $db->quoteName('#__jeproshop_search_word');
     $db->setQuery($query);
     $word_ids = $db->loadObjectList();
     $word_ids_by_word = array();
     while ($word_id = $db->nextRow($word_ids)) {
         if (!isset($word_ids_by_word[$word_id->shop_id][$word_id->lang_id])) {
             $word_ids_by_word[$word_id['id_shop']][$word_id['id_lang']] = array();
         }
         $word_ids_by_word[$word_id->shop_id][$word_id->lang_id]['_' . $word_id->word] = (int) $word_id->word_id;
     }
     // Retrieve the number of languages
     $total_languages = count(JeproshopLanguageModelLanguage::getLanguages(false));
     // Products are processed 50 by 50 in order to avoid overloading MySQL
     while (($products = JeproshopSearch::getProductsToIndex($total_languages, $product_id, 50, $weight_array)) && count($products) > 0) {
         $products_array = array();
         // Now each non-indexed product is processed one by one, langage by langage
         foreach ($products as $product) {
             if ((int) $weight_array['tag']) {
                 $product->tags = JeproshopSearch::getTags($db, (int) $product->product_id, (int) $product->lang_id);
             }
             if ((int) $weight_array['attributes']) {
                 $product->attributes = JeproshopSearch::getAttributes($db, (int) $product->product_id, (int) $product->lang_id);
             }
             if ((int) $weight_array['features']) {
                 $product->features = JeproshopSearch::getFeatures($db, (int) $product->product_id, (int) $product->lang_id);
             }
             // Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
             $product_array = array();
             foreach ($product as $key => $value) {
                 if (strncmp($key, 'id_', 3) && isset($weight_array[$key])) {
                     $words = explode(' ', JeproshopSearch::sanitize($value, (int) $product->lang_id, true, JeproshopContext::getContext()->language->iso_code));
                     foreach ($words as $word) {
                         if (!empty($word)) {
                             $word = substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
                             // Remove accents
                             $word = JeproshopValidator::replaceAccentedChars($word);
                             if (!isset($product_array[$word])) {
                                 $product_array[$word] = 0;
                             }
                             $product_array[$word] += $weight_array[$key];
                         }
                     }
                 }
             }
             // If we find words that need to be indexed, they're added to the word table in the database
             if (count($product_array)) {
                 $query_array = $query_array2 = array();
                 foreach ($product_array as $word => $weight) {
                     if ($weight && !isset($word_ids_by_word['_' . $word])) {
                         $query_array[$word] = '(' . (int) $product->lang_id . ', ' . (int) $product->shop_id . ', ' . $db->quote($word) . ')';
                         $query_array2[] = $db->quote($word);
                         $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word] = 0;
                     }
                 }
                 if ($query_array2) {
                     $query = "SELECT DISTINCT word FROM " . $db->quoteName('#__jeproshop_search_word') . " WHERE word IN (";
                     $query .= implode(',', $query_array2) . ") AND lang_id = " . (int) $product->lang_id . " AND shop_id = " . (int) $product->shop_id;
                     $db->setQuery($query);
                     $existing_words = $db->loadObjectList();
                     foreach ($existing_words as $data) {
                         unset($query_array[JeproshopValidator::replaceAccentedChars($data->word)]);
                     }
                 }
                 if (count($query_array)) {
                     // The words are inserted...
                     $query = "INSERT IGNORE INTO " . $db->quoteName('#__jeproshop_search_word') . " (lang_id, shop_id, word) VALUES " . implode(',', $query_array);
                     $db->setQuery($query);
                     $db->query();
                 }
                 if (count($query_array2)) {
                     // ...then their IDs are retrieved and added to the cache
                     $query = "SELECT search_word.word_id, search_word.word FROM " . $db->quoteName('#__jeproshop_search_word') . " AS search_word ";
                     $query .= " WHERE search_word.word IN (" . implode(',', $query_array2) . ") AND search_word.lang_id = " . (int) $product->lang_id;
                     $query .= " AND search_word.shop_id = " . (int) $product->shop_id . " LIMIT " . count($query_array2);
                     $db->setQuery($query);
                     $added_words = $db->loadObjectList();
                     // replace accents from the retrieved words so that words without accents or with differents accents can still be linked
                     foreach ($added_words as $word_id) {
                         $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . JeproshopValidator::replaceAccentedChars($word_id->word)] = (int) $word_id->word_id;
                     }
                 }
             }
             foreach ($product_array as $word => $weight) {
                 if (!$weight) {
                     continue;
                 }
                 if (!isset($word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word])) {
                     continue;
                 }
                 if (!$word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word]) {
                     continue;
                 }
                 $query_array3[] = '(' . (int) $product->product_id . ',' . (int) $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word] . ',' . (int) $weight . ')';
                 // Force save every 200 words in order to avoid overloading MySQL
                 if (++$count_words % 200 == 0) {
                     JeproshopSearch::saveIndex($query_array3);
                 }
             }
             if (!in_array($product->product_id, $products_array)) {
                 $products_array[] = (int) $product->product_id;
             }
         }
         JeproshopSearch::setProductsAsIndexed($products_array);
         // One last save is done at the end in order to save what's left
         JeproshopSearch::saveIndex($query_array3);
     }
     return true;
 }
Example #16
0
                echo JeproshopValidator::convertPrice($product->price_tax_exc);
            }
            ?>
							</span>
                                <meta itemprop="priceCurrency" content="<?php 
            echo $this->currency->iso_code;
            ?>
" />
                                <?php 
            if (isset($product->specific_prices) && $product->specific_prices && isset($product->specific_prices->reduction) && $product->specific_prices->reduction > 0) {
                ?>
                                    <?php 
                /* {hook h="displayProductPriceBlock" product=$product type="old_price"} */
                ?>
                                    <span class="old_price product_price"><?php 
                echo JeproshopValidator::displayPriceWithoutReduction($product->price_without_reduction);
                ?>
</span>
                                    <?php 
                //{hook h="displayProductPriceBlock" id_product=$product->id_product type="old_price"}
                ?>
                                    <?php 
                if ($product->specific_prices->reduction_type == 'percentage') {
                    ?>
                                        <span class="price_percent_reduction">-<?php 
                    echo $product->specific_prices->reduction * 100 . '%';
                    ?>
</span>
                                    <?php 
                }
                ?>
Example #17
0
 /**
  * Check employee informations saved into cookie and return employee validity
  *
  * @return boolean employee validity
  */
 public function isLoggedBack()
 {
     if (!JeproshopCache::isStored('jeproshop_is_logged_back_' . $this->employee_id)) {
         /* Employee is valid only if it can be load and if cookie password is the same as database one */
         JeproshopCache::store('jeproshop_is_logged_back_' . $this->employee_id, $this->employee_id && JeproshopValidator::isUnsignedInt($this->employee_id) && JeproshopEmployeeModelEmployee::checkPassword($this->employee_id, JeproshopContext::getContext()->cookie->passwd) && (!isset(JeproshopContext::getContext()->cookie->remote_addr) || JeproshopContext::getContext()->cookie->remote_addr == ip2long(JeproshopValidator::getRemoteAddr()) || !JeproshopSettingModelSetting::getValue('cookie_check_ip')));
     }
     return JeproshopCache::retrieve('jeproshop_is_logged_back_' . $this->employee_id);
 }