In Drupal, commerce order contains multiple products. These products are attached to the line item to the orders. The line item table holds the information about the quantities and other information. The below is the simplest code to get the quantity of the order with different products.
In Drupal, commerce orders are associated with the Billing and Shipping information. We can access both Billing and Shipping information from the order object. The below sample code shows how to access the profile information.
In Drupal, commerce order contains both Billing and shipping information on normal checkout process. If we are creating the commerce order programmatically then we have to add this information in manually. The below is the example of code for adding the Billing and shipping address to the order.
The Drupal Commerce Commerce POS module help us to achieve Point of Sale concept. The Drupal Commerce POS differs from normal commerce order. On Commerce POS they have implemented their own Order management rather than using Commerce Order. This has been achieved by its own interface and classes. On Completing each order, the order is again mapped to normal commerce order.
In Drupal commerce will help to convert any numbers into a proper currency format. The function commerce_currency_format() helps to convert decimal numbers to particular country formatted currency. This function will accept a decimal number and country currency code for change given number into currency.
In Drupal commerce, we can able to add new Commerce Products programmatically using the commerce_product_new() function. This will create an object of Commerce product, Using the object we can able to set their attributes for the product. The below is the example and syntax for creating the commerce product.
The Lineitem will represent the commerce products. So using this line item ID we can able to load the product details. The Below syntax and example will show the loading commerce product from Line Items id.
The Line Items in Drupal commerce used to refer the product in Order. Using the Line Item id we can able to load order details. The function commerce_line_item_load() will contains respective order ID of the order. We can able to get the order details from order ID using the function commerce_order_load().
In Drupal Commerce is an entity reference to the order during order creation. The line item will refer the product in the order. We can able to programmatically update the line item using the function "entity_metadata_wrapper()". The below example will show how to update the line items programmatically.
In Drupal the function commerce_line_item_load() help us to load the commerce line item details Programmatically. The function accepts the unique id of each line item. The below syntax and example shows how to access the line item details programmatically.
In Drupal, commerce Orders are acted as a separate entity. The order has different status during each stage on purchasing. These status updates are taken place during the order checkout process. It possible us to update order status programmatically from one state to others.
In Drupal 7 using the core functions of commerce, we can place orders programmatically. Using the function "commerce_product_line_item_new()" and "commerce_line_item_save()" we can add item to cart. The function "commerce_order_save()" will place all line items into order. The below is the sample code which demonstrates.
We will add the product to the cart to checkout. The below is the code which used to check current user cart have the product or not. The function "commerce_line_items_quantity()" will returns the total quantity and "commerce_line_items_total()" will return cart total. These functions are taking the order line item array. This code will return an array of product that user have been added to his/her cart.
The function commerce_cart_order_load() help to load the current user cart details. Using the cart order object details we can able to unset or empty the commerce cart of that user. The function commerce_cart_order_empty() help to achieve this. The below sample code demonstrate how to delete cart of a user.
In Drupal commerce, cart items are handled as Entity. The cart items are referenced to the particular user id. Using user id we can able to load cart details that are currently added by the user. The function "commerce_cart_order_load()" takes user id as argument to load the cart details. The below example shows how to load cart details of the current user.
In programmatically we can able to alter commerce line items. The line items are kept as an entity in Drupal commerce system. Using the function "commerce_line_item_load()" we load line item as the object and able to access line item properties. The function commerce_line_item_save() will help to update the line item.
The Commerce order will contain the information about the order that was placed. We can alter commerce order detail by loading this. With help of "field_attach_update()" function we can alter the commerce order details. The below is an example of commerce order update.
We using Drupal Commerce to store and retrieve line Items. It treat product as separate entity. The product informations are able to load by its product ID, the product information we get as Object. Using the product object we can update the values of commerce product. The below Syntax and example shows how to load commerce product and update values programatically.