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

Updating Other Child Quantities (product_in_stock) Upon Payment Completion

Started by bmannlta, August 25, 2015, 09:11:36 AM

Previous topic - Next topic

bmannlta

VM 3.0.9, Joomla 3.4.3

I have a scenario where we are using a parent product with 2 child products so that we can support two different types of donations for sponsoring students.  Each student has a parent product and product Child 1 is configured for an annual payment while product Child 2 is configured to take a recurring payment (both through paypal).  We are using the quantity as 1 when student not sponsored and 0 once student is sponsored (stored at each child).  When the user selects one child and sponsors them, we want the system to update product_in_stock for both children.  I have managed to handle the product maintenance side of this by adding additional SQL in the file ../com_virtuemart/models/product.php

$sql = 'update `#__virtuemart_products` set product_in_stock ='. $product_data->product_in_stock . ' where product_parent_id =' . $product_data->product_parent_id . ' and virtuemart_product_id <>' . $product_data->virtuemart_product_id;
                $db2 = JFactory::getDbo();
      $db2->setQuery( $sql );
           $db2->execute();
      $err2 = $db2->getErrorMsg();
      if(!empty($err2)){
         vmWarn('Updating Sibling',$err2);
      }

But I have not been able to figure out how to add similar code when the order is completed.  I have tried adding code in  the function  updateStockInDB in same file , but I am unable to see debug messages as it does not return to the cart after completion.  Update does not occur. This is the code I have at the bottom of that function.

//START - UPDATE QUANTITY OF OTHER CHILDREN
      vmdebug ('updateStockInDB: starting sibling update');
                $sql = 'update `#__virtuemart_products` set product_in_stock ='. $product->product_in_stock . ' where product_parent_id =' . $product->product_parent_id . ' and virtuemart_product_id <>' . $product->virtuemart_product_id;
                vmdebug ($sql);

                $db2 = JFactory::getDbo();
      $db2->setQuery( $sql );
           $db2->execute();
      $err2 = $db2->getErrorMsg();
      if(!empty($err2)){
         vmWarn('Updating Sibling',$err2);
      }
                //END - UPDATE QUANTITY OF OTHER CHILDREN

Any help on the code or alternative ways to accomplish the same would be greatly appreciated.

Studio 42

Hi,
YOu need to add a new paiment(or hack the code of your paiment)
in your new plugin
add only one function
plgVmOnPaymentNotification(){
/*YOUR CODE HERE*/
}

check your plugin is ordered last, in Joomla plugins, then you can check if the paiement was updated in cart.
YOu can see the code in paiment plugin function plgVmOnPaymentNotification, how the statut is set and get, to prevent haking the paiment and your own update.

bmannlta

Thanks for the response.  I get the idea - I'll be blazing new trails for myself with first plugin.  Is there a good reference document/tutorial to help me through the plugin process?  It would be really nice to see some diagrams that show the actors and timing of events.