Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteRelation.php
Go to the documentation of this file.
1 <?php
7 
9 
15 {
23  public function deleteRelation(
24  \Magento\Framework\Model\AbstractModel $address,
26  ) {
27  $toUpdate = $this->getDataToUpdate($address, $customer);
28 
29  if (!$address->getIsCustomerSaveTransaction() && !empty($toUpdate)) {
30  $address->getResource()->getConnection()->update(
31  $address->getResource()->getTable('customer_entity'),
32  $toUpdate,
33  $address->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId())
34  );
35  }
36  }
37 
45  private function getDataToUpdate(
46  \Magento\Framework\Model\AbstractModel $address,
48  ) {
49  $toUpdate = [];
50  if ($address->getId()) {
51  if ($customer->getDefaultBilling() == $address->getId()) {
52  $toUpdate[CustomerInterface::DEFAULT_BILLING] = null;
53  }
54 
55  if ($customer->getDefaultShipping() == $address->getId()) {
56  $toUpdate[CustomerInterface::DEFAULT_SHIPPING] = null;
57  }
58  }
59 
60  return $toUpdate;
61  }
62 }
$customer
Definition: customers.php:11
$address
Definition: customer.php:38
deleteRelation(\Magento\Framework\Model\AbstractModel $address, \Magento\Customer\Model\Customer $customer)