/** * 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')));*/ }
public function assignSummaryInformations() { $context = JeproshopContext::getContext(); $summary = $context->cart->getSummaryDetails(); $customizedDatas = JeproshopProductModelProduct::getAllCustomizedDatas($context->cart->cart_id); // override customization tax rate with real tax (tax rules) if ($customizedDatas) { foreach ($summary['products'] as &$productUpdate) { $productId = (int) (isset($productUpdate->product_id) ? $productUpdate->product_id : $productUpdate->product_id); $productAttributeId = (int) (isset($productUpdate->product_attribute_id) ? $productUpdate->product_attribute_id : $productUpdate->product_attribute_id); if (isset($customizedDatas[$productId][$productAttributeId])) { $productUpdate->tax_rate = JeproshopTaxModelTax::getProductTaxRate($productId, $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); } } JeproshopProductModelProduct::addCustomizationPrice($summary->products, $customizedDatas); } $cart_product_context = JeproshopContext::getContext()->cloneContext(); foreach ($summary['products'] as $key => $product) { $product->quantity = $product->cart_quantity; // for compatibility with 1.2 themes if ($cart_product_context->shop->shop_id != $product->shop_id) { $cart_product_context->shop = new JeproshopModelShop((int) $product->shop_id); } $null = null; $product->price_without_specific_price = JeproshopProductModelProduct::getStaticPrice($product->product_id, !JeproshopProductModelProduct::getTaxCalculationMethod(), $product->product_attribute_id, 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context); if (JeproshopProductModelProduct::getTaxCalculationMethod()) { $product->is_discounted = $product->price_without_specific_price != $product->price; } else { $product->is_discounted = $product->price_without_specific_price != $product->price_wt; } } // Get available cart rules and unset the cart rules already in the cart $available_cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->language->lang_id, isset($this->context->customer->customer_id) ? $this->context->customer->customer_id : 0, true, true, true, $this->context->cart); $cart_cart_rules = $context->cart->getCartRules(); foreach ($available_cart_rules as $key => $available_cart_rule) { if (!$available_cart_rule->high_light || strpos($available_cart_rule->code, 'BO_ORDER_') === 0) { unset($available_cart_rules[$key]); continue; } foreach ($cart_cart_rules as $cart_cart_rule) { if ($available_cart_rule->cart_rule_id == $cart_cart_rule->cart_rule_id) { unset($available_cart_rules[$key]); continue 2; } } } $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && JeproshopSettingModelSetting::getValue('ship_when_available'); $this->assign($summary); //$this->assign('token_cart', Tools::getToken(false)); $this->assign('is_logged', $this->context->controller->isLogged); $this->assign('is_virtual_cart', $this->context->cart->isVirtualCart()); $this->assign('product_number', $this->context->cart->numberOfProducts()); $this->assign('voucher_allowed', JeproshopCartRuleModelCartRule::isFeaturePublished()); $this->assign('shipping_cost', $this->context->cart->getOrderTotal(true, JeproshopCartModelCart::ONLY_SHIPPING)); $this->assign('shipping_cost_tax_excluded', $this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_SHIPPING)); $this->assign('customizedDatas', $customizedDatas); $this->assign('CUSTOMIZE_FILE', JeproshopProductModelProduct::CUSTOMIZE_FILE); $this->assign('CUSTOMIZE_TEXT_FIELD', JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD); $this->assign('last_product_added', $this->context->cart->getLastProduct()); $this->assign('display_vouchers', $available_cart_rules); $this->assign('currency_sign', $this->context->currency->sign); $this->assign('currency_rate', $this->context->currency->conversion_rate); $this->assign('currency_format', $this->context->currency->format); $this->assign('currency_blank', $this->context->currency->blank); $this->assign('show_option_allow_separate_package', $show_option_allow_separate_package); $this->assign('small_size', JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('small'))); /* $this->context->smarty->assign(array( 'HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary) ));*/ }
/** * Make sure caches are empty * Must be called before calling multiple time getContextualValue() */ public static function cleanObjectCache() { self::$only_one_gift = array(); }
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); }
public function product() { // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots if (!$this->context) { $this->context = JeproshopContext::getContext(); } if ($this->context->cookie->exists() && !$this->has_errors && !($this->context->customer->isLogged() && !$this->isTokenValid())) { // Send noindex to avoid ghost carts by bots header("X-Robots-Tag: noindex, nofollow", true); if (!$this->isInitialized()) { $this->initialize(); } $app = JFactory::getApplication(); $product_id = $app->input->get('product_id', null); $customization_id = (int) $app->input->get('customization_id', null); $address_delivery_id = (int) $app->input->get('address_delivery_id', null); $product_attribute_id = $app->input->get('product_attribute_id', null); $mode = $app->input->get('task') == 'update' && $product_id ? 'update' : 'add'; if ($app->input->get('quantity') == 0) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_NULL_QUANTITY_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } elseif (!$product_id) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_PRODUCT_ID_NOT_FOUND_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } $product = new JeproshopProductModelProduct($product_id, true, $this->context->language->lang_id); if (!$product->product_id || !$product->published) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THIS_PRODUCT_IS_NO_LONGER_AVAILABLE_MESSAGE.') . ' ' . !$app->input->get('use_ajax'); exit; } $quantity = abs($app->input->get('quantity', 1)); $qty_to_check = $quantity; $cart_products = $this->context->cart->getProducts(); if (is_array($cart_products)) { foreach ($cart_products as $cart_product) { if ((!isset($this->product_attribute_id) || $cart_product->product_attribute_id == $product_attribute_id) && (isset($product_id) && $cart_product->product_id == $product_id)) { $qty_to_check = $cart_product->cart_quantity; if ($app->input->get('op', 'up') == 'down') { $qty_to_check -= $quantity; } else { $qty_to_check += $quantity; } break; } } } // Check product quantity availability if ($product_attribute_id) { if (!JeproshopProductModelProduct::isAvailableWhenOutOfStock($product->out_of_stock) && !JeproshopAttributeModelAttribute::checkAttributeQty($product_attribute_id, $qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } } elseif ($product->hasAttributes()) { $minimumQuantity = $product->out_of_stock == 2 ? !JeproshopSettingModelSetting::getValue('order_out_of_stock') : !$product->out_of_stock; $product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($product->product_id, $minimumQuantity); // @todo do something better than a redirect admin !! if (!$product_attribute_id) { $app->redirect($this->getProductLink($product)); } elseif (!JeproshopProductModelProduct::isAvailableWhenOutOfStock($product->out_of_stock) && !JeproshopAttributeModelAttribute::checkAttributeQty($product_attribute_id, $qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } } elseif (!$product->checkQuantity($qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } // If no errors, process product addition if ($mode == 'add') { // Add cart if no cart found if (!$this->context->cart->cart_id) { if (JeproshopContext::getContext()->cookie->guest_id) { $guest = new JeproshopGuestModelGuest(JeproshopContext::getContext()->cookie->guest_id); $this->context->cart->mobile_theme = $guest->mobile_theme; } $this->context->cart->add(); if ($this->context->cart->cart_id) { $this->context->cookie->cart_id = (int) $this->context->cart->cart_id; } } // Check customizable fields if (!$product->hasAllRequiredCustomizableFields() && !$customization_id) { // $this->errors[] = Tools::displayError('Please fill in all of the required fields, and then save your customizations.', !Tools::getValue('ajax')); } if (!$this->has_errors) { $cart_rules = $this->context->cart->getCartRules(); $update_quantity = $this->context->cart->updateQuantity($quantity, $product_id, $product_attribute_id, $customization_id, $app->input->get('op', 'up'), $address_delivery_id); if ($update_quantity < 0) { // If product has attribute, minimal quantity is set with minimal quantity of attribute $minimal_quantity = $product_attribute_id ? JeproshopAttributeModelAttribute::getAttributeMinimalQty($product_attribute_id) : $product->minimal_quantity; $this->has_errors = true; sprintf(Tools::displayError('You must add %d minimum quantity', !$app->input->get('use_ajax')), $minimal_quantity); } elseif (!$update_quantity) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_YOU_ALREADY_HAVE_THE_MAXIMUM_AVAILABLE_FOR_THIS_PRODUCT_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } elseif ((int) $app->input->get('allow_refresh')) { // If the cart rules has changed, we need to refresh the whole cart $cart_rules2 = $this->context->cart->getCartRules(); if (count($cart_rules2) != count($cart_rules)) { $this->ajax_refresh = true; } else { $rule_list = array(); foreach ($cart_rules2 as $rule) { $rule_list[] = $rule->cart_rule_id; } foreach ($cart_rules as $rule) { if (!in_array($rule->cart_rule_id, $rule_list)) { $this->ajax_refresh = true; break; } } } } } } $removed = JeproshopCartRuleModelCartRule::autoRemoveFromCart(); JeproshopCartRuleModelCartRule::autoAddToCart(); if (count($removed) && (int) $app->input->get('allow_refresh')) { $this->ajax_refresh = true; } echo 'bonjour'; exit; } elseif (!$this->context->cookie->exists()) { echo 'bonjour cookkie'; exit; } elseif ($this->has_errors) { } elseif ($this->context->customer->isLogged() && !$this->isTokenValid()) { } }
public function delete() { if ((int) $this->category_id === 0 || (int) $this->category_id === 1) { return false; } $this->clearCache(); $allCategories = $this->getAllChildren(); $allCategories[] = $this; foreach ($allCategories as $category) { $category->deleteLite(); if (!$this->hasMultishopEntries()) { $category->deleteImage(); $category->cleanGroups(); $category->cleanAssoProducts(); // Delete associated restrictions on cart rules JeproshopCartRuleModelCartRule::cleanProductRuleIntegrity('categories', array($category->category_id)); JeproshopCategoryModelCategory::cleanPositions($category->parent_id); /* Delete Categories in GroupReduction */ if (JeproshopGroupReductionModelGroupReduction::getGroupsReductionByCategoryId((int) $category->category_id)) { JeproshopGroupReductionModelGroupReduction::deleteCategory($category->category_id); } } } /* Rebuild the nested tree */ if (!$this->hasMultishopEntries() && (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)) { JeproshopCategoryModelCategory::regenerateEntireNtree(); } Hook::exec('actionCategoryDelete', array('category' => $this)); return true; }
/** * @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; }
public function delete() { if (!count(JeproshopOrderModelOrder::getCustomerOrders((int) $this->customer_id))) { $addresses = $this->getAddresses((int) JeproshopSettingModelSetting::getValue('default_lang')); foreach ($addresses as $address) { $obj = new JeproshopAddressModelAddress((int) $address->address_id); $obj->delete(); } } $db = JFactory::getDBO(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_customer_group') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $db->query(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_message') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $db->query(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_specific_price') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $db->query(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_compare') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $db->query(); $query = "SELECT " . $db->quoteName('cart_id') . " FROM " . $db->quoteName('#__jeproshop_cart') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $carts = $db->loadObjectList(); if ($carts) { foreach ($carts as $cart) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_cart') . " WHERE " . $db->quoteName('cart_id') . " = " . (int) $cart->cart_id; $db->setQuery($query); $db->query(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_cart_product') . " WHERE " . $db->quoteName('cart_id') . " = " . (int) $cart->cart_id; $db->setQuery($query); $db->query(); } } $query = "SELECT " . $db->quoteName('customer_thread_id') . " FROM " . $db->quoteName('#__jeproshop_customer_thread') . " WHERE " . $this->quoteName('customer_id') . " = " . (int) $this->customer_id; $db->setQuery($query); $customer_threads = $db->loadObjectList(); if ($customer_threads) { foreach ($customer_threads as $customer_thread) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_customer_thread') . " WHERE " . $db->quoteName('customer_thread_id') . " = " . (int) $customer_thread->customer_thread_id; $db->setQuery($query); $db->query(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_customer_message') . " WHERE " . $db->quoteName('customer_thread_id') . " = " . (int) $customer_thread->customer_thread_id; $db->setQuery($query); $db->query(); } } JeproshopCartRuleModelCartRule::deleteByCustomerId((int) $this->customer_id); return parent::delete(); }
public function deleteFromCartRules() { JeproshopCartRuleModelCartRule::cleanProductRuleIntegrity('products', $this->product_id); return true; }
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); */ }