1

I am adding a shipping address with a same_as_billing value of 0, after adding this address to the cart / via the repository the value in the database for same_as_billing is 1 on the shipping address row.

I am trying to add the addresses in separate actions, is there (and if so where is it) any kind of mechanism that by default adds a shipping address with a same_as_billing value of 1 if it isn't set?

1

Found it: Magento\Quote\Model\Quote\Address

protected function _populateBeforeSaveData()
{
    if ($this->getQuote()) {
        $this->_dataSaveAllowed = (bool)$this->getQuote()->getId();

        if ($this->getQuote()->getId()) {
            $this->setQuoteId($this->getQuote()->getId());
        }
        $this->setCustomerId($this->getQuote()->getCustomerId());

        /**
         * Init customer address id if customer address is assigned
         */
        if ($this->getCustomerAddressData()) {
            $this->setCustomerAddressId($this->getCustomerAddressData()->getId());
        }

        if (!$this->getId()) {
            $this->setSameAsBilling((int)$this->_isSameAsBilling());
        }
    }
}

/**
 * Returns true if shipping address is same as billing
 *
 * @return bool
 */
protected function _isSameAsBilling()
{
    return $this->getAddressType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING &&
        ($this->_isNotRegisteredCustomer() ||
        $this->_isDefaultShippingNullOrSameAsBillingAddress());
}

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.