Skip to content

Commit

Permalink
Added the further changes according to the code standard
Browse files Browse the repository at this point in the history
  • Loading branch information
antu chaudhary committed Apr 17, 2024
1 parent f173202 commit ae594d0
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 188 deletions.
46 changes: 25 additions & 21 deletions packages/Webkul/UpsShipping/src/Carriers/Ups.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,59 +27,63 @@ public function calculate()
return false;
}

$shippingMethods = [];
$shippingRates = [];

$cart = Cart::getCart();

$address = $cart->shipping_address;

$data = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper')->getAllCartProducts($address);
$shippingMethodHelper = app(ShippingMethodHelper::class);

$cartProductsShippingData = $shippingMethodHelper->getAllCartProducts($address);

if (! $data) {
if (! $cartProductsShippingData) {
return false;
}

foreach ($data as $key => $fedexServices) {
foreach ($cartProductsShippingData as $sellerId => $shippingMethods) {
$totalShippingCost = 0;

$sellerRates = [];

$rates = [];

foreach ($fedexServices as $methods => $upsRate) {
$itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity'];
$sellerId = $upsRate['marketplace_seller_id'];
foreach ($shippingMethods as $methodCode => $methodData) {
$itemShippingCost = $methodData['rate'] * $methodData['itemQuantity'];
$marketplaceSellerId = $methodData['marketplace_seller_id'];

$rates[$sellerId] = [
$sellerRates[$marketplaceSellerId] = [
'amount' => core()->convertPrice($itemShippingCost),
'base_amount' => $itemShippingCost,
];

$totalShippingCost += $itemShippingCost;
}

$object = new CartShippingRate;
$cartShippingRate = new CartShippingRate;

$object->carrier = 'mpups';
$cartShippingRate->carrier = 'mpups';

$object->carrier_title = $this->getConfigData('title');
$cartShippingRate->carrier_title = $this->getConfigData('title');

$object->method = 'mpups_' . $key;
$cartShippingRate->method = 'mpups_' . $sellerId;

$object->method_title = $this->getConfigData('title');
$cartShippingRate->method_title = $this->getConfigData('title');

$object->method_description = $key;
$cartShippingRate->method_description = $sellerId;

$object->price = core()->convertPrice($totalShippingCost);
$cartShippingRate->price = core()->convertPrice($totalShippingCost);

$object->base_price = $totalShippingCost;
$cartShippingRate->base_price = $totalShippingCost;

$shippingMethods[] = $object;
$shippingRates[] = $cartShippingRate;

// Store rates in session
$marketplaceShippingRates = session()->get('marketplace_shipping_rates', []);

$marketplaceShippingRates['mpupsshipping'][$key] = $rates;
$marketplaceShippingRates['mpupsshipping'][$sellerId] = $sellerRates;

session()->put('marketplace_shipping_rates', $marketplaceShippingRates);
}

return $shippingMethods;
return $shippingRates;
}
}
Loading

0 comments on commit ae594d0

Please sign in to comment.