Issues (25)

Model/BillingAddressManagement.php (1 issue)

1
<?php
2
3
namespace Hryvinskyi\QuoteAddressValidator\Model;
4
5
use Magento\Framework\App\ObjectManager;
6
use Magento\Framework\Exception\InputException;
7
use Magento\Framework\Exception\LocalizedException;
8
use Magento\Quote\Api\Data\AddressInterface;
9
10
class BillingAddressManagement extends \Magento\Quote\Model\BillingAddressManagement
11
{
12
    private $shippingAddressAssignment;
13
14
    public function assign($cartId, AddressInterface $address, $useForShipping = false)
15
    {
16
        /** @var \Magento\Quote\Model\Quote $quote */
17
        $quote = $this->quoteRepository->getActive($cartId);
18
        $address->setCustomerId($quote->getCustomerId());
19
        $quote->removeAddress($quote->getBillingAddress()->getId());
20
        $quote->setBillingAddress($address);
21
        try {
22
            $this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping);
0 ignored issues
show
Deprecated Code introduced by
The function Hryvinskyi\QuoteAddressV...pingAddressAssignment() has been deprecated: 101.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
            /** @scrutinizer ignore-deprecated */ $this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
23
            $quote->setDataChanges(true);
24
            $this->quoteRepository->save($quote);
25
        } catch (LocalizedException $e) {
26
            $this->logger->critical($e);
27
            throw new InputException(
28
                __(
29
                    'The billing information was unable to be saved. Error: "%message"',
30
                    ['message' => $e->getMessage()]
31
                )
32
            );
33
        } catch (\Exception $e) {
34
            $this->logger->critical($e);
35
            throw new InputException(__('The address failed to save. Verify the address and try again.'));
36
        }
37
        return $quote->getBillingAddress()->getId();
38
    }
39
40
    /**
41
     * Get shipping address assignment
42
     *
43
     * @return \Magento\Quote\Model\ShippingAddressAssignment
44
     * @deprecated 101.0.0
45
     * @see \Magento\Quote\Model\ShippingAddressAssignment
46
     */
47
    private function getShippingAddressAssignment()
48
    {
49
        if (!$this->shippingAddressAssignment) {
50
            $this->shippingAddressAssignment = ObjectManager::getInstance()
51
                ->get(\Magento\Quote\Model\ShippingAddressAssignment::class);
52
        }
53
        return $this->shippingAddressAssignment;
54
    }
55
}
56