Esempio n. 1
0
 /**
  * Get quantity for a given attribute combination
  * Check if quantity is enough to deserve customer
  *
  * @param integer $product_attribute_id Product attribute combination id
  * @param integer $qty Quantity needed
  * @return boolean Quantity is available or not
  */
 public static function checkAttributeQty($product_attribute_id, $qty, JeproshopShopModelShop $shop = null)
 {
     if (!$shop) {
         $shop = JeproshopContext::getContext()->shop;
     }
     $result = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct(null, (int) $product_attribute_id, $shop->shop_id);
     return $result && $qty <= $result;
 }
Esempio n. 2
0
 /**
  *
  * This method allow to add stock information on a product detail
  *
  * If advanced stock management is active, get physical stock of this product in the warehouse associated to the product for the current order
  * Else get the available quantity of the product in function of the shop associated to the order
  *
  * @param array &$product
  */
 protected function setProductCurrentStock(&$product)
 {
     if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && (int) $product->advanced_stock_management == 1 && (int) $product->warehouse_id > 0) {
         $product->current_stock = JeproshopStockManagerFactory::getManager()->getProductPhysicalQuantities($product->product_id, $product->product_attribute_id, (int) $product->warehouse_id, true);
     } else {
         $product->current_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, $product->product_attribute_id, (int) $this->shop_id);
     }
 }
Esempio n. 3
0
 /**
  * For a given product, tells if it depends on the physical (usable) stock
  *
  * @param int $product_id
  * @param int $shop_id Optional : gets context if null @see Context::getContext()
  * @return bool : depends on stock @see $depends_on_stock
  */
 public static function dependsOnStock($product_id, $shop_id = null)
 {
     if (!JeproshopTools::isUnsignedInt($product_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     $query = "SELECT depends_on_stock FROM " . $db->quoteName('#__jeproshop_stock_available') . " WHERE product_id = " . (int) $product_id;
     $query .= " AND product_attribute_id = 0 " . JeproshopStockAvailableModelStockAvailable::addShopRestriction($shop_id);
     $db->setQuery($query);
     return $db->loadResult();
 }
Esempio n. 4
0
 public function update_status()
 {
     $app = JFactory::getApplication();
     $order_status_id = $app->input->get('order_status_id');
     $order_id = $app->input->get('order_id');
     $order = new JeproshopOrderModelOrder($order_id);
     $context = JeproshopContext::getContext();
     if (!JeproshopTools::isLoadedObject($order, 'order_id')) {
         echo '<p>' . JText::_('COM_JEPROSHOP_THE_ORDER_CANNOT_BE_FOUND_WITH_IN_YOUR_DATABASE_MESSAGE') . '</p>';
     }
     if ($this->viewAccess()) {
         $orderStatus = new JeproshopOrderStatusModelOrderStatus($order_status_id);
         if (!JeproshopTools::isLoadedObject($orderStatus, 'order_status_id')) {
             echo JText::_('COM_JEPROSHOP_THE_ORDER_STATUS_CANNOT_BE_FOUND_WITH_IN_YOUR_DATABASE_MESSAGE');
         } else {
             $order = new JeproshopOrderModelOrder();
             $currentOrderStatus = $order->getCurrentOrderStatus();
             if ($currentOrderStatus->order_status_id != $orderStatus) {
                 // Create a order history
                 $orderHistory = new JeproshopOrderHistoryModelOrderHistory();
                 $orderHistory->order_id = $order->order_id;
                 $orderHistory->employee_id = (int) $context->employee->employee_id;
                 $useExistingPayment = false;
                 if (!$order->hasInvoice()) {
                     $useExistingPayment = true;
                 }
                 $orderHistory->changeOrderStatusId((int) $orderStatus->order_status_id, $order, $useExistingPayment);
                 $carrier = new JeproshopCarrierModelCarrier($order->carrier_id, $order->lang_id);
                 $templateVars = array();
                 if ($orderHistory->order_status_id == JeproshopSettingModelSetting::getValue('order_status_shipping') && $order->shipping_number) {
                 }
                 if ($orderHistory->addWithEmail(true, $templateVars)) {
                     // synchronizes quantities if needed...
                     if (JeproshopSettingModelSetting::getValue('advanced_stock_management')) {
                         foreach ($order->getProducts() as $product) {
                             if (JeproshopStockAvailableModelStockAvailable::dependsOnStock($product->product_id)) {
                                 JeproshopStockAvailableModelStockAvailable::synchronize($product->product_id, (int) $product->sho_id);
                             }
                         }
                     }
                     $app->redirect('index.php?option=com_jeproshop&view=order&task=view&order_id=' . (int) $order->order_id . '&' . JeproshopTools::getOrderToken() . '=1');
                 }
                 echo JText::_('COM_JEPROSHOP_AN_ERROR_OCCURRED_WHILE_CHANGING_ORDER_STATUS_OR_WE_WERE_UNABLE_TO_SEND_AN_EMAIL_TO_THE_CUSTOMER_MESSAGE');
             } else {
                 echo JText::_('COM_JEPROSHOP_THE_ORDER_HAS_ALREADY_BEEN_ASSIGNED_THIS_STATUS_MESSAGE');
             }
         }
     } else {
         echo JText::_('COM_JEPROSHOP_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_ORDER_MESSAGE');
     }
 }
Esempio n. 5
0
 public function delete()
 {
     $db = JFactory::getDBO();
     $this->clearCache();
     $result = true;
     if (JeproshopShopModelShop::isTableAssociated('product_attribute')) {
         $shopListIds = JeproshopShopModelShop::getContextListShopIds();
         if (count($this->shop_list_id)) {
             $shopListIds = $this->shop_list_id;
         }
         $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_shop') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id . " AND " . $db->quoteName('shop_id') . " IN (" . implode($shopListIds) . ")";
         $db->setQuery($query);
         $result &= $db->query();
     }
     $hasMultiShopEntries = $this->hasMultiShopEntries();
     if ($result && !$hasMultiShopEntries) {
         $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id;
         $db->setQuery($query);
         $result &= $db->query();
     }
     if ($this->multi_lang && !$hasMultiShopEntries) {
         $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_lang') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id;
         $db->setQuery($query);
         $result &= $db->query();
     }
     if (!$result) {
         return false;
     }
     // Removes the product from StockAvailable, for the current shop
     JeproshopStockAvailableModelStockAvailable::removeProductFromStockAvailable((int) $this->product_id, (int) $this->product_attribute_id);
     if ($specific_prices = JeproshopSpecificPriceModelSpecificPrice::getByProductId((int) $this->product_id, (int) $this->product_attribute_id)) {
         foreach ($specific_prices as $specific_price) {
             $price = new JeproshopSpecificPriceModelSpecificPrice((int) $specific_price->specific_price_id);
             $price->delete();
         }
     }
     if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) {
         return false;
     }
     $this->deleteFromSupplier($this->product_id);
     JeproshopProductModelProduct::updateDefaultAttribute($this->product_id);
     return true;
 }
Esempio n. 6
0
 /**
  * Removes a given product from the stock available
  *
  * @param int $product_id
  * @param int $product_attribute_id Optional
  * @param mixed $shop shop id or shop object Optional
  */
 public static function removeProductFromStockAvailable($product_id, $product_attribute_id = null, $shop = null)
 {
     if (!JeproshopTools::isUnsignedInt($product_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
         if (JeproshopShopModelShop::getContextShopGroup()->share_stock == 1) {
             $product_attribute_sql = '';
             if ($product_attribute_id !== null) {
                 $product_attribute_sql = '_attribute';
                 $product_attribute_id_sql = $product_attribute_id;
             } else {
                 $product_attribute_id_sql = $product_id;
             }
             $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product' . $product_attribute_sql . '_shop') . " WHERE " . $db->quoteName('product' . $product_attribute_sql . '_id') . " = ";
             $query .= (int) $product_attribute_id_sql . " AND " . $db->quoteName('shop_id') . " IN (" . implode(',', array_map('intval', JeproshopShopModelShop::getContextListShopIds(JeproshopShopModelShop::SHARE_STOCK))) . ")";
             $db->setQuery($query);
             $result = (int) $db->loadResult();
             if ($result) {
                 return true;
             }
         }
     }
     $query = "DELETE FROM " . $db->quoteName('#__jeproshop_stock_available') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id;
     $query .= ($product_attribute_id ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : "") . JeproshopStockAvailableModelStockAvailable::addShopRestriction(null, $shop);
     $db->setQuery($query);
     $res = $db->query();
     if ($product_attribute_id) {
         if ($shop === null || !JeproshopTools::isLoadedObject($shop, 'shop_id')) {
             $shop_datas = new Object();
             JeproshopStockAvailableModelStockAvailable::addSqlShopParams($shop_datas);
             $shop_id = (int) $shop_datas->shop_id;
         } else {
             $shop_id = (int) $shop->shop_id;
         }
         $stock_available = new JeproshopStockAvailableModelStockAvailable();
         $stock_available->product_id = (int) $product_id;
         $stock_available->product_attribute_id = (int) $product_id;
         $stock_available->shop_id = (int) $shop_id;
         $stock_available->postSave();
     }
     JeproshopCache::clean('jeproshop_stock_available_get-quantity_Available_by_product_' . (int) $product_id . '_*');
     return $res;
 }
Esempio n. 7
0
 /**
  * Check product availability
  *
  * @param integer $qty Quantity desired
  * @return boolean True if product is available with this quantity
  */
 public function checkQuantity($qty)
 {
     if (JeproshopProductPack::isPack((int) $this->product_id) && !JeproshopProductPack::isInStock((int) $this->product_id)) {
         return false;
     }
     if ($this->isAvailableWhenOutOfStock(JeproshopStockAvailableModelStockAvailable::outOfStock($this->product_id))) {
         return true;
     }
     if (isset($this->product_attribute_id)) {
         $product_attribute_id = $this->product_attribute_id;
     } else {
         $product_attribute_id = 0;
     }
     return $qty <= JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($this->product_id, $product_attribute_id);
 }
Esempio n. 8
0
 public function renderView($tpl = NULL)
 {
     if (!isset($this->context) || $this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     $app = JFactory::getApplication();
     $order = new JeproshopOrderModelOrder($app->input->get('order_id'));
     if (!JeproshopTools::isLoadedObject($order, 'order_id')) {
         JError::raiseError(500, JText::_('COM_JEPROSHOP_THE_ORDER_CANNOT_BE_FOUND_WITHIN_YOUR_DATA_BASE_MESSAGE'));
     }
     $customer = new JeproshopCustomerModelCustomer($order->customer_id);
     $carrier = new JeproshopCarrierModelCarrier($order->carrier_id);
     $products = $this->getProducts($order);
     $currency = new JeproshopCurrencyModelCurrency((int) $order->currency_id);
     // Carrier module call
     $carrier_module_call = null;
     if ($carrier->is_module) {
         /*$module = Module::getInstanceByName($carrier->external_module_name);
         		if (method_exists($module, 'displayInfoByCart'))
         			$carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); */
     }
     // Retrieve addresses information
     $addressInvoice = new JeproshopAddressModelAddress($order->address_invoice_id, $this->context->language->lang_id);
     if (JeproshopTools::isLoadedObject($addressInvoice, 'address_id') && $addressInvoice->state_id) {
         $invoiceState = new JeproshopStateModelState((int) $addressInvoice->state_id);
     }
     if ($order->address_invoice_id == $order->address_delivery_id) {
         $addressDelivery = $addressInvoice;
         if (isset($invoiceState)) {
             $deliveryState = $invoiceState;
         }
     } else {
         $addressDelivery = new JeproshopAddressModelAddress($order->address_delivery_id, $this->context->language->lang_id);
         if (JeproshopTools::isLoadedObject($addressDelivery, 'address_id') && $addressDelivery->state_id) {
             $deliveryState = new JeproshopStateModelState((int) $addressDelivery->state_id);
         }
     }
     $title = JText::_('COM_JEPROSHOP_ORDER_LABEL') . ' ';
     //todo learn how to display
     //$toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->order_id, $order->reference, $customer->firstname, $customer->lastname);
     if (JeproshopShopModelShop::isFeaturePublished()) {
         $shop = new JeproshopShopModelShop((int) $order->shop_id);
         //$this->toolbar_title .= ' - '.sprintf($this->l('Shop: %s'), $shop->name);
     }
     JToolBarHelper::title($title);
     // gets warehouses to ship products, if and only if advanced stock management is activated
     $warehouse_list = null;
     $order_details = $order->getOrderDetailList();
     foreach ($order_details as $order_detail) {
         $product = new JeproshopProductModelProduct($order_detail->product_id);
         if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $product->advanced_stock_management) {
             $warehouses = JeproshopWarehouseModelWarehouse::getWarehousesByProductId($order_detail->product_id, $order_detail->product_attribute_id);
             foreach ($warehouses as $warehouse) {
                 if (!isset($warehouse_list[$warehouse->warehouse_id])) {
                     $warehouse_list[$warehouse->warehouse_id] = $warehouse;
                 }
             }
         }
     }
     $payment_methods = array();
     /*foreach (PaymentModule::getInstalledPaymentModules() as $payment)
     		{
     			$module = Module::getInstanceByName($payment['name']);
     			if (Validate::isLoadedObject($module) && $module->active)
     				$payment_methods[] = $module->displayName;
     		}*/
     // display warning if there are products out of stock
     $display_out_of_stock_warning = false;
     $current_order_status = $order->getCurrentOrderStatus();
     if (JeproshopSettingModelSetting::getValue('stock_management') && (!JeproshopTools::isLoadedObject($current_order_status, 'order_id') || $current_order_status->delivery != 1 && $current_order_status->shipped != 1)) {
         $display_out_of_stock_warning = true;
     }
     // products current stock (from stock_available)
     foreach ($products as &$product) {
         $product->current_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, $product->product_attribute_id, $product->shop_id);
         $resume = JeproshopOrderSlipModelOrderSlip::getProductSlipResume($product->order_detail_id);
         $product->quantity_refundable = $product->product_quantity - $resume->product_quantity;
         $product->amount_refundable = $product->total_price_tax_incl - $resume->amount_tax_incl;
         $product->amount_refund = JeproshopTools::displayPrice($resume->amount_tax_incl, $currency);
         $product->refund_history = JeproshopOrderSlipModelOrderSlip::getProductSlipDetail($product->order_detail_id);
         $product->return_history = JeproshopOrderReturnModelOrderReturn::getProductReturnDetail($product->order_detail_id);
         // if the current stock requires a warning
         if ($product->current_stock == 0 && $display_out_of_stock_warning) {
             JError::raiseWarning(500, JText::_('COM_JEPROSHOP_THIS_PRODUCT_IS_OUT_OF_STOCK_LABEL') . ' : ' . $product->product_name);
         }
         if ($product->warehouse_id != 0) {
             $warehouse = new JeproshopWarehouseModelWarehouse((int) $product->warehouse_id);
             $product->warehouse_name = $warehouse->name;
         } else {
             $product->warehouse_name = '--';
         }
     }
     //$gender = new Gender((int)$customer->id_gender, $this->context->language->id);
     $history = $order->getHistory($this->context->language->lang_id);
     foreach ($history as &$order_state) {
         $order_state->text_color = JeproshopTools::getBrightness($order_state->color) < 128 ? 'white' : 'black';
     }
     $this->setLayout('view');
     $this->assignRef('order', $order);
     $cart = new JeproshopCartModelCart($order->cart_id);
     $this->assignRef('cart', $cart);
     $this->assignRef('customer', $customer);
     $customer_addresses = $customer->getAddresses($this->context->language->lang_id);
     $this->assignRef('customer_addresses', $customer_addresses);
     $this->assignRef('delivery_address', $addressDelivery);
     $this->assignRef('deliveryState', isset($deliveryState) ? $deliveryState : null);
     $this->assignRef('invoice_address', $addressInvoice);
     $this->assignRef('invoiceState', isset($invoiceState) ? $invoiceState : null);
     $customerStats = $customer->getStats();
     $this->assignRef('customerStats', $customerStats);
     $this->assignRef('products', $products);
     $discounts = $order->getCartRules();
     $this->assignRef('discounts', $discounts);
     $orderTotalPaid = $order->getOrdersTotalPaid();
     $this->assignRef('orders_total_paid_tax_incl', $orderTotalPaid);
     // Get the sum of total_paid_tax_incl of the order with similar reference
     $totalPaid = $order->getTotalPaid();
     $this->assignRef('total_paid', $totalPaid);
     $returns = JeproshopOrderReturnModelOrderReturn::getOrdersReturn($order->customer_id, $order->order_id);
     $this->assignRef('returns', $returns);
     $customerThreads = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages($order->customer_id);
     $this->assignRef('customer_thread_message', $customerThreads);
     $orderMessages = JeproshopOrderMessageModelOrderMessage::getOrderMessages($order->lang_id);
     $this->assignRef('order_messages', $orderMessages);
     $messages = JeproshopMessageModelMessage::getMessagesByOrderId($order->order_id, true);
     $this->assignRef('messages', $messages);
     $carrier = new JeproshopCarrierModelCarrier($order->carrier_id);
     $this->assignRef('carrier', $carrier);
     $this->assignRef('history', $history);
     $statues = JeproshopOrderStatusModelOrderStatus::getOrderStatus($this->context->language->lang_id);
     $this->assignRef('order_statues', $statues);
     $this->assignRef('warehouse_list', $warehouse_list);
     $sources = JeproshopConnectionSourceModelConnectionSource::getOrderSources($order->order_id);
     $this->assignRef('sources', $sources);
     $orderStatus = $order->getCurrentOrderStatus();
     $this->assignRef('current_status', $orderStatus);
     $this->assignRef('currency', new JeproshopCurrencyModelCurrency($order->currency_id));
     $currencies = JeproshopCurrencyModelCurrency::getCurrenciesByShopId($order->shop_id);
     $this->assignRef('currencies', $currencies);
     $previousOrder = $order->getPreviousOrderId();
     $this->assignRef('previousOrder', $previousOrder);
     $nextOrder = $order->getNextOrderId();
     $this->assignRef('nextOrder', $nextOrder);
     //$this->assignRef('current_index', self::$currentIndex);
     $this->assignRef('carrier_module_call', $carrier_module_call);
     $this->assignRef('iso_code_lang', $this->context->language->iso_code);
     $this->assignRef('lang_id', $this->context->language->lang_id);
     $can_edit = true;
     $this->assignRef('can_edit', $can_edit);
     //($this->tabAccess['edit'] == 1));
     $this->assignRef('current_id_lang', $this->context->language->lang_id);
     $invoiceCollection = $order->getInvoicesCollection();
     $this->assignRef('invoices_collection', $invoiceCollection);
     $unPaid = $order->getNotPaidInvoicesCollection();
     $this->assignRef('not_paid_invoices_collection', $unPaid);
     $this->assignRef('payment_methods', $payment_methods);
     $invoiceAllowed = JeproshopSettingModelSetting::getValue('invoice_allowed');
     $this->assignRef('invoice_management_active', $invoiceAllowed);
     $display_warehouse = (int) JeproshopSettingModelSetting::getValue('advanced_stock_management');
     $this->assignRef('display_warehouse', $display_warehouse);
     $stockManagement = JeproshopSettingModelSetting::getValue('stock_management');
     $this->assignRef('stock_management', $stockManagement);
     /*$this->assignRef('HOOK_CONTENT_ORDER', Hook::exec('displayAdminOrderContentOrder', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				),
     		$this->assignRef('HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				),
     		$this->assignRef('HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				
     		$this->assignRef('HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array(
     		$this->assignRef('order' => $order,
     		$this->assignRef('products' => $products,
     		$this->assignRef('customer' => $customer) */
     $this->addToolBar();
     $this->sideBar = JHtmlSideBar::render();
     parent::display($tpl);
 }
Esempio n. 9
0
 public function renderView($tpl = null)
 {
     if (!$this->loadObject(true)) {
         return;
     }
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $customer = new JeproshopCustomerModelCustomer($this->cart->customer_id);
     $currency = new JeproshopCurrencyModelCurrency($this->cart->currency_id);
     $this->context->cart = $this->cart;
     $this->context->currency = $currency;
     $this->context->customer = $customer;
     //$this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->cart_id);
     $products = $this->cart->getProducts();
     $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas((int) $this->cart->cart_id);
     JeproshopProductModelProduct::addCustomizationPrice($products, $customized_datas);
     $summary = $this->cart->getSummaryDetails();
     /* Display order information */
     $order_id = (int) JeproshopOrderModelOrder::getOrderIdByCartId($this->cart->cart_id);
     $order = new JeproshopOrderModelOrder($order_id);
     if (JeproshopTools::isLoadedObject($order, 'order_id')) {
         $tax_calculation_method = $order->getTaxCalculationMethod();
         $shop_id = (int) $order->shop_id;
     } else {
         $shop_id = (int) $this->cart->shop_id;
         $tax_calculation_method = JeproshopGroupModelGroup::getPriceDisplayMethod(JeproshopGroupModelGroup::getCurrent()->group_id);
     }
     if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) {
         $total_products = $summary->total_products;
         $total_discounts = $summary->total_discounts_tax_exc;
         $total_wrapping = $summary->total_wrapping_tax_exc;
         $total_price = $summary->total_price_without_tax;
         $total_shipping = $summary->total_shipping_tax_exc;
     } else {
         $total_products = $summary->total_products_wt;
         $total_discounts = $summary->total_discounts;
         $total_wrapping = $summary->total_wrapping;
         $total_price = $summary->total_price;
         $total_shipping = $summary->total_shipping;
     }
     foreach ($products as $k => &$product) {
         if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) {
             $product->product_price = $product->price;
             $product->product_total = $product->total;
         } else {
             $product->product_price = $product->price_wt;
             $product->product_total = $product->total_wt;
         }
         $image = array();
         $db = JFactory::getDBO();
         if (isset($product->product_attribute_id) && (int) $product->product_attribute_id) {
             $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_product_attribute_image') . " WHERE product_attribute_id = " . (int) $product->product_attribute_id;
             $db->setQuery($query);
             $image = $db->loadObject();
         }
         if (!isset($image->image_id)) {
             $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_image') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product->product_id . " AND cover = 1 ";
             $db->setQuery($query);
             $image = $db->loadObject();
         }
         $product_obj = new JeproshopProductModelProduct($product->product_id);
         $product->qty_in_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, isset($product->product_attribute_id) ? $product->product_attribute_id : null, (int) $shop_id);
         $image_product = new JeproshopImageModelImage($image->image_id);
         $product->image = isset($image->image_id) ? JeproshopImageManager::thumbnail(COM_JEPROSHOP_IMAGE_DIR . 'products/' . $image_product->getExistingImagePath() . '.jpg', 'product_mini_' . (int) $product->product_id . (isset($product->product_attribute_id) ? '_' . (int) $product->product_attribute_id : '') . '.jpg', 45, 'jpg') : '--';
     }
     /*$helper = new HelperKpi();
       $helper->id = 'box-kpi-cart';
       $helper->icon = 'icon-shopping-cart';
       $helper->color = 'color1';
       $helper->title = $this->l('Total Cart', null, null, false);
       $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id);
       $helper->value = Tools::displayPrice($total_price, $currency);
       $kpi = $helper->generate(); */
     //$this->assignRef('kpi', $kpi);
     $this->assignRef('products', $products);
     $discounts = $this->cart->getCartRules();
     $this->assignRef('discounts', $discounts);
     $this->assignRef('order', $order);
     $this->assignRef('currency', $currency);
     $this->assignRef('customer', $customer);
     $customerStats = $customer->getStats();
     $this->assignRef('customer_stats', $customerStats);
     $this->assignRef('total_products', $total_products);
     $this->assignRef('total_discounts', $total_discounts);
     $this->assignRef('total_wrapping', $total_wrapping);
     $this->assignRef('total_price', $total_price);
     $this->assignRef('total_shipping', $total_shipping);
     $this->assignRef('customized_datas', $customized_datas);
     if ($this->getLayout() != 'modal') {
         $this->addToolBar();
         $this->sideBar = JHtmlSidebar::render();
     }
     parent::display($tpl);
 }
Esempio n. 10
0
 private function initQuantitiesForm()
 {
     if (!$this->context->controller->default_form_language) {
         $this->languages = $this->context->controller->getLanguages();
     }
     if ($this->product->product_id) {
         if ($this->product_exists_in_shop) {
             //Get all product_attribute_id
             $attributes = $this->product->getAttributesResume($this->context->language->lang_id);
             if (empty($attributes)) {
                 $attributes[] = new JObject();
                 $attributes[0]->set('product_attribute_id', 0);
                 $attributes[0]->set('attribute_designation', '');
             }
             /** get available quantities **/
             $available_quantity = array();
             $product_designation = array();
             foreach ($attributes as $attribute) {
                 $product_attribute_id = is_object($attribute) ? $attribute->product_attribute_id : $attribute['product_attribute_id'];
                 $attribute_designation = is_object($attribute) ? $attribute->attribute_designation : $attribute['attribute_designation'];
                 // Get available quantity for the current product attribute in the current shop
                 $available_quantity[$product_attribute_id] = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct((int) $this->product->product_id, $product_attribute_id);
                 // Get all product designation
                 $product_designation[$product_attribute_id] = rtrim($this->product->name[$this->context->language->lang_id] . ' - ' . $attribute_designation, ' - ');
             }
             $show_quantities = true;
             $shop_context = JeproshopShopModelShop::getShopContext();
             $shop_group = new JeproshopShopGroupModelShopGroup((int) JeproshopShopModelShop::getContextShopGroupID());
             // if we are in all shops context, it's not possible to manage quantities at this level
             if (JeproshopShopModelShop::isFeaturePublished() && $shop_context == JeproshopShopModelShop::CONTEXT_ALL) {
                 $show_quantities = false;
                 // if we are in group shop context
             } elseif (JeproshopShopModelShop::isFeaturePublished() && $shop_context == JeproshopShopModelShop::CONTEXT_GROUP) {
                 // if quantities are not shared between shops of the group, it's not possible to manage them at group level
                 if (!$shop_group->share_stock) {
                     $show_quantities = false;
                 }
             } else {
                 // if we are in shop context
                 // if quantities are shared between shops of the group, it's not possible to manage them for a given shop
                 if ($shop_group->share_stock) {
                     $show_quantities = false;
                 }
             }
             $stock_management = JeproshopSettingModelSetting::getValue('stock_management');
             $this->assignRef('stock_management', $stock_management);
             $has_attribute = $this->product->hasAttributes();
             $this->assignRef('has_attribute', $has_attribute);
             // Check if product has combination, to display the available date only for the product or for each combination
             $db = JFactory::getDBO();
             if (JeproshopCombinationModelCombination::isFeaturePublished()) {
                 $query = "SELECT COUNT(product_id) FROM " . $db->quoteName('#__jeproshop_product_attribute') . " WHERE ";
                 $query .= " product_id = " . (int) $this->product->product_id;
                 $db->setQuery($query);
                 $countAttributes = (int) $db->loadResult();
             } else {
                 $countAttributes = false;
             }
             $this->assignRef('count_attributes', $countAttributes);
             // if advanced stock management is active, checks associations
             $advanced_stock_management_warning = false;
             if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $this->product->advanced_stock_management) {
                 $product_attributes = JeproshopProductModelProduct::getProductAttributesIds($this->product->product_id);
                 $warehouses = array();
                 if (!$product_attributes) {
                     $warehouses[] = JeproshopWarehouseModelWarehouse::getProductWarehouseList($this->product->product_id, 0);
                 }
                 foreach ($product_attributes as $product_attribute) {
                     $ws = JeproshopWarehouseModelWarehouse::getProductWarehouseList($this->product->product_id, $product_attribute->product_attribute_id);
                     if ($ws) {
                         $warehouses[] = $ws;
                     }
                 }
                 $warehouses = JeproshopTools::arrayUnique($warehouses);
                 if (empty($warehouses)) {
                     $advanced_stock_management_warning = true;
                 }
             }
             if ($advanced_stock_management_warning) {
                 JError::raiseWarning(500, JText::_('If you wish to use the advanced stock management, you must:'));
                 JError::raiseWarning(500, '- ' . JText::_('associate your products with warehouses.'));
                 JError::raiseWarning(500, '- ' . JText::_('associate your warehouses with carriers.'));
                 JError::raiseWarning(500, '- ' . JText::_('associate your warehouses with the appropriate shops.'));
             }
             $pack_quantity = null;
             // if product is a pack
             if (JeproshopProductPack::isPack($this->product->product_id)) {
                 $items = JeproshopProductPack::getItems((int) $this->product->product_id, JeproshopSettingModelSetting::getValue('default_lang'));
                 // gets an array of quantities (quantity for the product / quantity in pack)
                 $pack_quantities = array();
                 foreach ($items as $item) {
                     if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock)) {
                         $pack_id_product_attribute = JeproshopProductModelProduct::getDefaultAttribute($item->product_id, 1);
                         $pack_quantities[] = JeproshopProductModelProduct::getQuantity($item->id, $pack_id_product_attribute) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
                     }
                 }
                 // gets the minimum
                 if (count($pack_quantities)) {
                     $pack_quantity = $pack_quantities[0];
                     foreach ($pack_quantities as $value) {
                         if ($pack_quantity > $value) {
                             $pack_quantity = $value;
                         }
                     }
                 }
                 if (!JeproshopWarehouseModelWarehouse::getPackWarehouses((int) $this->product->product_id)) {
                     $this->displayWarning($this->l('You must have a common warehouse between this pack and its product.'));
                 }
             }
             $this->assignRef('attributes', $attributes);
             $this->assignRef('available_quantity', $available_quantity);
             $this->assignRef('pack_quantity', $pack_quantity);
             $stock_management_active = JeproshopSettingModelSetting::getValue('advanced_stock_management');
             $this->assignRef('stock_management_active', $stock_management_active);
             $this->assignRef('product_designation', $product_designation);
             $this->assignRef('show_quantities', $show_quantities);
             $order_out_of_stock = JeproshopSettingModelSetting::getValue('allow_out_of_stock_ordering');
             $this->assignRef('order_out_of_stock', $order_out_of_stock);
             /*'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'),
                       'token' => $this->token,
                       'languages' => $this->_languages,
                       'id_lang' => $this->context->language->id
               ));*/
         } else {
             JError::raiseWarning(500, JText::_('You must save the product in this shop before managing quantities.'));
         }
     } else {
         JError::raiseWarning(500, JText::_('You must save this product before managing quantities.'));
     }
 }
Esempio n. 11
0
 /**
  * It is NOT possible to delete a product if there are currently:
  * - physical stock for this product
  * - supply order(s) for this product
  **/
 public function delete()
 {
     $db = JFactory::getDBO();
     if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $this->advanced_stock_management) {
         $stockManager = JeproshopStockManagerFactory::getManager();
         $physicalQuantity = $stockManager->getProductPhysicalQuantities($this->product_id, 0);
         $realQuantity = $stockManager->getProductRealQuantities($this->product_id, 0);
         if ($physicalQuantity > 0) {
             return false;
         }
         if ($realQuantity > $physicalQuantity) {
             return false;
         }
     }
     $this->clearCache();
     $result = true;
     if (JeproshopShopModelShop::isTableAssociated('product')) {
         $shopListIds = JeproshopShopModelShop::getContextShopGroupID();
         if (count($this->shop_list_id) > 0) {
             $shopListIds = $this->shop_list_id;
         }
         if (!is_array($shopListIds)) {
             $shopListIds = array($shopListIds);
         }
         $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_shop') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_id . " AND " . $db->quoteName('shop_id') . " IN(" . implode($shopListIds) . ")";
         $db->setQuery($query);
         $result &= $db->query();
     }
     $hasMultiShopEntries = $this->hasMultishopEntries();
     if ($result && !$hasMultiShopEntries) {
         $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product') . " WHERE " . $db->quoteName('product_id') . " = " . $this->product_id;
         $db->setQuery($query);
         $result &= $db->query();
     }
     if (!$result) {
         return false;
     }
     $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_lang') . " WHERE " . $db->quoteName('product_id') . " = " . $this->product_id;
     $db->setQuery($query);
     $result &= $db->query();
     JeproshopStockAvailableModelStockAvailable::removeProductFromStockAvailable($this->product_id);
     $result &= $this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts();
     if ($this->hasMultiShopEntries()) {
         return true;
     }
     if (!$result || !JeproshopGroupReductionModelGroupReduction::deleteProductReduction($this->product_id) || !$this->deleteCategories(true) || !$this->deleteProductFeatures() || !$this->deleteTags() || !$this->deleteCartProducts() || !$this->deleteAttributesImpacts() || !$this->deleteAttachments(false) || !$this->deleteCustomization() || !JeproshopSpecificPriceModelSpecificPrice::deleteByProductId((int) $this->product_id) || !$this->deletePack() || !$this->deleteProductSale() || !$this->deleteSearchIndexes() || !$this->deleteAccessories() || !$this->deleteFromAccessories() || !$this->deleteFromSupplier() || !$this->deleteDownload() || !$this->deleteFromCartRules()) {
         return false;
     }
     return true;
 }