I'm creating orders programmaticaly but my billings address are not updating.

I can set the shipping address that I want (another from the connected user) but the billing is still the one from the connected user.

See :

        $websiteId = $this->_storeManager->getStore()->getWebsiteId();
        $customerTemp->loadByEmail($orderData['email']);// load customet by email address
        $quote=$this->quote->create(); //Create object of quote
        $quote->setStore($store); //set store for which you create quote
        $customer= $this->customerRepository->getById($customerTemp->getEntityId());
        $quote->assignCustomer($customer); //Assign quote to customer
        $objectManager = ObjectManager::getInstance();
        $codeClient = $orderData["code_client"];
        //add items in quote
        $comment = $orderData["comment"];
        foreach($orderData['items'] as $item){
            //add products

        //Set Address to quote
        $billings = $quote->getBillingAddress()->addData($orderData['shipping_address']);
        // Collect Rates and Set Shipping & Payment Method
        $shippingAddress->setShippingMethod('flatrate_flatrate'); //shipping method
//        $quote->save(); //Now Save quote and your quote is ready        // Set Sales Order Payment
        $quote->getPayment()->importData(['method' => 'checkmo']);
        // Collect Totals & Save Quote

I've solved my problem by adding missing fields in my array :

    $shippingAdress = array(
    "customer_address_id" => "",
    "prefix" => "",
    'firstname' => $prenom,
    "middlename" => "",
    'lastname' => $nom,
    'street' => $adresse,
    "company"=> "",
    'street' => array($adresse),
    'city' => $villeShipping,
    'country_id' => "FR",
    'region' => $paysShipping,
    'postcode' => $CPShipping,
    'telephone' => "",
    'fax' => "",
    "same_as_billing" => true,
    'save_in_address_book' => 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.