I create orders programmatically, and I’ve a tax drawback: Drupal Development Service order, after altering Drupal Development Service line merchandise value, at all times has Drupal Development Service tax value with Drupal Development Service previous product value. How can I refresh Drupal Development Service adjustment tax after altering Drupal Development Service line-item value?
foreach ($entity_ids as $entity_id) { $abo = Node::load($entity_id); //utilisateur $consumer = $abo->get('field_utilisateur')->getValue()[0]['target_id']; $utilisateur = DrupaluserEntityUser::load($consumer); //profile $entity_manager = Drupal::entityTypeManager(); $profile = $entity_manager->getStorage('profile')->load($consumer); //abonnement $nid= $abo->id(); //livraison $date_livraison = new DateTime(); $date_livraison->modify('subsequent friday'); //ligne de commande $line_items = array(); $abo_array= $abo->get('field_abo_produits')->getValue(); foreach ($abo_array as $abo_item) { $ligne = $abo_item['target_id']; //load produit abonnement $merchandise = Drupalcommerce_orderEntityOrderItem::load($ligne); $quantite = $item->getQuantity(); $produit = $item->getPurchasedEntity(); $order_item = Drupalcommerce_orderEntityOrderItem::create([ 'type' => 'default', 'purchased_entity' => $produit, 'quantity' => $quantite, //'unit_price' => $role_price, ]); $order_item->save(); array_push($line_items,$order_item); } //creation de la commande $order = Drupalcommerce_orderEntityOrder::create([ 'type' => 'default', 'store_id' => 1, 'checkout_flow' => 'boulangerie', 'uid' => $user, 'billing_profile' =>$profile, 'field_abonnement' => $nid, 'placed' => time(), 'field_date_livraison' =>$date_livraison->format('Y-m-d'), 'order_items' =>$line_items ]); $order->save(); $order->set('order_number', $order->id()); $order->save(); $order->set('state', 'full'); $order->save(); //prix custo foreach ($order->getItems() as $ligne_de_commande) { $produit = $ligne_de_commande->getPurchasedEntity(); //prix if ($utilisateur->hasRole('biocoop')) { $role_price = $produit->get('field_prix_biocoop'); $position = 'biocoop'; } if ($utilisateur->hasRole('montagne')) { $role_price = $produit->get('field_prix_montagne'); $position = 'montagne'; } if ($utilisateur->hasRole('vente_directe')) { $role_price = $produit->get('field_prix_vd'); $position = 'vente_directe'; } $unit_price = new Drupalcommerce_pricePrice($role_price->quantity, 'EUR'); $ligne_de_commande->setUnitPrice($unit_price); $ligne_de_commande->save(); } $order->save(); }