Example #1
0
/**
 * Override or insert variables into the node templates.
 */
function joost_preprocess_node(&$vars)
{
    switch ($vars['type']) {
        case 'ready_made_':
            foreach ($vars['node']->field_ready_made_ref[LANGUAGE_NONE] as $product_id) {
                $product_ids[] = $product_id['product_id'];
                // dsm($product_id);
                //dsm($product_ids);
            }
            $products = commerce_product_load_multiple($product_ids);
            $product_prices = array();
            foreach ($products as $product_id => $product) {
                $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
                $product_prices[] = $product_wrapper->commerce_price->amount->value();
                $count_prices = count($product_prices);
                // dsm($count_prices);
            }
            sort($product_prices, SORT_NUMERIC);
            $lower = commerce_currency_format(reset($product_prices), 'GBP');
            $upper = commerce_currency_format(end($product_prices), 'GBP');
            $price_range = "{$lower} - {$upper}";
            $price_lower = "{$lower}";
            if ($count_prices == 1) {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_lower;
            } else {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_range;
            }
            break;
    }
}
/**
 * Defines rows for use in payment totals area handlers on Views.
 *
 * The payment totals area handler totals the amount of payments received by
 * currency for all the payment transactions in a View. The array of totals are
 * is used to build a table containing rows for each of the totals and/or the
 * remaining balance of the order by default. Other modules may use this hook to
 * add additional rows to the table.
 *
 * @param $totals
 *   An array of payment totals whose keys are currency codes and values are the
 *   total amount paid in each currency.
 * @param $order
 *   If available, the order object to which the payments apply.
 *
 * @return
 *   An array of table row data as expected by theme_table(). Row arrays may
 *   contain an additional weight key with the value being an integer used to
 *   sort the rows prior to display.
 *
 * @see commerce_payment_commerce_payment_totals_rows()
 * @see commerce_payment_commerce_payment_totals_row_info()
 * @see theme_table()
 */
function hook_commerce_payment_totals_row_info($totals, $order)
{
    $rows = array();
    if (count($totals) <= 1) {
        // Add a row for the remaining balance on the order.
        if ($order) {
            $balance = commerce_payment_order_balance($order, $totals);
            $rows[] = array('data' => array(array('data' => t('Order balance'), 'class' => array('label')), array('data' => commerce_currency_format($balance['amount'], $balance['currency_code']), 'class' => array('balance'))), 'class' => array('order-balance'), 'weight' => 10);
        }
    }
    return $rows;
}
 function testPaymentMethodViewsDataExport()
 {
     $this->createOrders(10, TRUE);
     $transactions = 0;
     $revenue = 0;
     foreach ($this->orders as $order) {
         $transactions++;
         $revenue += $order['commerce_transaction']->amount;
     }
     $rendered = $this->getRenderedExport('commerce_reports_payment_methods');
     $this->assertCsvHeaders('"Payment method","Transactions","Revenue"', $rendered[0]);
     array_shift($rendered);
     $this->assertEqual(count($rendered), 1, t('The amount of payment methods (%reported) that is reported (%generated) upon is correct.', array('%reported' => count($rendered), '%generated' => 1)));
     // Verify data
     $data = reset($rendered);
     $data = str_getcsv($data);
     $this->assertEqual("Example payment", $data[0]);
     $this->assertEqual($transactions, $data[1]);
     $this->assertEqual(commerce_currency_format($revenue, commerce_default_currency()), $data[2]);
 }
Example #4
0
/**
 * Find the prices for a given legal status based on the products.
 */
function devis_get_prices_from_legal_status($legal_status)
{
    $product_key = trois_devis_get_product_from_status($legal_status);
    $products = commerce_product_load_multiple(array(), array('type' => 'devis'));
    $keep = $temp = $order = array();
    foreach ($products as $key => $product) {
        if (substr($product->sku, 0, -5) == $product_key) {
            $price = commerce_product_calculate_sell_price($product);
            $price_display = commerce_currency_format($price['amount'], $price['currency_code'], $product);
            $temp[$key] = $price_display;
            $order[$key] = $price['amount'];
        }
    }
    asort($order, SORT_NUMERIC);
    foreach ($order as $key => $price) {
        $keep[$key] = $temp[$key];
    }
    return $keep;
}
Example #5
0
    <tr class="pane-data even even">
      <td class="pane-data-full">
      <div class="field field-name-commerce-customer-address field-type-addressfield field-label-hidden">
        <div class="field-items">
          <div class="field-item even">
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('Order Number: @order_number', array('@order_number' => $order->order_number));
?>
</div>
            </div>
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('API Provider: @api_provider', array('@api_provider' => $api_provider));
?>
</div>
            </div>
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('Amount: @amount', array('@amount' => commerce_currency_format($order->commerce_order_total[LANGUAGE_NONE][0]['amount'], $order->commerce_order_total[LANGUAGE_NONE][0]['currency_code'])));
?>
</div>
            </div>
          </div>
        </div>
      </div>
      </td>
    </tr>
  </tbody>
</table>
global $user;
$quantity = 0;
$total = '$0.00';
$order = commerce_cart_order_load($user->uid);
if ($order) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $line_items = $wrapper->commerce_line_items;
    $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    $order_total = commerce_line_items_total($line_items);
}
?>
  <a href="<?php 
print url('cart');
?>
">
    <span>
      <i class="fa fa-shopping-cart"></i>
    </span> 
    <?php 
print $quantity;
?>
 item(s) - 
    <?php 
if ($order) {
    print commerce_currency_format($order_total['amount'], $order_total['currency_code']);
} else {
    print $total;
}
?>
  </a>
<?php

/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
$node = entity_load_single('node', $output);
$wrapper = entity_metadata_wrapper('node', $node);
$commerce_price_data = $wrapper->field_product_store[0]->commerce_price->value();
$commerce_price = commerce_currency_format($commerce_price_data['amount'], $commerce_price_data['currency_code']);
print $commerce_price;
Example #8
0
function _condenast_get_order_price_by_components($view)
{
    // First look for an order_id argument.
    foreach ($view->argument as $name => $argument) {
        if ($argument instanceof commerce_order_handler_argument_order_order_id) {
            // If it is single value...
            if (count($argument->value) == 1) {
                // Load the order.
                if ($order = commerce_order_load(reset($argument->value))) {
                    $price_item = $order->commerce_order_total['und'][0];
                    $total_price = commerce_currency_format($price_item['amount'], $price_item['currency_code'], $order);
                    $components = array();
                    $weight = 0;
                    foreach ($price_item['data']['components'] as $key => $component) {
                        $component_type = commerce_price_component_type_load($component['name']);
                        if (empty($components[$component['name']])) {
                            $components[$component['name']] = array('title' => check_plain($component_type['display_title']), 'price' => commerce_price_component_total($price_item, $component['name']), 'weight' => $component_type['weight']);
                            $weight = max($weight, $component_type['weight']);
                        }
                    }
                    // If there is only a single component and its price equals the field's,
                    // then remove it and just show the actual price amount.
                    if (count($components) == 1 && in_array('base_price', array_keys($components))) {
                        $components = array();
                    }
                    // Sort the components by weight.
                    uasort($components, 'drupal_sort_weight');
                    // Format the prices for display.
                    foreach ($components as $key => &$component) {
                        $component['formatted_price'] = commerce_currency_format($component['price']['amount'], $component['price']['currency_code'], $order);
                    }
                }
            }
        }
    }
    return array('total' => $total_price, 'components' => $components);
}
 /**
  * Web Service: Validate request
  *
  * @param $request_state
  *   @see CommerceFirstDataGGE4Controller::resolvePaymentState()
  *   Additional properties:
  *   - 'validation_errors': An array of validation errors
  *
  * @return
  *   TRUE if the request can be performed, else FALSE with $request_state
  *   updated with an array of  'validation_errors'
  */
 public function requestValidate(&$request_state)
 {
     $request_state['validation_errors'] = array();
     $errors =& $request_state['validation_errors'];
     if (!$this->isValid()) {
         $errors[] = t('First Data web service is not configured.');
         return FALSE;
     }
     if (empty($request_state) || !is_array($request_state)) {
         $errors[] = t('Empty request.');
         return FALSE;
     }
     // Resolve state
     $this->controller->resolvePaymentState($request_state);
     // Set local vars
     $card = $request_state['card'];
     $charge = $request_state['charge'];
     // Check transaction type
     $txn_type_info = $this->controller->transactionType($request_state['txn_type']);
     if (empty($txn_type_info)) {
         $errors[] = t('Invalid transaction type requested.');
         return FALSE;
     }
     // Charge parameters are required for all txn types
     if (empty($request_state['skip_charge_validation'])) {
         // Check that charge is a valid price array
         if (empty($charge) || !isset($charge['amount']) || !isset($charge['currency_code'])) {
             $errors[] = t('No charge details provided.');
             return FALSE;
         }
         // Zero Dollar Pre-Authorizations
         if ($request_state['txn_type'] != FIRSTDATA_GGE4_CREDIT_PREAUTH_ONLY && commerce_firstdata_gge4_is_zero($charge['amount'])) {
             if (empty($txn_type_info['zero_auth_allowed'])) {
                 $requested_txn_type_info = $this->controller->transactionType($request_state['txn_type']);
                 $errors[] = t('Zero Dollar Pre-Authorizations cannot be performed on @label transactions.', array(isset($requested_txn_type_info['label']) ? $requested_txn_type_info['label'] : $request_state['txn_type']));
                 return FALSE;
             }
             // Switch type to preauth
             $request_state['txn_type'] = FIRSTDATA_GGE4_CREDIT_PREAUTH_ONLY;
             $txn_type_info = $this->controller->transactionType($request_state['txn_type']);
         }
     }
     // Set variable for easier checks
     $charge_exists = !empty($charge) && isset($charge['amount']) && isset($charge['currency_code']);
     // Set transaction type
     $txn_type_code = $request_state['txn_type'];
     // Validate per txn type
     if (!empty($txn_type_info['requires_card'])) {
         // Purchase, Pre-auth, Pre-auth only, Refund via card
         // Card data is needed for these transactions
         if (empty($card)) {
             $errors[] = t('Missing credit card data.');
             return FALSE;
         }
         // Only active cards can be processed
         if (isset($card->status) && $card->status != 1) {
             $errors[] = t('Credit card is not active.');
             return FALSE;
         }
         // Expiration date is needed for these transactions
         if (empty($card->card_exp_month) || empty($card->card_exp_year)) {
             $errors[] = t('Missing credit card expiration.');
             return FALSE;
         }
         // Load card functions
         module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.credit_card');
         // Validate the expiration date.
         if (commerce_payment_validate_credit_card_exp_date($card->card_exp_month, $card->card_exp_year) !== TRUE) {
             $errors[] = t('Credit card has expired.');
             return FALSE;
         }
         // Check if empty card number or remote id
         // - cardonfile plugin validates for request basd on remote_id
         if (empty($card->card_number) && empty($card->remote_id)) {
             $errors[] = t('Missing credit card number.');
             return FALSE;
         }
         // Name on card
         if (empty($card->card_name)) {
             $has_card_name = FALSE;
             if (!empty($request_state['billing_address'])) {
                 if (!empty($request_state['billing_address']['name_line'])) {
                     $has_card_name = TRUE;
                 }
             }
             if (!$has_card_name) {
                 $errors[] = t('Missing name for the credit card.');
                 return FALSE;
             }
         }
     } elseif (!empty($txn_type_info['transaction_operation'])) {
         // Pre-auth capture, Void, Refund
         /** @todo: static transactionAccess($txn_type, $transaction, $amount = NULL) ****/
         $prev_transaction = $request_state['previous_transaction'];
         if (empty($prev_transaction)) {
             $errors[] = t('Missing previous transaction.');
             return FALSE;
         }
         if (empty($prev_transaction->data['authorization_num'])) {
             $errors[] = t('Missing previous transaction authorization number.');
             return FALSE;
         }
         if (empty($prev_transaction->data['transaction_tag'])) {
             $errors[] = t('Missing previous transaction tag.');
             return FALSE;
         }
         // Now used for all time calculations
         $now = time();
         // Check if requested transaction type is expired
         if (!empty($txn_type_info['expiration']) && !empty($prev_transaction->created)) {
             if ($now - $prev_transaction->created > $txn_type_info['expiration']) {
                 $errors[] = t('@label is not available after @expiration.', array('@label' => $txn_type_info['label'], '@expiration' => format_interval($txn_type_info['expiration'])));
                 return FALSE;
             }
         }
         // Check expiration since the last update to the transaction.
         if (!empty($txn_type_info['changed_expiration']) && !empty($prev_transaction->changed)) {
             if ($now - $prev_transaction->changed > $txn_type_info['changed_expiration']) {
                 $errors[] = t('@label is not available after @expiration.', array('@label' => $txn_type_info['label'], '@expiration' => format_interval($txn_type_info['changed_expiration'])));
                 return FALSE;
             }
         }
         // Check previous transaction with type info
         if (!empty($prev_transaction->remote_status) && ($prev_txn_type_info = $this->controller->transactionType($prev_transaction->remote_status))) {
             // Check allowed_transactions
             if (empty($prev_txn_type_info['allowed_transactions']) || !in_array($txn_type_code, $prev_txn_type_info['allowed_transactions'])) {
                 $errors[] = t('@label is not available for this transaction.', array('@label' => $txn_type_info['label']));
                 return FALSE;
             }
             // Check the amount is less than or equal to the max transaction amount allowed.
             if (!empty($txn_type_info['max_amount_factor']) && $charge_exists && empty($request_state['skip_charge_validation'])) {
                 $txn_max = $this->controller->transactionMaxAmount($txn_type_code, $prev_transaction);
                 $txn_max = array('amount' => commerce_currency_convert($txn_max['amount'], $txn_max['currency_code'], $charge['currency_code']), 'currency_code' => $charge['currency_code']);
                 if ($charge['amount'] > $txn_max['amount']) {
                     $action_word = !empty($txn_type_info['action_word']['present']) ? $txn_type_info['action_word']['present'] : $txn_type_code;
                     if ($txn_type_info['max_amount_factor'] > 1) {
                         $percent = 100 * ($txn_type_info['max_amount_factor'] - 1);
                         $errors[] = t('You cannot @action more than @max_amount, @percent% above the transaction amount.', array('@action' => $action_word, '@percent' => number_format($percent, 2), '@max_amount' => commerce_currency_format($txn_max['amount'], $prev_transaction->currency_code)));
                     } elseif ($txn_type_info['max_amount_factor'] < 1) {
                         $percent = 100 * (1 - $txn_type_info['max_amount_factor']);
                         $errors[] = t('You cannot @action more than @max_amount, @percent% below the transaction amount.', array('@action' => $action_word, '@percent' => number_format($percent, 2), '@max_amount' => commerce_currency_format($txn_max['amount'], $prev_transaction->currency_code)));
                     } else {
                         $errors[] = t('You cannot @action more than the transaction amount.', array('@action' => $action_word));
                     }
                     return FALSE;
                 }
             }
         }
         // Requested transaction type specific checks
         switch ($txn_type_code) {
             case COMMERCE_CREDIT_CREDIT:
                 // Doesn't have a success status or has an amount of 0 or less.
                 if ($prev_transaction->status != COMMERCE_PAYMENT_STATUS_SUCCESS || $prev_transaction->amount <= 0) {
                     $errors[] = t('Credit processing is not available for this transaction.');
                     return FALSE;
                 }
                 break;
         }
     }
     // Let other plugins and modules validate
     $event_errors = $this->controller->trigger('ws_request_validate', $request_state);
     if (!empty($event_errors)) {
         $errors = array_merge($errors, $event_errors);
         return FALSE;
     }
     // ALLOW if made it here
     return TRUE;
 }
<div class="views-field-field-product-image"><?php 
print $fields['field_product_image']->content;
?>
</div>
<div class="views-field-title"><?php 
print $fields['title']->content;
?>
</div>

<?php 
$nid = strip_tags($fields['nid']->content);
$node = node_load($nid);
$product = commerce_product_load($node->field_product[LANGUAGE_NONE][0]['product_id']);
?>
<div class="views-field-field-sell-price"><?php 
print commerce_currency_format($product->commerce_price[LANGUAGE_NONE][0]['amount'], 'VND');
?>
</div>

<div class="views-field-field-old-price"><?php 
print $fields['field_old_price']->content;
?>
</div>
<?php 
$line_item = commerce_line_item_new($product->type, $order_id = 0);
$line_item->data['context']['product_ids'] = array($product->product_id);
$line_item->quantity = 1;
$qty = 1;
$form_id = commerce_cart_add_to_cart_form_id(array($product->product_id), $qty);
$addtocart_form = drupal_get_form($form_id, $line_item);
?>
Example #11
0
        <div class="field-items">
          <div class="field-item even">
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('Order Number: @order_number', array('@order_number' => $order->order_number));
?>
</div>
            </div>
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('API Provider: @api_number', array('@api_number' => $api_provider));
?>
</div>
            </div>
            <div class="addressfield-container-inline name-block">
              <div class="name-block"><?php 
print t('Amount:');
?>
 <?php 
print commerce_currency_format($order->commerce_order_total[LANGUAGE_NONE][0]['amount'], $order->commerce_order_total[LANGUAGE_NONE][0]['currency_code']);
?>
</div>
            </div>
          </div>
        </div>
      </div>
      </td>
    </tr>
  </tbody>
</table>
    <div class="cart-head" id="cart-head">
        <label><?php 
print t('My cart');
?>
 <span>(<?php 
print format_plural($quantity, '1', '@count');
?>
)</span></label>
        <?php 
if ($quantity > 0) {
    ?>
        	<p><span><?php 
    print t('Total');
    ?>
:</span> <?php 
    print commerce_currency_format($order->commerce_order_total['und'][0]['amount'], $order->commerce_order_total['und'][0]['currency_code']);
    ?>
</p>
        <?php 
} else {
    ?>
        	<p><span><?php 
    print t('Total');
    ?>
:</span> <?php 
    print '$' . $quantity;
    ?>
&nbsp;</p>
		<?php 
}
?>
            ?>
</td>
              <td><?php 
            print commerce_currency_format($balance->getTransaction()->getRate(), $balance->getSupportedCurrency()->getName(), NULL, FALSE);
            ?>
</td>
              <td><?php 
            print commerce_currency_format($balance->getUsage(), $balance->getSupportedCurrency()->getName(), NULL, FALSE);
            ?>
</td>
              <td><?php 
            print commerce_currency_format($balance->getTax(), $balance->getSupportedCurrency()->getName(), NULL, FALSE);
            ?>
</td>
              <td><?php 
            print commerce_currency_format($balance->getAmount(), $balance->getSupportedCurrency()->getName(), NULL, FALSE);
            ?>
            <?php 
        }
        ?>
            <?php 
        if ($download_prepaid_report_perm) {
            ?>
&nbsp;&nbsp;
              <?php 
            print l(t('Balance Detail (CSV)'), 'users/me/monetization/billing/report/download-prepaid-report/' . rawurlencode($balance->getSupportedCurrency()->getName()) . '/' . rawurlencode(date('F-Y', time())), array('attributes' => array('style' => 'float:right')));
            ?>
            <?php 
        }
        ?>
          </td>
    ?>
  <div class="multivendor-shipping-vendor-base">
    <?php 
    echo t('Base shipping rate is @amount', array('@amount' => commerce_currency_format($vendor->base_amount, commerce_default_currency())), array('context' => 'Multivendor shipping'));
    ?>
  </div>
  <?php 
}
?>

  <?php 
if ($vendor->package_amount > 0) {
    ?>
  <div class="multivendor-shipping-vendor-package">
    <?php 
    echo t('Each package with @size items costs @amount', array('@size' => $vendor->package_size, '@amount' => commerce_currency_format($vendor->package_amount, commerce_default_currency())), array('context' => 'Multivendor shipping'));
    ?>
  </div>
  <?php 
}
?>

  <?php 
if (!empty($vendor->description)) {
    ?>
  <div class="multivendor-shipping-vendor-description">
    <?php 
    echo t($vendor->description, array(), array('context' => 'Multivendor shipping'));
    ?>
  </div>
  <?php 
Example #15
0
    ?>
>
                    <p class="special-price">
                      <span class="price">
					  	<?php 
    print commerce_currency_format($product->commerce_price['und'][0]['amount'], $product->commerce_price['und'][0]['currency_code']);
    ?>
                      </span> 
                    </p> 
                    <p class="old-price"> 
                      <span class="price">
					  	<?php 
    if (isset($product->field_old_price['und'])) {
        ?>
							<?php 
        print commerce_currency_format($product->field_old_price['und'][0]['amount'], $product->field_old_price['und'][0]['currency_code']);
        ?>
                        <?php 
    }
    ?>
                      </span> 
                    </p>
                </div>
            <?php 
}
?>
          </div>

          <div class="short-description">
            <?php 
print render($content['field_product_short_description']);