0

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 :

            $store=$this->_storeManager->getStore();
        $websiteId = $this->_storeManager->getStore()->getWebsiteId();
        $customerTemp=$this->customerFactory->create();
        $customerTemp->setWebsiteId($websiteId);
        $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->setCurrency();
        $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
        $quote->getShippingAddress()->addData($orderData['shipping_address']);
        $billings = $quote->getBillingAddress()->addData($orderData['shipping_address']);
        // Collect Rates and Set Shipping & Payment Method
        $shippingAddress=$quote->getShippingAddress();
        $shippingAddress->setCollectShippingRates(true)->collectShippingRates();
        $this->shippingRate->setCode('flatrate_flatrate');
        $shippingAddress->setShippingMethod('flatrate_flatrate'); //shipping method
        $quote->getShippingAddress()->addShippingRate($this->shippingRate);
        $quote->setCouponCode("")->collectTotals();
        $this->quoteRepository->save($quote);
//        $quote->save(); //Now Save quote and your quote is ready        // Set Sales Order Payment
        $quote->getPayment()->importData(['method' => 'checkmo']);
        // Collect Totals & Save Quote
        $quote->collectTotals();
        $this->nice($quote->getBillingAddress()->getCity());
        die;
        $this->quoteRepository->save($quote);
0

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.