Files
Oleksii Korshenko 4b5626478a MAGETWO-71174: Update doc block information in php classes with @deprecated and @since tags
- replaced release version with package version in @since and @depreacated tags
 - removed @since tag from private properties/methods  and non @api classes
2017-08-04 19:15:55 -05:00

63 lines
1.9 KiB
PHP

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\ResourceModel\Address;
use Magento\Customer\Api\Data\CustomerInterface;
/**
* Class DeleteRelation
* @package Magento\Customer\Model\ResourceModel\Address
*/
class DeleteRelation
{
/**
* Delete relation (billing and shipping) between customer and address
*
* @param \Magento\Framework\Model\AbstractModel $address
* @param \Magento\Customer\Model\Customer $customer
* @return void
*/
public function deleteRelation(
\Magento\Framework\Model\AbstractModel $address,
\Magento\Customer\Model\Customer $customer
) {
$toUpdate = $this->getDataToUpdate($address, $customer);
if (!$address->getIsCustomerSaveTransaction() && !empty($toUpdate)) {
$address->getResource()->getConnection()->update(
$address->getResource()->getTable('customer_entity'),
$toUpdate,
$address->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId())
);
}
}
/**
* Return address type (billing or shipping), or null if address is not default
*
* @param \Magento\Customer\Api\Data\AddressInterface $address
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return array
*/
private function getDataToUpdate(
\Magento\Framework\Model\AbstractModel $address,
\Magento\Customer\Model\Customer $customer
) {
$toUpdate = [];
if ($address->getId()) {
if ($customer->getDefaultBilling() == $address->getId()) {
$toUpdate[CustomerInterface::DEFAULT_BILLING] = null;
}
if ($customer->getDefaultShipping() == $address->getId()) {
$toUpdate[CustomerInterface::DEFAULT_SHIPPING] = null;
}
}
return $toUpdate;
}
}