fixing pickup

This commit is contained in:
merdan 2022-03-09 11:43:45 +05:00
parent 3f0ac64cbd
commit 941e3a3b72
3 changed files with 82 additions and 5 deletions

View File

@ -56,7 +56,7 @@ class Checkout extends CheckoutController
}
$shippingMethod = $request->get('shipping_method');
if (Cart::hasError() || ! Cart::saveCustomerAddress($data) || ! Shipping::collectRates()
if (Cart::hasError() || ! Cart::saveAddress($data) || ! Shipping::collectRates()
|| ! $shippingMethod
|| ! Cart::saveShippingMethod($shippingMethod)) {
return response(['message'=>'error. wrong shipment method or address'],400);

View File

@ -2,9 +2,86 @@
namespace Sarga\Shop;
use Sarga\Shop\Repositories\RecipientRepository;
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],
$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
*/
private function assignCustomerFields(\Webkul\Checkout\Contracts\Cart $cart): void
public function assignCustomerFields(\Webkul\Checkout\Contracts\Cart $cart): void
{
if (
auth()->guard()->check()
@ -923,7 +923,7 @@ class Cart
* @param $cart
* @return array
*/
private function gatherBillingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
public function gatherBillingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
{
$customerAddress = [];
@ -952,7 +952,7 @@ class Cart
* @param \Webkul\Checkout\Cart|null $cart
* @return array
*/
private function gatherShippingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
public function gatherShippingAddress($data, \Webkul\Checkout\Models\Cart $cart): array
{
$customerAddress = [];
@ -982,7 +982,7 @@ class Cart
* @param array $shippingAddressData
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
private function linkAddresses(
public function linkAddresses(
\Webkul\Checkout\Models\Cart $cart,
array $billingAddressData,
array $shippingAddressData