Created
September 28, 2016 15:12
-
-
Save joshmiller83/2a091a348b0952db20663ce894677d6b to your computer and use it in GitHub Desktop.
Create an order programmatically for Drupal Commerce 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$order_type = "default"; | |
$store_id = 1; | |
$uid = 0; | |
$entity_type_manager = \Drupal::service('entity_type.manager'); | |
$order_storage = $entity_type_manager->getStorage('commerce_order'); | |
$new_order = $orderStorage->create([ | |
'type' => $order_type, | |
'store_id' => $store_id, | |
'uid' => $uid, | |
'cart' => FALSE, | |
]); | |
$new_order->save(); |
doesnt work it says
TypeError: Argument 1 passed to Drupal\commerce_tax\TaxRatePercentage::calculateTaxAmount() must be an instance of Drupal\commerce_price\Price, null given, called in C:\Users\ren\Sites\devdesktop\MemorphoseDev2020\web\modules\contrib\commerce\modules\tax\src\Plugin\Commerce\TaxType\LocalTaxTypeBase.php on line 131 in Drupal\commerce_tax\TaxRatePercentage->calculateTaxAmount() (line 131 of modules\contrib\commerce\modules\tax\src\TaxRatePercentage.php).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
A small typo - line 8 should be:
$new_order = $order_storage->create([