Skip to main content

Posts

Showing posts from September, 2017

Create batch process on form submit in Drupal 7

Using Drupal batch API we can create batch processes. // form submit. function product_display_submit($form, &$form_state) { $products = $form_state['input']['product_table']; if (!empty($products)) { // Remove empty values. $emptyRemoved = remove_empty($products); // re-index array. $myarray = array_values($emptyRemoved); $progress = 0; // where to start $max = count($myarray); // how many records to process until stop. // Tell Drupal about the batch process. $batch = array( 'operations' => array(), 'finished' => 'product_display_batch_finished', // runs after batch is finished 'title' => t('Deleting products'), 'init_message' => t('Beginning product delete'), 'progress_message' => t('Deleted @current out of @total'), 'error_message' => t('Product deletion failed.'), ); //

How to create custom rules condition in Drupal 7

hook_rules_condition_info() is used to create custom rules conditions. /** * Implements hook_rules_condition_info() */ function custom_rules_rules_condition_info() { return array( 'custom_rules_default_condition_dealer_store' => array( 'label' => t('Dealer store'), 'group' => t('Domains'), 'parameter' => array( 'operator' => array( 'type' => 'text', 'label' => t('Show pricing enabled'), 'options list' => '__custom_rules_dealer_store_operators', 'default value' => '0' ) ) ), ); } /** * Custom hook * Test domain for matching * @param string $operator * @return bool */ function custom_rules_default_condition_dealer_store($operator) { $domain_info = domain_get_domain(); // returns 0 or 1. // 1 means current domain is dealer store.

Mapping of XML feeds conditionally using Feed Importer In Drupal 7

Map XML feeds on some basic conditions without using feeds tamper module First, take a look at an example <images>    <image type="file">https://s3.amazon.com/example1.pdf</image>    <image type="file">https://s3.amazon.com/example3.pdf</image>    <image type="file">https://s3.amazon.com/example2.pdf</image>    <image type="image">https://s3.amazon.com/example.jpg</image> </images> Case 1 : If you want to import only those feeds that has type "image" then your XML Parser settings should be like Images/Image[./@type = 'image'] Case 2 : Import feeds that has not file type then Images/Image[./@type != 'file'] Example 2:   < item > < enclosure url = " http://www.example.com/path-to-image/image1.jpg " type = " image/jpeg " /> < enclosure url = " http://www.example.com/path-to-image/image2.jpg

Display payment method name in Drupal Commerce

To display payment method name from payment machine_name programmatically in Drupal Commerce // Display payment method. $r = explode('|', $commerce_order->data['payment_method']); if (count($r) > 1){ $rule = rules_config_load($r[1]); $payment_method = $rule->label; echo "Payment Method: " . $payment_method ; }