How to Create Manual Orders in Drupal 10 with Commerce (SGD Currency)
Creating manual orders in Drupal 10 Commerce is a common requirement for admins who take offline payments such as cash, bank transfer, or PayNow. This tutorial explains how to build a custom manual order form and ensure the order currency is always Singapore Dollar (SGD).
Why Manual Orders Are Needed
- Offline payments (Cash, Bank Transfer, PayNow)
- Admin-created orders
- Special discounts
- School / student-based billing
Step 1: Configure Store Currency
Drupal Commerce always uses the store currency. Make sure your store default currency is set to SGD.
Admin → Commerce → Configuration → Stores Default currency: SGD---
Step 2: Create Order Programmatically
Below is an example of creating a draft order programmatically.
use Drupal\commerce_order\Entity\Order; $order = Order::create([ 'type' => 'default', 'store_id' => $store_id, 'uid' => $uid, 'mail' => $mail, 'state' => 'draft', ]); $order->save();---
Step 3: Add Order Item with SGD Price
Always define the price with currency SGD.
use Drupal\commerce_price\Price;
use Drupal\commerce_order\Entity\OrderItem;
$price = new Price('100.00', 'SGD');
$order_item = OrderItem::create([
'type' => 'default',
'purchased_entity' => $variation,
'quantity' => 1,
]);
$order_item->setUnitPrice($price);
$order->addItem($order_item);
---
Step 4: Apply Discount (Optional)
use Drupal\commerce_order\Adjustment;
$order_item->addAdjustment(new Adjustment([
'type' => 'promotion',
'label' => 'Discount (10%)',
'amount' => new Price('-10.00', 'SGD'),
]));
---
Step 5: Add GST (9%)
$gst = $order->getSubtotalPrice()->multiply('0.09');
$order->addAdjustment(new Adjustment([
'type' => 'tax',
'label' => 'GST',
'amount' => $gst,
'percentage' => '0.09',
]));
---
Step 6: Create Manual Payment
use Drupal\commerce_payment\Entity\Payment; $payment = Payment::create([ 'state' => 'completed', 'amount' => $order->getTotalPrice(), 'payment_gateway' => 'manual', 'order_id' => $order->id(), ]); $payment->save();---
Final Result
- ✔ Order currency: SGD
- ✔ Discount applied
- ✔ GST calculated
- ✔ Payment marked as paid
Common Mistakes to Avoid
- Using store currency different from SGD
- Creating prices without currency
- Applying GST before discount
- Creating payment before order save
Conclusion
Drupal 10 Commerce is flexible enough to handle manual orders with full control over currency, taxes, and payments. By forcing SGD at the store and price level, you can avoid all currency mismatch issues.
Developer Sahayak brings real-world solutions for Drupal, Laravel, and PHP developers. Stay tuned for more backend tutorials.
Author: Backend Developer (Drupal | Laravel | PHP)
0 Comments