예제 #1
0
 public function renderDetails($tpl = null)
 {
     $cartModel = new JeproshopCartModelCart();
     $carts = $cartModel->getCartList();
     $this->assignRef('carts', $carts);
     if ($this->getLayout() != 'modal') {
         $this->addToolBar();
         $this->sideBar = JHtmlSidebar::render();
     }
     parent::display($tpl);
 }
예제 #2
0
 /**
      * Check if order is free
      * @return boolean
      * /
     public function checkFreeOrder(){
         $context = JeproshopContext::getContext();
         if ($context->cart->getOrderTotal() <= 0) {
             $order = new JeproshopFreeOrderModelFreeOrder();
             $order->free_order_class = true;
             $order->validateOrder($context->cart->cart_id, Configuration::get('PS_OS_PAYMENT'), 0, Tools::displayError('Free order', false), null, array(), null, false, $context->cart->secure_key);
             return (int)JeproshopOrderModelOrder::getOrderByCartId($context->cart->cart_id);
         }
         return false;
     }
 
 
     public function assignCarrier(){
         $view = JFactory::getDBO();
         $context = JeproshopContext::getContext();
         $address = new JeproshopAddressModelAddress($context->cart->address_delivery_id);
         $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId($address->address_id);
         $carriers = $context->cart->simulateCarriersOutput(null, true);
         $checked = $context->cart->simulateCarrierSelectedOutput(false);
         $delivery_option_list = $context->cart->getDeliveryOptionList();
         $delivery_option = $context->cart->getDeliveryOption(null, false);
         $this->setDefaultCarrierSelection($delivery_option_list);
 
         $view->assignRef('address_collection', $context->cart->getAddressCollection());
         $view->assignRef('delivery_option_list', $delivery_option_list);
         $view->assignRef('carriers', $carriers);
         $view->assignRef('checked',  $checked);
         $view->assignRef('delivery_option', $delivery_option);
 
 
         $vars = array(
             /*'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array(
                     'carriers' => $carriers,
                     'checked' => $checked,
                     'delivery_option_list' => $delivery_option_list,
                     'delivery_option' => $delivery_option
                 ))*  /
         );
 
         JeproshopCartModelCart::addExtraCarriers($vars);
 
         $view->assignRef('extra_carriers', $vars);
     }
 
     /**
      * Decides what the default carrier is and update the cart with it
      *
      * @todo this function must be modified - id_carrier is now delivery_option
      *
      * @param array $carriers
      *
      * @deprecated since 1.5.0
      *
      * @return number the id of the default carrier
      * /
     protected function setDefaultCarrierSelection($carriers) {
         $context = JeproshopContext::getContext();
         if (!$context->cart->getDeliveryOption(null, true))
             $context->cart->setDeliveryOption($context->cart->getDeliveryOption());
     }*/
 public function globalInitialization()
 {
     $app = JFactory::getApplication();
     $view = $app->input->get('view');
     $viewClass = $this->getView($view, JFactory::getDocument()->getType());
     $context = JeproshopContext::getContext();
     $this->isLogged = (bool) ($context->customer->customer_id && JeproshopCustomerModelCustomer::customerIdExistsStatic((int) $context->cookie->customer_id));
     parent::initialize();
     /* Disable some cache related bugs on the cart/order */
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     if (!$context->customer->isLogged(true) && $this->useMobileTheme() && $app->input->get('step')) {
         $app->redirect(JRoute::_('index.php?option=com_jeproshop&view=authentication&lang_id=' . $context->language->lang_id, true, 1));
     }
     // Redirect to the good order process
     $task = $app->input->get('task', '');
     $order_process_type = JeproshopSettingModelSetting::getValue('order_process_type');
     if ($order_process_type == 'standard' && ($task != '' || $task != 'display')) {
         //$app->redirect('index.php?option=com_jeproshop&view=order');
     }
     if ($order_process_type == 'page_checkout' && $task != 'opc') {
         $step = $app->input->get('step');
         if (isset($step) && $step == 3) {
             $app->redirect('index.php?option=com_jeproshop&view=order&task=opc&isPaymentStep=true');
         }
         $app->redirect('index.php?option=com_jeproshop&view=order&task=opc');
     }
     $catalog_mode = JeproshopSettingModelSetting::getValue('catalog_mode');
     if ($catalog_mode) {
         $this->has_errors = true;
         JError::raiseError(500, JText::_('COM_JEPROSHOP_THIS_STORE_DOES_NOT_ACCEPT_NEW_ORDER_MESSAGE'));
     }
     $order_id = (int) $app->input->get('order_id');
     $currentTask = $app->input->get('task');
     if ($currentTask == 'submitReorder' && $order_id) {
         $oldCart = new JeproshopCartModelCart(JeproshopOrderModelOrder::getStaticCartId($order_id, $context->customer->customer_id));
         $duplication = $oldCart->duplicate();
         if (!$duplication || !JeproshopTools::isLoadedObject($duplication->cart, 'cart_id')) {
             $this->has_errors = true;
             Tools::displayError('Sorry. We cannot renew your order.');
         } else {
             if (!$duplication->success) {
                 $this->has_errors = true;
                 Tools::displayError('Some items are no longer available, and we are unable to renew your order.');
             } else {
                 $context->cookie->cart_id = $duplication->cart->cart_id;
                 $context->cookie->write();
                 if ($order_process_type == 'page_checkout') {
                     $app->redirect('index.php?option=com_jeproshop&view=order&task=opc');
                 }
                 $app->redirect('index.php?option=com_jeproshop&view=order');
             }
         }
     }
     $viewClass->assignRef('order_process_type', $order_process_type);
     $nbProducts = $context->cart->numberOfProducts();
     if ($nbProducts) {
         if (JeproshopCartRuleModelCartRule::isFeaturePublished()) {
             if (Tools::isSubmit('submitAddDiscount')) {
                 if (!($code = trim(Tools::getValue('discount_name')))) {
                     $this->has_errors = true;
                     JError::raiseError('You must enter a voucher code.');
                 } elseif (!Validate::isCleanHtml($code)) {
                     $this->has_errors = true;
                     JEroor::raiseError('The voucher code is invalid.');
                 } else {
                     $cartRule = new JeproshopCartRuleModelCartRule(JeproshopCartRuleModelCartRule::getIdByCode($code));
                     if ($cartRule && JeproshopTools::isLoadedObject($cartRule, 'cart_rule_id')) {
                         if ($error = $cartRule->checkValidity($context, false, true)) {
                             $this->has_errors = true;
                             JError::raiseError(500, $error);
                         } else {
                             $context->cart->addCartRule($cartRule->cart_rule_id);
                             if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
                                 Tools::redirect('index.php?controller=order-opc&addingCartRule=1');
                             }
                             Tools::redirect('index.php?controller=order&task=adding_cart_rule');
                         }
                     } else {
                         $this->has_errors = true;
                         Tools::displayError('This voucher does not exists.');
                     }
                 }
                 $discountName = JeproshopTools::safeOutput($code);
                 $viewClass->assignRef('discount_name', $discountName);
             } elseif (($cart_rule_id = (int) Tools::getValue('delete_discount')) && JeproshopTools::isUnsignedId($cart_rule_id)) {
                 $context->cart->removeCartRule($cart_rule_id);
                 $app->redirect('index.php?option=com_jeproshop&view=order&task=opc');
             }
         }
         /* Is there only virtual product in cart */
         if ($isVirtualCart = $context->cart->isVirtualCart()) {
             $this->setNoCarrier();
         }
     }
     //$viewClass->assignRef('back', JTools::safeOutput(Tools::getValue('back')));*/
 }
예제 #3
0
파일: cart.php 프로젝트: jeprodev/jeproshop
 /**
  * @static
  * @param $lang_id
  * @param $customer_id
  * @param bool $published
  * @param bool $includeGeneric
  * @param bool $inStock
  * @param JeproshopCartModelCart|null $cart
  * @return array
  */
 public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null)
 {
     if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) {
         return array();
     }
     $db = JFactory::getDBO();
     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang');
     $query .= " AS cart_rule_lang ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND ";
     $query .= "cart_rule_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = ";
     $query .= (int) $customer_id . " OR cart_rule.group_restriction = 1 " . ($includeGeneric ? "OR cart_rule." . $db->quoteName('customer_id') . " = 0" : "");
     $query .= ") AND cart_rule.date_from < \"" . date('Y-m-d H:i:s') . "\" AND cart_rule.date_to > \"" . date('Y-m-d H:i:s') . "\"";
     $query .= ($published ? " AND cart_rule" . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : "");
     $db->setQuery($query);
     $result = $db->loadObjectList();
     // Remove cart rule that does not match the customer groups
     $customerGroups = JeproshopCustomerModelCustomer::getGroupsStatic($customer_id);
     foreach ($result as $key => $cart_rule) {
         if ($cart_rule->group_restriction) {
             $query = "SELECT " . $db->quoteName('group_id') . " FROM " . $db->quoteName('#__jeproshop_cart_rule_group') . " WHERE " . $db->quoteName('cart_rule_id') . " = " . (int) $cart_rule->cart_rule_id;
             $db->setQuery($query);
             $cartRuleGroups = $db->loadObjectList();
             foreach ($cartRuleGroups as $cartRuleGroup) {
                 if (in_array($cartRuleGroup->group_id, $customerGroups)) {
                     continue 2;
                 }
             }
             unset($result[$key]);
         }
     }
     foreach ($result as &$cart_rule) {
         if ($cart_rule->quantity_per_user) {
             $quantity_used = JeproshopOrderModelOrder::getCustomerDiscounts((int) $customer_id, (int) $cart_rule->cart_rule_id);
             if (isset($cart) && isset($cart->cart_id)) {
                 $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id);
             }
             $cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used;
         } else {
             $cart_rule->quantity_for_user = 0;
         }
     }
     unset($cart_rule);
     foreach ($result as $cart_rule) {
         if ($cart_rule->shop_restriction) {
             $query = "SELECT shop_id FROM " . $db->quoteName('#__jeproshop_cart_rule_shop') . " WHERE cart_rule_id = " . (int) $cart_rule->cart_rule_id;
             $db->setQuery($query);
             $cartRuleShops = $db->loadObjectList();
             foreach ($cartRuleShops as $cartRuleShop) {
                 if (JeproshopShopModelShop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getShopContext()->shop->shop_id) {
                     continue 2;
                 }
             }
             unset($result[$key]);
         }
     }
     // RetroCompatibility with 1.4 discounts
     foreach ($result as &$cart_rule) {
         $cart_rule->value = 0;
         $cart_rule->minimal = JeproshopTools::convertPriceFull($cart_rule->minimum_amount, new JeproshopCurrencyModelCurrency($cart_rule->minimum_amount_currency), JeproshopContext::getContext()->currency);
         $cart_rule->cumulable = !$cart_rule->cart_rule_restriction;
         $cart_rule->discount_type_id = false;
         if ($cart_rule->free_shipping) {
             $cart_rule->discount_type_id = Discount::FREE_SHIPPING;
         } elseif ($cart_rule->reduction_percent > 0) {
             $cart_rule->discount_type_id = Discount::PERCENT;
             $cart_rule->value = $cart_rule->reduction_percent;
         } elseif ($cart_rule->reduction_amount > 0) {
             $cart_rule->discount_type_id = Discount::AMOUNT;
             $cart_rule->value = $cart_rule->reduction_amount;
         }
     }
     return $result;
 }
예제 #4
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);
 }
예제 #5
0
파일: cart.php 프로젝트: jeprodev/jeproshop
    /**
     * @static
     * @param $lang_id
     * @param $customer_id
     * @param bool $published
     * @param bool $includeGeneric
     * @param bool $inStock
     * @param JeproshopCartModelCart|null $cart
     * @return array
     */
    public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null)
    {
        if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) {
            return array();
        }
        $db = JFactory::getDBO();
        $query = "SELECT * FROM " . $db->quoteName('#_jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang') . " AS cart_ruler_lang";
        $query .= " ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND cart_rule_lang." . $db->quoteName('lang_id');
        $query .= " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = " . (int) $customer_id . " OR cart_rule.group_restriction = 1 ";
        $query .= ($includeGeneric ? " OR cart_rule." . $db->quoteName('customer_id') . " = 0" : "") . ") AND cart_rule.date_from < '" . date('Y-m-d H:i:s') . "' AND cart_rule.date_to > '";
        $query .= date('Y-m-d H:i:s') . "' " . ($published ? "AND cart_rule." . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : "");
        $db->setQuery($query);
        $result = $db->loadObjectList();
        // Remove cart rule that does not match the customer groups
        $customerGroups = JeproshopCustomerModelCustomer::getStaticGroups($customer_id);
        foreach ($result as $key => $cart_rule) {
            if ($cart_rule->group_restriction) {
                $cartRuleGroups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'cart_rule_group WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']);
                foreach ($cartRuleGroups as $cartRuleGroup) {
                    if (in_array($cartRuleGroup->group_id, $customerGroups)) {
                        continue 2;
                    }
                }
                unset($result[$key]);
            }
        }
        foreach ($result as &$cart_rule) {
            if ($cart_rule->quantity_per_user) {
                $quantity_used = Order::getDiscountsCustomer((int) $customer_id, (int) $cart_rule->cart_rule_id);
                if (isset($cart) && isset($cart)) {
                    $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id);
                }
                $cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used;
            } else {
                $cart_rule->quantity_for_user = 0;
            }
        }
        unset($cart_rule);
        foreach ($result as $key => $cart_rule) {
            if ($cart_rule->shop_restriction) {
                $cartRuleShops = Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'cart_rule_shop WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']);
                foreach ($cartRuleShops as $cartRuleShop) {
                    if (Shop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getContext()->shop->shop_id) {
                        continue 2;
                    }
                }
                unset($result[$key]);
            }
        }
        if (isset($cart) && isset($cart->cart_id)) {
            foreach ($result as $key => $cart_rule) {
                if ($cart_rule->product_restriction) {
                    $cr = new JeproshopCartRuleModelCartRule((int) $cart_rule->cart_rule_id);
                    $restriction = $cr->checkProductRestrictions(JeproshopContext::getContext(), false, false);
                    if ($restriction !== false) {
                        continue;
                    }
                    unset($result[$key]);
                }
            }
        }
        foreach ($result as $key => $cart_rule) {
            if ($cart_rule['country_restriction']) {
                $countries = Db::getInstance()->ExecuteS('
					SELECT `id_country`
					FROM `' . _DB_PREFIX_ . 'address`
					WHERE `customer_id` = ' . (int) $customer_id . '
					AND `deleted` = 0');
                if (is_array($countries) && count($countries)) {
                    foreach ($countries as $country) {
                        $id_cart_rule = (bool) Db::getInstance()->getValue('
							SELECT crc.id_cart_rule
							FROM ' . _DB_PREFIX_ . 'cart_rule_country crc
							WHERE crc.id_cart_rule = ' . (int) $cart_rule['id_cart_rule'] . '
							AND crc.id_country = ' . (int) $country['id_country']);
                        if (!$id_cart_rule) {
                            unset($result[$key]);
                        }
                    }
                }
            }
        }
        // Retro-compatibility with 1.4 discounts
        foreach ($result as &$cart_rule) {
            $cart_rule['value'] = 0;
            $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency);
            $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction'];
            $cart_rule['id_discount_type'] = false;
            if ($cart_rule['free_shipping']) {
                $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING;
            } elseif ($cart_rule['reduction_percent'] > 0) {
                $cart_rule['id_discount_type'] = Discount::PERCENT;
                $cart_rule['value'] = $cart_rule['reduction_percent'];
            } elseif ($cart_rule['reduction_amount'] > 0) {
                $cart_rule->discount_type_id = Discount::AMOUNT;
                $cart_rule['value'] = $cart_rule['reduction_amount'];
            }
        }
        unset($cart_rule);
        return $result;
    }
예제 #6
0
        ?>
</td -->
                            <td class="nowrap center"  width="3%" ><?php 
        echo $cart->order_id;
        ?>
</td>
                            <td class="nowrap" ><?php 
        echo $cart->customer_name;
        ?>
</td>
                            <td class="nowrap center" ><?php 
        echo JeproshopCartModelCart::getOrderTotalUsingTaxCalculationMethod($cart->cart_id);
        ?>
</td>
                            <td class="nowrap" ><?php 
        echo JeproshopCartModelCart::replaceZeroByShopName($cart->carrier_name);
        ?>
</td>
                            <td class="nowrap" ><?php 
        echo $cart->date_add;
        ?>
</td>
                            <td class="nowrap" ><?php 
        //echo $cart;
        ?>
</td>
                            <td class="nowrap" >
                                <div class="btn-group-action" >
                                    <div class="btn-group pull-right" >
                                        <a href="<?php 
        echo $cart_view_link;
예제 #7
0
 public function initialize()
 {
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     $app = JFactory::getApplication();
     $context = JeproshopContext::getContext();
     $view = $app->input->get('view', 'default');
     $viewClass = $this->getView($view, JFactory::getDocument()->getType());
     if (JeproshopTools::usingSecureMode()) {
         $this->ssl_enabled = true;
     }
     if (isset($context->cookie->account_created)) {
         $accountCreated = true;
         $viewClass->assignRef('account_created', $accountCreated);
         $context->cookie->account_created = 0;
     }
     JeproshopTools::setCookieLanguage($context->cookie);
     $cart_id = (int) $this->recoverCart();
     if ($cart_id) {
         $context->cookie->cart_id = $cart_id;
     }
     if ($this->authenticated && !$context->customer->isLogged($this->guest_allowed)) {
         $app->redirect('index.php?option=com_jeproshop&view=authentication');
         // todo add retun option
     }
     if (JeproshopSettingModelSetting::getValue('enable_geolocation')) {
         $defaultCountry = $this->geolocationManagement($context->country);
         if ($defaultCountry && JeproshopTools::isLoadedObject($defaultCountry, 'country_id')) {
             $context->country = $defaultCountry;
         }
     }
     $currency = JeproshopTools::setCurrency($context->cookie);
     $logout = $app->input->get('logout');
     $myLogout = $app->input->get('mylogout');
     if (isset($logout) || $context->customer->logged && JeproshopCustomerModelCustomer::isBanned($context->cutomer->customer_id)) {
         $context->customer->logout();
         //$app->input->get('')
     } elseif (isset($myLogout)) {
         $context->customer->mylogout();
     }
     if ((int) $context->cookie->cart_id) {
         $cart = new JeproshopCartModelCart($context->cookie->cart_id);
         if ($cart->orderExists()) {
             $context->cookie->cart_id = null;
             $context->cookie->check_selling_condition = false;
         } elseif ((int) JeproshopSettingModelSetting::getValue('enable_geolocation') && !in_array(strtoupper($context->cookie->iso_code_country), explode(';', JeproshopSettingModelSetting::getValue('allowed_countries'))) && $cart->numberOfProducts() && (int) JeproshopSettingModelSetting::getValue('geolocation_behavior') != -1 && !self::isInWhiteListForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
             $context->cookie->cart_id = null;
             $cart = null;
         } elseif ($context->cookie->customer_id != $cart->customer_id || $context->cookie->lang_id != $cart->lang_id || $currency->currency_id != $cart->currency_id) {
             if ($context->cookie->customer_id) {
                 $cart->customer_id = (int) $context->cookie->customer_id;
             }
             $cart->lang_id = (int) $context->cookie->lang_id;
             $cart->currency_id = (int) $currency->currency_id;
             $cart->update();
         }
         if (isset($cart) && (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0 || !isset($cart->address_invoice_id) || $cart->address_invoice_id) && $context->cookie->customer_id) {
             $toUpdate = false;
             if (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0) {
                 $toUpdate = true;
                 $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             }
             if (!isset($cart->address_invoice_id) || $cart->address_invoice_id == 0) {
                 $toUpdate = true;
                 $cart->address_invoice_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             }
             if ($toUpdate) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || $cart->cart_id) {
         $cart = new JeproshopCartModelCart();
         $cart->lang_id = (int) $context->cookie->lang_id;
         $cart->currency_id = (int) $context->cookie->currency_id;
         $cart->guest_id = (int) $context->cookie->guest_id;
         $cart->shop_group_id = (int) $context->shop->shop_group_id;
         $cart->shop_id = $context->shop->shop_id;
         if ($context->cookie->customer_id) {
             $cart->customer_id = (int) $context->cookie->id_customer;
             $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             $cart->address_invoice_id = $cart->address_delivery_id;
         } else {
             $cart->address_delivery_id = 0;
             $cart->address_invoice_id = 0;
         }
         // Needed if the merchant want to give a free product to every visitors
         $context->cart = $cart;
         JeproshopCartRuleModelCartRule::autoAddToCart($context);
     } else {
         $context->cart = $cart;
     }
     JeproshopProductModelProduct::initPricesComputation();
     $display_tax_label = $context->country->display_tax_label;
     if (isset($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) && $cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) {
         $info = JeproshopAddressModelAddress::getCountryAndState($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
         $country = new JeproshopCountryModelCountry((int) $info->country_id);
         $context->country = $country;
         if (JeproshopTools::isLoadedObject($country, 'country_id')) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $languages = JeproshopLanguageModelLanguage::getLanguages(true);
     $meta_language = array();
     foreach ($languages as $lang) {
         $meta_language[] = $lang->iso_code;
     }
     $compared_products = array();
     $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item');
     if ($comparatorMaxItem && isset($context->cookie->compare_id)) {
         $compared_products = JeproshopProductComparedModelProductCompared::getComparedProducts($context->cookie->compare_id);
     }
     $mobileDevice = $context->getMobileDevice();
     $viewClass->assignRef('mobile_device', $mobileDevice);
     $viewClass->assignRef('cart', $cart);
     $viewClass->assignRef('currency', $currency);
     $viewClass->assignRef('display_tax_label', $display_tax_label);
     $isLogged = (bool) $context->customer->isLogged();
     $viewClass->assignRef('is_logged', $isLogged);
     $isGuest = (bool) $context->customer->isGuest();
     $viewClass->assignRef('is_guest', $isGuest);
     $priceRoundMode = JeproshopSettingModelSetting::getValue('price_round_mode');
     $viewClass->assignRef('price_round_mode', $priceRoundMode);
     $useTax = JeproshopSettingModelSetting::getValue('use_tax');
     $viewClass->assignRef('use_taxes', $useTax);
     $showTax = (int) JeproshopSettingModelSetting::getValue('display_tax') == 1 && JeproshopSettingModelSetting::getValue('use_tax');
     $viewClass->assignRef('show_tax', $showTax);
     $catalogMode = (bool) JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices;
     $viewClass->assignRef('catalog_mode', $catalogMode);
     $enableB2bMode = (bool) JeproshopSettingModelSetting::getValue('enable_b2b_mode');
     $viewClass->assignRef('enable_b2b_mode', $enableB2bMode);
     $stockManagement = JeproshopSettingModelSetting::getValue('stock_management');
     $viewClass->assignRef('stock_management', $stockManagement);
     $metaLanguages = implode(',', $meta_language);
     $viewClass->assignRef('meta_languages', $metaLanguages);
     $viewClass->assignRef('languages', $languages);
     $numberOfProducts = $cart->numberOfProducts();
     $viewClass->assignRef('cart_quantities', $numberOfProducts);
     $currencies = JeproshopCurrencyModelCurrency::getCurrencies();
     $viewClass->assignRef('currencies', $currencies);
     $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item');
     $viewClass->assignRef('comparator_max_item', $comparatorMaxItem);
     $quickView = (bool) JeproshopSettingModelSetting::getValue('quick_view');
     $viewClass->assignRef('quick_view', $quickView);
     $restrictedCountryMode = false;
     $viewClass->assignRef('restricted_country_mode', $restrictedCountryMode);
     $displayPrice = JeproshopProductModelProduct::getTaxCalculationMethod((int) $context->cookie->customer_id);
     $viewClass->assignRef('display_price', $displayPrice);
     /*$viewClass->assignRef('');
       $viewClass->assignRef('');
       $viewClass->assignRef('');*/
     $viewClass->assignRef('compared_products', $compared_products);
     /*$viewClass->assignRef('comparator_max_item', $comparatorMaxItem); */
 }