fixing pickup

This commit is contained in:
merdan 2022-03-09 13:51:07 +05:00
parent 5bd77bdb84
commit 7534ef4b81
2 changed files with 4 additions and 81 deletions

View File

@ -8,81 +8,4 @@ use Webkul\Checkout\Models\CartAddress;
class ShoppingCart extends \Webkul\Checkout\Cart
{
public function saveAddress($address, $shipment) : bool
{
if (! $cart = $this->getCart()) {
return false;
}
if($shipment !== 'pickup_pickup'){
$this->saveMusteriAddress($address,$cart);
}
else
$this->saveRecipientAddress($address,$cart);
$this->assignCustomerFields($cart);
return $cart->save();
}
/**
* Save customer address.
*
* @param array $data
* @return bool
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
private function saveMusteriAddress($data,$cart)
{
$billingAddressData = $this->gatherBillingAddress($data, $cart);
$shippingAddressData = $this->gatherShippingAddress($data, $cart);
$this->linkAddresses($cart, $billingAddressData, $shippingAddressData);
}
public function saveRecipientAddress($data,$cart)
{
$recipientAddressRepository = app(RecipientRepository::class);
$customerAddress = [];
if (isset($data['billing']['address_id']) && $data['billing']['address_id'])
{
$customerAddress = $recipientAddressRepository->findOneWhere(['id' => $data['billing']['address_id']])
->toArray();
}
$billingAddress = array_merge(
$customerAddress,
$data['billing'],
['cart_id' => $cart->id, 'customer_id' => $cart->customer_id],
$this->fillAddressAttributes($data['billing'])
);
$this->linkAddresses($cart,$billingAddress,$billingAddress);
}
/**
* Fill address attributes.
*
* @return array
*/
private function fillAddressAttributes(array $addressAttributes): array
{
$attributes = [];
$cartAddress = new CartAddress();
foreach ($cartAddress->getFillable() as $attribute) {
if (isset($addressAttributes[$attribute])) {
$attributes[$attribute] = $addressAttributes[$attribute];
}
}
return $attributes;
}
}

View File

@ -786,7 +786,7 @@ class Cart
*
* @param \Webkul\Checkout\Contracts\Cart $cart
*/
public function assignCustomerFields(\Webkul\Checkout\Contracts\Cart $cart): void
private function assignCustomerFields(\Webkul\Checkout\Contracts\Cart $cart): void
{
if (
auth()->guard()->check()
@ -923,7 +923,7 @@ class Cart
* @param $cart
* @return array
*/
public function gatherBillingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
private function gatherBillingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
{
$customerAddress = [];
@ -952,7 +952,7 @@ class Cart
* @param \Webkul\Checkout\Cart|null $cart
* @return array
*/
public function gatherShippingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
private function gatherShippingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
{
$customerAddress = [];
@ -982,7 +982,7 @@ class Cart
* @param array $shippingAddressData
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function linkAddresses(
private function linkAddresses(
\Webkul\Checkout\Models\Cart $cart,
array $billingAddressData,
array $shippingAddressData