Exemplo n.º 1
1
 /**
  * This function will create recurring order and entity programmatically.
  * @param $product_ids
  * @return \entity
  */
 public static function createProgrammatically($product_ids)
 {
     global $user;
     global $entities;
     $product = array();
     $quantity = 1;
     $uid = $user->uid;
     $add_shipping = FALSE;
     //
     $subscription_products = Utils::getSubscriptionProductsList()->verify(get_class());
     foreach ($product_ids as $product_id) {
         if ($product = commerce_product_load($product_id)) {
             if ($product->type == 'product') {
                 $add_shipping = TRUE;
             }
             if (in_array($product->sku, $subscription_products)) {
                 $product->commerce_price[LANGUAGE_NONE][0]['amount'] = 0;
                 $line_item = commerce_product_line_item_new($product, $quantity);
             } else {
                 $line_item = commerce_product_line_item_new($product, $quantity);
             }
             commerce_cart_product_add($uid, $line_item);
         }
     }
     // if no product loaded then need to return null
     if (empty($product)) {
         return NULL;
     }
     $order = commerce_cart_order_load($uid);
     $order = commerce_order_status_update($order, "pending", TRUE);
     if ($add_shipping) {
         // Save and add the line item to the order.
         $line_item = new Shipping(NULL, $order->order_id);
         $line_item = $line_item->createShippingLineItemProgrammatically($order);
         $new_line_item = commerce_shipping_add_shipping_line_item($line_item, $order, TRUE);
     }
     commerce_avatax_calculate_sales_tax($order);
     commerce_order_save($order);
     drupal_static_reset('commerce_recurring_order_load_recurring_line_items');
     commerce_checkout_complete($order);
     $order_object = new CommerceOrder($order->order_id);
     $entities['commerce_order'][$order_object->getId()] = $order_object;
     $order_object->reload();
     return new Response(TRUE, $order_object, "");
 }
 /**
  * Replace with your own cart here to try out
  * different promotions, tax, shipping, etc. 
  * 
  * @param merchantID
  * @param awsAccessKeyID
  */
 private function getCartXML($merchantID, $awsAccessKeyID)
 {
     $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "<Order xmlns=\"http://payments.amazon.com/checkout/2008-06-15/\">" . "    <ClientRequestId>123457</ClientRequestId>" . "    <Cart>" . "    <Items>";
     global $user;
     $cart = commerce_cart_order_load($user->uid);
     foreach ($cart->commerce_line_items['und'] as $line_item_id) {
         $line_item = commerce_line_item_load($line_item_id);
         list($quantity) = explode('.', $line_item->quantity);
         $xml .= "      <Item>" . "         <SKU>" . $line_item->line_item_label . "</SKU>" . "         <MerchantId>" . $merchantID . "</MerchantId>" . "         <Title>" . $line_item->line_item_label . "</Title>" . "         <Description>" . $line_item->line_item_label . "</Description>" . "         <Price>" . "            <Amount>" . (0 + $line_item->commerce_unit_price['und'][0]['amount'] / 100) . "</Amount>" . "            <CurrencyCode>INR</CurrencyCode>" . "         </Price>" . "         <Quantity> " . $quantity . "</Quantity>" . "         <Weight>" . "            <Amount>.5</Amount>" . "            <Unit>kg</Unit>" . "         </Weight>" . "         <Category>Tshirts</Category>" . "      </Item>";
     }
     $xml .= "    </Items>" . "    </Cart>" . "</Order>";
     return $xml;
 }
Exemplo n.º 3
0
 public function __construct($order_id = NULL)
 {
     if (is_null($order_id)) {
         global $user;
         $order = commerce_cart_order_load($user->uid);
     } else {
         $order = commerce_order_load($order_id);
     }
     $this->order_id = $order->order_id;
     $view = $this->getCartView();
     $output = '';
     parent::__construct(views_form_id($view), $view, $output);
 }
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
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']);
/**
 * Overrides theme_menu_link().
 */
function cubert_menu_link(array $variables)
{
    $element = $variables['element'];
    $sub_menu = '';
    $team_menus = array('menu-teampayment-navigation', 'user-menu');
    $is_user_menu = !empty($element['#original_link']['menu_name']) && $element['#original_link']['menu_name'] == 'user-menu';
    // On primary navigation menu, class 'active' is not set on active menu item.
    // @see https://drupal.org/node/1896674
    if (($element['#href'] == $_GET['q'] || $element['#href'] == '<front>' && drupal_is_front_page()) && empty($element['#localized_options']['language'])) {
        $element['#attributes']['class'][] = 'active';
    }
    // Add FontAwesome icons based on link function
    $icon = "";
    if (!empty($element['#original_link']['menu_name']) && $element['#original_link']['menu_name'] == 'user-menu') {
        $title = !empty($element['#title']) ? $element['#title'] : '';
        $element['#attributes']['class'][] = 'user-action';
        if ($element['#href'] == 'user') {
            global $user;
            $element['#title'] = $user->name;
            $icon = "<i class='fa fa-user'></i>&nbsp;&nbsp;";
            $element['#attributes']['class'][] = 'user-action-account';
        }
        if ($element['#href'] == 'user/logout') {
            $icon = "<i class='fa fa-sign-out'></i> ";
            $element['#attributes']['class'][] = 'user-action-logout';
        }
        if ($element['#href'] == 'cart/my') {
            $icon = "<i class='fa fa-shopping-cart'></i> ";
            $element['#attributes']['class'][] = 'user-action-cart';
            global $user;
            $quantity = 0;
            if ($order = commerce_cart_order_load($user->uid)) {
                $wrapper = entity_metadata_wrapper('commerce_order', $order);
                $quantity = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());
            }
            $title = $title . " (" . $quantity . ")";
            $element['#title'] = $title;
        }
    }
    $element['#localized_options'] += array('html' => TRUE);
    if (!empty($element['#original_link']['menu_name']) && ($element['#original_link']['menu_name'] == 'menu-teampayment-navigation' || $element['#original_link']['menu_name'] == 'user-menu')) {
        if ($element['#href'] == 'dashboard') {
            $icon = "<i class='fa fa-home'></i> ";
            $element['#title'] = '';
            $element['#attributes']['class'][] = 'main-nav-home';
        }
        $commerce_links = array('products', 'cart', 'cart/my');
        if (in_array($element['#href'], $commerce_links)) {
            if (module_exists('team_payment')) {
                $group = team_payment_get_group_info();
                $products = team_payment_get_all_commerce_products($group);
                if (count($products) == 0) {
                    return;
                }
            }
        }
    }
    if ($element['#below']) {
        // Prevent dropdown functions from being added to management menu so it
        // does not affect the navbar module.
        if ($element['#original_link']['menu_name'] == 'management' && module_exists('navbar')) {
            $sub_menu = drupal_render($element['#below']);
        } elseif (!empty($element['#original_link']['depth']) && in_array($element['#original_link']['menu_name'], $team_menus)) {
            $depth = $element['#original_link']['depth'];
            // Add our own wrapper.
            if ($depth == 2 && !$is_user_menu || $depth == 1 && $is_user_menu) {
                unset($element['#below']['#theme_wrappers']);
                $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
                // Generate as standard dropdown.
                $element['#title'] .= ' <i class="fa fa-chevron-down"></i>';
                $element['#attributes']['class'][] = 'dropdown';
                $element['#localized_options']['html'] = TRUE;
                // Set dropdown trigger element to # to prevent inadvertant page loading
                // when a submenu link is clicked.
                $element['#localized_options']['attributes']['data-target'] = '#';
                $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
                $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
            } else {
                if ($is_user_menu && ($depth = 2)) {
                    unset($element['#below']['#theme_wrappers']);
                    $sub_menu = '<ul class="menu__nested">' . drupal_render($element['#below']) . '</ul>';
                }
            }
        }
    }
    $prefix = "";
    $suffix = "";
    $output = l($icon . $element['#title'], $element['#href'], $element['#localized_options']);
    if (!empty($element['#original_link']['depth']) && $element['#original_link']['depth'] == 2) {
        //$prefix = '<li role="separator" class="divider"></li>';
        //$suffix = '<li role="separator" class="divider"></li>';
    }
    return $prefix . '<li ' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>" . $suffix . "\n";
}