/** * This function will run all applicable cron on recurring entity * @return array|bool */ public function runCron($cron = 'All') { $recurring_order = array(); $return_value = array(); module_load_include('inc', 'commerce_recurring', 'commerce_recurring.rules'); module_load_include('inc', 'mp_order', 'mp_order.rules'); module_load_include('inc', 'mp_upgrade', 'mp_upgrade.rules'); // Create Order Based on recurring entity due date $recurring_entity = $this->getEntity(); if (in_array($cron, array('All', 'create_order'))) { $due_entities = commerce_recurring_rules_get_due_items(); $entity_array = array(); foreach ($due_entities['commerce_recurring_entities'] as $entity_key => $entity) { $entity_array[$entity->id] = $entity; } if (array_key_exists($this->getId(), $entity_array)) { // Passing recurring entity and create order $recurring_order = commerce_recurring_rules_generate_order_from_recurring($recurring_entity); if (!empty($recurring_order) && isset($recurring_order['commerce_order'])) { $return_value['commerce_order'] = $recurring_order['commerce_order']; global $entities; $order = new CommerceOrder($recurring_order['commerce_order']->order_id); $order->reload(); $entities['commerce_order'][$order->getId()] = $order; mp_order_update_order_with_store_credit($recurring_order['commerce_order']); mp_subscription_rules_action_update_recurring_billing_due_date($recurring_order['commerce_order']); // Attaching order with recurring entity } } } //Payment and Order Status of Above Created Order if (in_array($cron, array('All', 'pending_payment'))) { $orders = $this->getCommerceRecurringOrderValues(); foreach ($orders as $associated_oder) { $order = new CommerceOrder($associated_oder['target_id']); if ($order->getStatusValues() == 'recurring_pending') { $card_response = commerce_cardonfile_rules_action_order_select_default_card($order->getEntity()); $total = $order->getFieldItems('commerce_order_total'); $charge_response = commerce_cardonfile_rules_action_order_charge_card($order->getEntity(), $total[0], $card_response['select_card_response']); $return_value['charge_response'] = $charge_response; } } } //Upgrade Yearly Plan if (in_array($cron, array('All', 'upgrade'))) { $recurring_entities = mp_upgrade_rules_action_get_upgraded_items(); if (array_key_exists($this->getId(), $recurring_entities['commerce_recurring_entities'])) { mp_upgrade_rules_action_upgrade_recurring_license($this->getEntity()); } } return new Response(TRUE, $return_value, NULL); }