Ejemplo n.º 1
0
 /**
  * For a given product id, sets if stock available depends on stock
  *
  * @param int $product_id
  * @param bool|int $depends_on_stock Optional : true by default
  * @param int $shop_id Optional : gets context by default
  * @param int $product_attribute_id
  * @return bool
  */
 public static function setProductDependsOnStock($product_id, $depends_on_stock = true, $shop_id = null, $product_attribute_id = 0)
 {
     if (!JeproshopTools::isUnsignedInt($product_id)) {
         return false;
     }
     $existing_id = JeproshopStockAvailableModelStockAvailable::getStockAvailableIdByProductId((int) $product_id, (int) $product_attribute_id, $shop_id);
     $db = JFactory::getDBO();
     if ($existing_id > 0) {
         $query = "UPDATE " . $db->quoteName('#__jeproshop_stock_available') . " SET " . $db->quoteName('depends_on_stock') . " = ";
         $query .= (int) $depends_on_stock . " WHERE " . $db->quoteName('stock_available_id') . " = " . (int) $existing_id;
         $db->setQuery($query);
         $db->query();
     } else {
         $context = JeproshopContext::getContext();
         $groupOk = false;
         if ($shop_id === null) {
             if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) {
                 $shop_group = JeproshopShopModelShop::getContextShopGroup();
             } else {
                 $shop_group = $context->shop->getShopGroup();
                 $shop_id = $context->shop->shop_id;
             }
         } else {
             $shop = new JeproshopShopModelShop($shop_id);
             $shop_group = $shop->getShopGroup();
         }
         if ($shop_group->share_stock) {
             $shop_group_id = $shop_group->shop_group_id;
             $shop_id = 0;
             $groupOk = true;
         } else {
             $shop_group_id = 0;
         }
         $query = "INSERT INTO " . $db->quoteName('#__jeproshop_stock_available') . "(" . $db->quoteName('depends_on_stock') . ", ";
         $query .= $db->quoteName('product_id') . ", " . $db->quoteName('product_attribute_id') . ", " . $db->quoteName('shop_id');
         $query .= ", " . $db->quoteName('shop_group_id') . ") VALUES(" . (int) $depends_on_stock . ", " . (int) $product_id . ", ";
         $query .= (int) $product_attribute_id . ", " . (int) $shop_id . ", " . (int) $shop_group_id . ")";
         $db->setQuery($query);
         $db->query();
     }
     // depends on stock.. hence synchronizes
     if ($depends_on_stock) {
         JeproshopStockAvailableModelStockAvailable::synchronize($product_id);
     }
 }
Ejemplo n.º 2
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');
     }
 }
Ejemplo n.º 3
0
 /**
  * Post treatment for warehouses
  */
 public function processWarehouses()
 {
     $app = JFactory::getApplication();
     $product = new JeproshopProductModelProduct((int) $app->input->get('product_id'));
     if ((int) $app->input->get('warehouse_loaded') === 1 && JeproshopTools::isLoadedObject($product, 'product_id')) {
         // Get all id_product_attribute
         $warehouse_attributes = $product->getAttributesResume($this->context->language->lang_id);
         if (empty($warehouse_attributes)) {
             $attribute = new JObject();
             $attribute->set('product_attribute_id', 0);
             $attribute->set('attribute_designation', '');
             $warehouse_attributes[] = $attribute;
         }
         // Get all available warehouses
         $warehouses = JeproshopWarehouseModelWarehouse::getWarehouses(true);
         // Get already associated warehouses
         $associated_warehouses_collection = JeproshopWarehouseProductLocationModelWarehouseProductLocation::getCollection($product->product_id);
         $elements_to_manage = array();
         // get form information
         foreach ($warehouse_attributes as $attribute) {
             foreach ($warehouses as $warehouse) {
                 $key = $warehouse->warehouse_id . '_' . $product->product_id . '_' . $attribute->product_attribute_id;
                 // get elements to manage
                 if ($app->input->get('check_warehouse_' . $key)) {
                     $location = $app->input->get('location_warehouse_' . $key, '');
                     $elements_to_manage[$key] = $location;
                 }
             }
         }
         // Delete entry if necessary
         foreach ($associated_warehouses_collection as $awc) {
             if (!array_key_exists($awc->warehouse_id . '_' . $awc->product_id . '_' . $awc->product_attribute_id, $elements_to_manage)) {
                 $awc->delete();
             }
         }
         // Manage locations
         foreach ($elements_to_manage as $key => $location) {
             $params = explode('_', $key);
             $wpl_id = (int) JeproshopWarehouseProductLocationModelWarehouseProductLocation::getIdByProductAndWarehouse((int) $params[1], (int) $params[2], (int) $params[0]);
             if (empty($wpl_id)) {
                 //create new record
                 $warehouse_location_entity = new JeproshopWarehouseProductLocationModelWarehouseProductLocation();
                 $warehouse_location_entity->product_id = (int) $params[1];
                 $warehouse_location_entity->product_attribute_id = (int) $params[2];
                 $warehouse_location_entity->warehouse_id = (int) $params[0];
                 $warehouse_location_entity->location = JFactory::getDBO()->query($location);
                 $warehouse_location_entity->save();
             } else {
                 $warehouse_location_entity = new WarehouseProductLocation((int) $wpl_id);
                 $location = $location;
                 if ($location != $warehouse_location_entity->location) {
                     $warehouse_location_entity->location = $location;
                     $warehouse_location_entity->update();
                 }
             }
         }
         JeproshopStockAvailableModelStockAvailable::synchronize((int) $product->product_id);
     }
 }