Esempio n. 1
0
 static function add_order_enrols_vm2($order_id, $user_id)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser($user_id);
     $username = $user->username;
     $email = $user->email;
     /* Update user profile in Moodle  with VM data, if necessary */
     JoomdleHelperContent::call_method('create_joomdle_user', $username);
     $order_id = $db->Quote($order_id);
     $query = 'SELECT *' . ' FROM #__virtuemart_order_items' . ' WHERE virtuemart_order_id =';
     $query .= "{$order_id}";
     $db->setQuery($query);
     $items = $db->loadObjectList();
     if ($db->getErrorNum()) {
         JError::raiseWarning(500, $db->stderr());
     }
     /* No items in this order */
     if (count($items) == 0) {
         return;
     }
     $params = JComponentHelper::getParams('com_joomdle');
     $buy_for_children = $params->get('buy_for_children');
     $courses_category = $params->get('courses_category');
     foreach ($items as $item) {
         /* Only process product in Courses category */
         $product_id = $item->virtuemart_product_id;
         $order_item_id = $item->virtuemart_order_item_id;
         $query = "SELECT virtuemart_category_id" . " FROM #__virtuemart_product_categories" . " WHERE virtuemart_product_id=" . $db->Quote($product_id);
         $db->setQuery($query);
         $cats = $db->loadAssocList();
         $cats_array = array();
         foreach ($cats as $cat) {
             $cats_array[] = $cat['virtuemart_category_id'];
         }
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->stderr());
         }
         /* If it is a course */
         if (in_array($courses_category, $cats_array)) {
             $sku = $item->order_item_sku;
             if ($buy_for_children) {
                 if (strncmp($item->order_item_sku, 'bundle_', 7) == 0) {
                     //bundle
                     JoomdleHelperParents::purchase_bundle($username, $sku, $item->product_quantity);
                 } else {
                     JoomdleHelperParents::purchase_course($username, $sku, $item->product_quantity);
                 }
             } else {
                 if (strncmp($item->order_item_sku, 'bundle_', 7) == 0) {
                     //bundle
                     JoomdleHelperShop::enrol_bundle($username, $sku);
                 } else {
                     //course
                     JoomdleHelperContent::enrolUser($username, $sku);
                     /* Send confirmation email */
                     JoomdleHelperShop::send_confirmation_email($email, $sku);
                 }
             }
         }
     }
 }