News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

stock does not update

Started by amanda mc donald, March 27, 2012, 21:43:38 PM

Previous topic - Next topic

amanda mc donald

Hi

After an order is placed (VM2) and the order is confirmed the stock is still the same as before order was placed.
Why does the stock not update?  (must be whatever it was before order minus the quantity of order)
Is there a setting I'm missing?

Please help
Thank you

John2400

amanda mc donald,

stock control has been a much discussed issue - The isdea to test is to set the product to 1 only and then buy twice.

If you see a few issues , then you might like to update to newer versions - there have been some heavily discussed hacks in posts but chnging the core
might not be the best way.

* here are some updated versions http://dev.virtuemart.net/projects/virtuemart/files    - being tested- back up your site and then upgrade to one version - if you like. or wait for the stable version -

amanda mc donald


marcel63

Hi there,

We got the same problem and solved it. We use standard version 2.02 with joomla 2.5.4. The problem is that when you try to use the 2.03X versions is that your templates do not work anymore and you get all kind of new faults. You have to modify following functions in administrator/components/com_virtuemart/models/orders.php and then the stock is updated correctly whatever you do. You can change from pending to shipped and from shipped to pending again etc. Even when you delete the order the update is correct. We did a lot of testing with more than one product in the order and it works (note that the status of order-items inside the order is not updated in this solution but in VM 2.02 this status is never changed in the database as far as I could see.......):

   public function updateSingleItem($virtuemart_order_item_id, &$orderdata,$oldOrderStatus)
   {

      // Update order item status
      if(empty($virtuemart_order_item_id)){


            $q = 'SELECT virtuemart_order_item_id
                  FROM #__virtuemart_order_items
                  WHERE virtuemart_order_id="'.(int)$orderdata->virtuemart_order_id.'"';
            $db = JFactory::getDBO();
            $db->setQuery($q);
            $virtuemart_order_item_ids = $db->loadResultArray();

      }else {
         if(!is_array($virtuemart_order_item_id)) $virtuemart_order_item_ids = array($virtuemart_order_item_id);
      }
      
                //aiming to set order item status to order status, did not work no update of database, thus not necessary yet $orderTable =  $this->getTable('orders');
                //aiming to set order item status to order status, did not work no update of database, thus not necessary yet $orderTable->load($orderdata->virtuemart_order_id);
                //vmdebug('ordertable',$orderTable);
   
      foreach($virtuemart_order_item_ids as $id){          
         $table = $this->getTable('order_items');
         $table->load($id);
         // vmdebug('table',$table);
         //$oldOrderStatus = $table->order_status;
   
//          JPluginHelper::importPlugin('vmcustom');
//          $_dispatcher = JDispatcher::getInstance();
//          $_returnValues = $_dispatcher->trigger('plgVmOnUpdateSingleItem',array($table,&$orderdata));
            
         
               /* Update the order item history */
         //$this->_updateOrderItemHist($id, $order_status, $customer_notified, $comment);
         

                        vmdebug('order status',$orderdata->order_status);
                        vmdebug('old order status',$oldOrderStatus);                     
                       
                        /* aiming to set order item status to order status, did not work no update of database, thus not necessary yet $table->order_status = $orderdata->order_status;
                        $orderTable->bindChecknStore($table,true);      
                        $errors = $orderTable->getErrors();
              foreach($errors as $error){
                 vmdebug('error',$error);
                vmError($error);
              }*/
      
         $this->handleStockAfterStatusChangedPerProduct($orderdata->order_status, $oldOrderStatus, $table,$table->product_quantity);

      }

function removeOrderLineItem($orderLineId,$old_status) {

      $item = $this->getTable('order_items');
      if (!$item->load($orderLineId)) {
         vmError($item->getError());
         return false;
      }
      
      
      vmdebug('orderstatus',$item->order_status);
      $this->handleStockAfterStatusChangedPerProduct('X', $old_status,$item, $item->product_quantity);
      if ($item->delete($orderLineId)) {
         return true;
      }
      else {
         vmError($item->getError());
         return false;
      }
   }

   /**
    * Delete all record ids selected
    *
    * @author Max Milbers
    * @author Patrick Kohl
    * @return boolean True is the delete was successful, false otherwise.
    */
   public function remove($ids) {

      $table = $this->getTable($this->_maintablename);
      

      foreach($ids as $id) {

                       $orderTable =  $this->getTable('orders');
                       $orderTable->load($id);
                       $old_status = $orderTable->order_status;
                       vmdebug('oldstatus',$old_status);                        
         
         // remove order_item and update stock
         $q = "SELECT `virtuemart_order_item_id` FROM `#__virtuemart_order_items`
            WHERE `virtuemart_order_id`=".$id;
                        
         $this->_db->setQuery($q);
         $item_ids = $this->_db->loadResultArray();
         foreach( $item_ids as $item_id ) $this->removeOrderLineItem($item_id,$old_status);

         if (!$table->delete((int)$id)) {
            vmError(get_class( $this ).'::remove '.$id.' '.$table->getError());
            return false;
         }
      }

      return true;
   }


function updateStatusForOneOrder($virtuemart_order_id,$inputOrder,$useTriggers=true){

      vmdebug('updateStatusForOneOrder');
      /* Update the order */
      $data = $this->getTable('orders');
      $data->load($virtuemart_order_id);
      $old_order_status = $data->order_status;
      $data->bind($inputOrder);

      //First we must call the payment, the payment manipulates the result of the order_status
      if($useTriggers){
            if(!class_exists('vmPSPlugin')) require(JPATH_VM_PLUGINS.DS.'vmpsplugin.php');
            // Payment decides what to do when order status is updated
            JPluginHelper::importPlugin('vmpayment');
            $_dispatcher = JDispatcher::getInstance();                                 //Should we add this? $inputOrder
            $_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderPayment',array(&$data,$old_order_status));
            foreach ($_returnValues as $_returnValue) {
               if ($_returnValue === true) {
                  break; // Plugin was successfull
               } elseif ($_returnValue === false) {
                  return false; // Plugin failed
               }
               // Ignore null status and look for the next returnValue
            }

         JPluginHelper::importPlugin('vmshipment');
         $_dispatcher = JDispatcher::getInstance();                                 //Should we add this? $inputOrder
         $_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderShipment',array(&$data,$old_order_status));


         /**
         * If an order gets cancelled, fire a plugin event, perhaps
         * some authorization needs to be voided
         */
         if ($data->order_status == "X") {
            JPluginHelper::importPlugin('vmpayment');                                                         //Should we add this? $inputOrder
            $_dispatcher = JDispatcher::getInstance();$_dispatcher->trigger('plgVmOnCancelPayment',array(&$data,$old_order_status));
         }
      }


      if ($data->store()) {
         $q = 'SELECT virtuemart_order_item_id
                                    FROM #__virtuemart_order_items
                                    WHERE virtuemart_order_id="'.$virtuemart_order_id.'"';
         $db = JFactory::getDBO();
         $db->setQuery($q);
         $order_items = $db->loadObjectList();
         if ($order_items) {
            foreach ($order_items as $order_item) {
               //$this->updateSingleItem($order_item->virtuemart_order_item_id, $data->order_status, $order['comments'] , $virtuemart_order_id, $data->order_pass);
               $this->updateSingleItem($order_item->virtuemart_order_item_id, $data, $old_order_status);
            }
         }

         /* Update the order history */
         $this->_updateOrderHist($virtuemart_order_id, $data->order_status, $inputOrder['customer_notified'], $inputOrder['comments']);

         // When the plugins did not already notified the user, do it here (the normal way)
         //Attention the ! prevents at the moment that an email is sent. But it should used that way.
//          if (!$inputOrder['customer_notified']) {
         $this->notifyCustomer( $data->virtuemart_order_id , $inputOrder );
//          }

         JPluginHelper::importPlugin('vmcoupon');
         $dispatcher = JDispatcher::getInstance();
         $returnValues = $dispatcher->trigger('plgVmCouponUpdateOrderStatus', array($data, $old_order_status));
         if(!empty($returnValues)){
            foreach ($returnValues as $returnValue) {
               if ($returnValue !== null  ) {
                  return $returnValue;
               }
            }
         }
         return true;
      } else {
         return false;
      }
   }


Good luck !

Studio 42

HI,
in virtuemart 2 , you have 3 stock status possibility.
-in stock , normal case
-virtual stock or reserved stock , for eg after order/paid
+not in stock, for eg. shipped
Why reserved/virtual stock?
Because in real, paid products are in stock but have not to be  displayed in the shop for customers.

in BE products you must look in Product Status TAB if

"Booked, ordered products " is updated
the instock only change in last step "shipped"