diff --git a/config/app.php b/config/app.php index a3cf7f964..1f0b07847 100755 --- a/config/app.php +++ b/config/app.php @@ -104,7 +104,7 @@ return [ | */ - 'default_country' => null, + 'default_country' => 'DE', /* |-------------------------------------------------------------------------- diff --git a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php index a1b28cbd0..499fbfe74 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php @@ -266,7 +266,7 @@ @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -344,11 +344,14 @@ @endif - - {{ __('admin::app.sales.orders.tax') }} + @php ($taxRates = Webkul\Checkout\Helpers\Tax::getTaxRatesWithAmount($order, true)) + @foreach ($taxRates as $taxRate => $baseTaxAmount) + last ? 'class=border' : ''}}> + {{ __('admin::app.sales.orders.tax') }} {{ $taxRate }} % - - {{ core()->formatBasePrice($order->base_tax_amount) }} + {{ core()->formatBasePrice($baseTaxAmount) }} + @endforeach {{ __('admin::app.sales.orders.grand-total') }} diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 9157dc392..c6eca6000 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -5,6 +5,7 @@ namespace Webkul\Checkout; use Webkul\Checkout\Repositories\CartRepository; use Webkul\Checkout\Repositories\CartItemRepository; use Webkul\Checkout\Repositories\CartAddressRepository; +use Webkul\Customer\Models\CustomerAddress; use Webkul\Product\Repositories\ProductRepository; use Webkul\Tax\Repositories\TaxCategoryRepository; use Webkul\Checkout\Models\CartItem; @@ -14,6 +15,17 @@ use Webkul\Customer\Repositories\CustomerAddressRepository; use Illuminate\Support\Facades\Event; use Illuminate\Support\Arr; +class addressHelper +{ + public $country; + public $postcode; + + function __construct() + { + $this->country = config('app.default_country'); + } +} + /** * Facades handler for all the methods to be implemented in Cart. * @@ -21,7 +33,8 @@ use Illuminate\Support\Arr; * @author Jitendra Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class Cart { +class Cart +{ /** * CartRepository instance @@ -75,15 +88,16 @@ class Cart { /** * Create a new controller instance. * - * @param Webkul\Checkout\Repositories\CartRepository $cart - * @param Webkul\Checkout\Repositories\CartItemRepository $cartItem - * @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress - * @param Webkul\Product\Repositories\ProductRepository $product - * @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory - * @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress - * @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress - * @param Webkul\Discount\Repositories\CartRuleRepository $cartRule - * @param Webkul\Helpers\Discount $discount + * @param Webkul\Checkout\Repositories\CartRepository $cart + * @param Webkul\Checkout\Repositories\CartItemRepository $cartItem + * @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress + * @param Webkul\Product\Repositories\ProductRepository $product + * @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory + * @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress + * @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress + * @param Webkul\Discount\Repositories\CartRuleRepository $cartRule + * @param Webkul\Helpers\Discount $discount + * * @return void */ public function __construct( @@ -94,8 +108,7 @@ class Cart { TaxCategoryRepository $taxCategoryRepository, WishlistRepository $wishlistRepository, CustomerAddressRepository $customerAddressRepository - ) - { + ) { $this->cartRepository = $cartRepository; $this->cartItemRepository = $cartItemRepository; @@ -128,6 +141,7 @@ class Cart { * * @param integer $productId * @param array $data + * * @return Cart */ public function addProduct($productId, $data) @@ -136,8 +150,9 @@ class Cart { $cart = $this->getCart(); - if (! $cart && ! $cart = $this->create($data)) + if (!$cart && !$cart = $this->create($data)) { return; + } $product = $this->productRepository->findOneByField('id', $productId); @@ -146,7 +161,7 @@ class Cart { if (is_string($cartProducts)) { $this->collectTotals(); - if (! count($cart->all_items) > 0) { + if (!count($cart->all_items) > 0) { session()->forget('cart'); } @@ -157,21 +172,24 @@ class Cart { foreach ($cartProducts as $cartProduct) { $cartItem = $this->getItemByProduct($cartProduct); - if (isset($cartProduct['parent_id'])) + if (isset($cartProduct['parent_id'])) { $cartProduct['parent_id'] = $parentCartItem->id; + } - if (! $cartItem) { + if (!$cartItem) { $cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id])); } else { if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) { - $cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id])); + $cartItem = $this->cartItemRepository->create(array_merge($cartProduct, + ['cart_id' => $cart->id])); } else { $cartItem = $this->cartItemRepository->update($cartProduct, $cartItem->id); } } - if (! $parentCartItem) + if (!$parentCartItem) { $parentCartItem = $cartItem; + } } } @@ -186,17 +204,18 @@ class Cart { * Create new cart instance. * * @param array $data + * * @return Cart|null */ public function create($data) { $cartData = [ - 'channel_id' => core()->getCurrentChannel()->id, - 'global_currency_code' => core()->getBaseCurrencyCode(), - 'base_currency_code' => core()->getBaseCurrencyCode(), + 'channel_id' => core()->getCurrentChannel()->id, + 'global_currency_code' => core()->getBaseCurrencyCode(), + 'base_currency_code' => core()->getBaseCurrencyCode(), 'channel_currency_code' => core()->getChannelBaseCurrencyCode(), - 'cart_currency_code' => core()->getCurrentCurrencyCode(), - 'items_count' => 1 + 'cart_currency_code' => core()->getCurrentCurrencyCode(), + 'items_count' => 1, ]; //Authentication details @@ -212,7 +231,7 @@ class Cart { $cart = $this->cartRepository->create($cartData); - if (! $cart) { + if (!$cart) { session()->flash('error', trans('shop::app.checkout.cart.create-error')); return; @@ -235,8 +254,9 @@ class Cart { foreach ($data['qty'] as $itemId => $quantity) { $item = $this->cartItemRepository->findOneByField('id', $itemId); - if (! $item) + if (!$item) { continue; + } if ($quantity <= 0) { $this->removeItem($itemId); @@ -246,18 +266,19 @@ class Cart { $item->quantity = $quantity; - if (! $this->isItemHaveQuantity($item)) + if (!$this->isItemHaveQuantity($item)) { throw new \Exception(trans('shop::app.checkout.cart.quantity.inventory_warning')); + } Event::dispatch('checkout.cart.update.before', $item); $this->cartItemRepository->update([ - 'quantity' => $quantity, - 'total' => core()->convertPrice($item->price * $quantity), - 'base_total' => $item->price * $quantity, - 'total_weight' => $item->weight * $quantity, - 'base_total_weight' => $item->weight * $quantity - ], $itemId); + 'quantity' => $quantity, + 'total' => core()->convertPrice($item->price * $quantity), + 'base_total' => $item->price * $quantity, + 'total_weight' => $item->weight * $quantity, + 'base_total_weight' => $item->weight * $quantity, + ], $itemId); Event::dispatch('checkout.cart.update.after', $item); } @@ -271,6 +292,7 @@ class Cart { * Get cart item by product * * @param array $data + * * @return CartItem|void */ public function getItemByProduct($data) @@ -280,8 +302,10 @@ class Cart { foreach ($items as $item) { if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional'])) { if (isset($data['additional']['parent_id'])) { - if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, request()->all())) + if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, + request()->all())) { return $item; + } } else { return $item; } @@ -293,14 +317,16 @@ class Cart { * Remove the item from the cart * * @param integer $itemId + * * @return boolean */ public function removeItem($itemId) { Event::dispatch('checkout.cart.delete.before', $itemId); - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } $this->cartItemRepository->delete($itemId); @@ -328,18 +354,21 @@ class Cart { public function mergeCart() { if (session()->has('cart')) { - $cart = $this->cartRepository->findOneWhere(['customer_id' => $this->getCurrentCustomer()->user()->id, 'is_active' => 1]); + $cart = $this->cartRepository->findOneWhere([ + 'customer_id' => $this->getCurrentCustomer()->user()->id, + 'is_active' => 1, + ]); $guestCart = session()->get('cart'); //when the logged in customer is not having any of the cart instance previously and are active. - if (! $cart) { + if (!$cart) { $this->cartRepository->update([ - 'customer_id' => $this->getCurrentCustomer()->user()->id, - 'is_guest' => 0, + 'customer_id' => $this->getCurrentCustomer()->user()->id, + 'is_guest' => 0, 'customer_first_name' => $this->getCurrentCustomer()->user()->first_name, - 'customer_last_name' => $this->getCurrentCustomer()->user()->last_name, - 'customer_email' => $this->getCurrentCustomer()->user()->email + 'customer_last_name' => $this->getCurrentCustomer()->user()->last_name, + 'customer_email' => $this->getCurrentCustomer()->user()->email, ], $guestCart->id); session()->forget('cart'); @@ -352,23 +381,25 @@ class Cart { $found = false; foreach ($cart->items as $cartItem) { - if (! $cartItem->product->getTypeInstance()->compareOptions($cartItem->additional, $guestCartItem->additional)) + if (!$cartItem->product->getTypeInstance()->compareOptions($cartItem->additional, + $guestCartItem->additional)) { continue; + } $cartItem->quantity = $newQuantity = $cartItem->quantity + $guestCartItem->quantity; - if (! $this->isItemHaveQuantity($cartItem)) { + if (!$this->isItemHaveQuantity($cartItem)) { $this->cartItemRepository->delete($guestCartItem->id); continue; } $this->cartItemRepository->update([ - 'quantity' => $newQuantity, - 'total' => core()->convertPrice($cartItem->price * $newQuantity), - 'base_total' => $cartItem->price * $newQuantity, - 'total_weight' => $cartItem->weight * $newQuantity, - 'base_total_weight' => $cartItem->weight * $newQuantity + 'quantity' => $newQuantity, + 'total' => core()->convertPrice($cartItem->price * $newQuantity), + 'base_total' => $cartItem->price * $newQuantity, + 'total_weight' => $cartItem->weight * $newQuantity, + 'base_total_weight' => $cartItem->weight * $newQuantity, ], $cartItem->id); $guestCart->items->forget($key); @@ -378,14 +409,14 @@ class Cart { $found = true; } - if (! $found) { + if (!$found) { $this->cartItemRepository->update([ - 'cart_id' => $cart->id + 'cart_id' => $cart->id, ], $guestCartItem->id); foreach ($guestCartItem->children as $child) { $this->cartItemRepository->update([ - 'cart_id' => $cart->id + 'cart_id' => $cart->id, ], $child->id); } } @@ -405,11 +436,12 @@ class Cart { * Save cart * * @param Cart $cart + * * @return void */ public function putCart($cart) { - if (! $this->getCurrentCustomer()->check()) { + if (!$this->getCurrentCustomer()->check()) { session()->put('cart', $cart); } } @@ -426,7 +458,7 @@ class Cart { if ($this->getCurrentCustomer()->check()) { $cart = $this->cartRepository->findOneWhere([ 'customer_id' => $this->getCurrentCustomer()->user()->id, - 'is_active' => 1 + 'is_active' => 1, ]); } elseif (session()->has('cart')) { $cart = $this->cartRepository->find(session()->get('cart')->id); @@ -465,18 +497,20 @@ class Cart { * Save customer address * * @param array $data + * * @return boolean */ public function saveCustomerAddress($data) { - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } $billingAddress = $data['billing']; $billingAddress['cart_id'] = $cart->id; if (isset($data['billing']['address_id']) && $data['billing']['address_id']) { - $address = $this->customerAddressRepository->findOneWhere(['id'=> $data['billing']['address_id']])->toArray(); + $address = $this->customerAddressRepository->findOneWhere(['id' => $data['billing']['address_id']])->toArray(); $billingAddress['first_name'] = $this->getCurrentCustomer()->user()->first_name; $billingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name; @@ -490,7 +524,7 @@ class Cart { } if (isset($data['billing']['save_as_address']) && $data['billing']['save_as_address']) { - $billingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id; + $billingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id; $this->customerAddressRepository->create($billingAddress); } @@ -499,7 +533,7 @@ class Cart { $shippingAddress['cart_id'] = $cart->id; if (isset($data['shipping']['address_id']) && $data['shipping']['address_id']) { - $address = $this->customerAddressRepository->findOneWhere(['id'=> $data['shipping']['address_id']])->toArray(); + $address = $this->customerAddressRepository->findOneWhere(['id' => $data['shipping']['address_id']])->toArray(); $shippingAddress['first_name'] = $this->getCurrentCustomer()->user()->first_name; $shippingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name; @@ -513,7 +547,7 @@ class Cart { } if (isset($data['shipping']['save_as_address']) && $data['shipping']['save_as_address']) { - $shippingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id; + $shippingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id; $this->customerAddressRepository->create($shippingAddress); } @@ -531,9 +565,11 @@ class Cart { } } else { if (isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { - $this->cartAddressRepository->create(array_merge($billingAddress, ['address_type' => 'shipping'])); + $this->cartAddressRepository->create(array_merge($billingAddress, + ['address_type' => 'shipping'])); } else { - $this->cartAddressRepository->create(array_merge($shippingAddress, ['address_type' => 'shipping'])); + $this->cartAddressRepository->create(array_merge($shippingAddress, + ['address_type' => 'shipping'])); } } } @@ -568,12 +604,14 @@ class Cart { * Save shipping method for cart * * @param string $shippingMethodCode + * * @return boolean */ public function saveShippingMethod($shippingMethodCode) { - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } $cart->shipping_method = $shippingMethodCode; $cart->save(); @@ -585,15 +623,18 @@ class Cart { * Save payment method for cart * * @param string $payment + * * @return CartPayment */ public function savePaymentMethod($payment) { - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } - if ($cartPayment = $cart->payment) + if ($cartPayment = $cart->payment) { $cartPayment->delete(); + } $cartPayment = new CartPayment; @@ -613,11 +654,13 @@ class Cart { { $validated = $this->validateItems(); - if (! $validated) + if (!$validated) { return false; + } - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } Event::dispatch('checkout.cart.collect.totals.before', $cart); @@ -632,19 +675,19 @@ class Cart { $cart->discount_amount += $item->discount_amount; $cart->base_discount_amount += $item->base_discount_amount; - $cart->grand_total = (float) $cart->grand_total + $item->total + $item->tax_amount - $item->discount_amount; - $cart->base_grand_total = (float) $cart->base_grand_total + $item->base_total + $item->base_tax_amount - $item->base_discount_amount; + $cart->grand_total = (float)$cart->grand_total + $item->total + $item->tax_amount - $item->discount_amount; + $cart->base_grand_total = (float)$cart->base_grand_total + $item->base_total + $item->base_tax_amount - $item->base_discount_amount; - $cart->sub_total = (float) $cart->sub_total + $item->total; - $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_total; + $cart->sub_total = (float)$cart->sub_total + $item->total; + $cart->base_sub_total = (float)$cart->base_sub_total + $item->base_total; - $cart->tax_total = (float) $cart->tax_total + $item->tax_amount; - $cart->base_tax_total = (float) $cart->base_tax_total + $item->base_tax_amount; + $cart->tax_total = (float)$cart->tax_total + $item->tax_amount; + $cart->base_tax_total = (float)$cart->base_tax_total + $item->base_tax_amount; } if ($shipping = $cart->selected_shipping_rate) { - $cart->grand_total = (float) $cart->grand_total + $shipping->price - $shipping->discount_amount; - $cart->base_grand_total = (float) $cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount; + $cart->grand_total = (float)$cart->grand_total + $shipping->price - $shipping->discount_amount; + $cart->base_grand_total = (float)$cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount; $cart->discount_amount += $shipping->discount_amount; $cart->base_discount_amount += $shipping->base_discount_amount; @@ -673,8 +716,9 @@ class Cart { */ public function validateItems() { - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return; + } //rare case of accident-->used when there are no items. if (count($cart->items) == 0) { @@ -685,12 +729,12 @@ class Cart { foreach ($cart->items as $item) { $item->product->getTypeInstance()->validateCartItem($item); - $price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price; + $price = !is_null($item->custom_price) ? $item->custom_price : $item->base_price; $this->cartItemRepository->update([ - 'price' => core()->convertPrice($price), + 'price' => core()->convertPrice($price), 'base_price' => $price, - 'total' => core()->convertPrice($price * $item->quantity), + 'total' => core()->convertPrice($price * $item->quantity), 'base_total' => $price * $item->quantity, ], $item->id); } @@ -706,17 +750,19 @@ class Cart { */ public function calculateItemsTax() { - if (! $cart = $this->getCart()) + if (!$cart = $this->getCart()) { return false; + } - if (! $cart->shipping_address && ! $cart->billing_address) - return; +// if (! $cart->shipping_address && ! $cart->billing_address) +// return; foreach ($cart->items()->get() as $item) { $taxCategory = $this->taxCategoryRepository->find($item->product->tax_category_id); - if (! $taxCategory) + if (!$taxCategory) { continue; + } if ($item->product->getTypeInstance()->isStockable()) { $address = $cart->shipping_address; @@ -724,25 +770,30 @@ class Cart { $address = $cart->billing_address; } + if ($address === null) { + $address = new addressHelper(); + } + $taxRates = $taxCategory->tax_rates()->where([ - 'country' => $address->country, - ])->orderBy('tax_rate', 'desc')->get(); + 'country' => $address->country, + ])->orderBy('tax_rate', 'desc')->get(); if ($taxRates->count()) { foreach ($taxRates as $rate) { $haveTaxRate = false; - if ($rate->state != '' && $rate->state != $address->state) + if ($rate->state != '' && $rate->state != $address->state) { continue; - - if (! $rate->is_zip) { - if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) - $haveTaxRate = true; - } else { - if ($address->postcode >= $rate->zip_from && $address->postcode <= $rate->zip_to) - $haveTaxRate = true; } - + if (!$rate->is_zip) { + if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) { + $haveTaxRate = true; + } + } else { + if ($address->postcode >= $rate->zip_from && $address->postcode <= $rate->zip_to) { + $haveTaxRate = true; + } + } if ($haveTaxRate) { $item->tax_percent = $rate->tax_rate; $item->tax_amount = ($item->total * $rate->tax_rate) / 100; @@ -769,11 +820,13 @@ class Cart { */ public function hasError() { - if (! $this->getCart()) + if (!$this->getCart()) { return true; + } - if (! $this->isItemsHaveSufficientQuantity()) + if (!$this->isItemsHaveSufficientQuantity()) { return true; + } return false; } @@ -786,8 +839,9 @@ class Cart { public function isItemsHaveSufficientQuantity() { foreach ($this->getCart()->items as $item) { - if (! $this->isItemHaveQuantity($item)) + if (!$this->isItemHaveQuantity($item)) { return false; + } } return true; @@ -797,6 +851,7 @@ class Cart { * Checks if all cart items have sufficient quantity. * * @param CartItem $item + * * @return boolean */ public function isItemHaveQuantity($item) @@ -830,42 +885,42 @@ class Cart { $data = $this->toArray(); $finalData = [ - 'cart_id' => $this->getCart()->id, - 'customer_id' => $data['customer_id'], - 'is_guest' => $data['is_guest'], - 'customer_email' => $data['customer_email'], - 'customer_first_name' => $data['customer_first_name'], - 'customer_last_name' => $data['customer_last_name'], - 'customer' => $this->getCurrentCustomer()->check() ? $this->getCurrentCustomer()->user() : null, - 'total_item_count' => $data['items_count'], - 'total_qty_ordered' => $data['items_qty'], - 'base_currency_code' => $data['base_currency_code'], + 'cart_id' => $this->getCart()->id, + 'customer_id' => $data['customer_id'], + 'is_guest' => $data['is_guest'], + 'customer_email' => $data['customer_email'], + 'customer_first_name' => $data['customer_first_name'], + 'customer_last_name' => $data['customer_last_name'], + 'customer' => $this->getCurrentCustomer()->check() ? $this->getCurrentCustomer()->user() : null, + 'total_item_count' => $data['items_count'], + 'total_qty_ordered' => $data['items_qty'], + 'base_currency_code' => $data['base_currency_code'], 'channel_currency_code' => $data['channel_currency_code'], - 'order_currency_code' => $data['cart_currency_code'], - 'grand_total' => $data['grand_total'], - 'base_grand_total' => $data['base_grand_total'], - 'sub_total' => $data['sub_total'], - 'base_sub_total' => $data['base_sub_total'], - 'tax_amount' => $data['tax_total'], - 'base_tax_amount' => $data['base_tax_total'], - 'coupon_code' => $data['coupon_code'], + 'order_currency_code' => $data['cart_currency_code'], + 'grand_total' => $data['grand_total'], + 'base_grand_total' => $data['base_grand_total'], + 'sub_total' => $data['sub_total'], + 'base_sub_total' => $data['base_sub_total'], + 'tax_amount' => $data['tax_total'], + 'base_tax_amount' => $data['base_tax_total'], + 'coupon_code' => $data['coupon_code'], 'applied_cart_rule_ids' => $data['applied_cart_rule_ids'], - 'discount_amount' => $data['discount_amount'], - 'base_discount_amount' => $data['base_discount_amount'], - 'billing_address' => Arr::except($data['billing_address'], ['id', 'cart_id']), - 'payment' => Arr::except($data['payment'], ['id', 'cart_id']), - 'channel' => core()->getCurrentChannel(), + 'discount_amount' => $data['discount_amount'], + 'base_discount_amount' => $data['base_discount_amount'], + 'billing_address' => Arr::except($data['billing_address'], ['id', 'cart_id']), + 'payment' => Arr::except($data['payment'], ['id', 'cart_id']), + 'channel' => core()->getCurrentChannel(), ]; if ($this->getCart()->haveStockableItems()) { $finalData = array_merge($finalData, [ - 'shipping_method' => $data['selected_shipping_rate']['method'], - 'shipping_title' => $data['selected_shipping_rate']['carrier_title'] . ' - ' . $data['selected_shipping_rate']['method_title'], - 'shipping_description' => $data['selected_shipping_rate']['method_description'], - 'shipping_amount' => $data['selected_shipping_rate']['price'], - 'base_shipping_amount' => $data['selected_shipping_rate']['base_price'], - 'shipping_address' => Arr::except($data['shipping_address'], ['id', 'cart_id']), - 'shipping_discount_amount' => $data['selected_shipping_rate']['discount_amount'], + 'shipping_method' => $data['selected_shipping_rate']['method'], + 'shipping_title' => $data['selected_shipping_rate']['carrier_title'] . ' - ' . $data['selected_shipping_rate']['method_title'], + 'shipping_description' => $data['selected_shipping_rate']['method_description'], + 'shipping_amount' => $data['selected_shipping_rate']['price'], + 'base_shipping_amount' => $data['selected_shipping_rate']['base_price'], + 'shipping_address' => Arr::except($data['shipping_address'], ['id', 'cart_id']), + 'shipping_discount_amount' => $data['selected_shipping_rate']['discount_amount'], 'base_shipping_discount_amount' => $data['selected_shipping_rate']['base_discount_amount'], ]); } @@ -881,29 +936,30 @@ class Cart { * Prepares data for order item * * @param array $data + * * @return array */ public function prepareDataForOrderItem($data) { $finalData = [ - 'product' => $this->productRepository->find($data['product_id']), - 'sku' => $data['sku'], - 'type' => $data['type'], - 'name' => $data['name'], - 'weight' => $data['weight'], - 'total_weight' => $data['total_weight'], - 'qty_ordered' => $data['quantity'], - 'price' => $data['price'], - 'base_price' => $data['base_price'], - 'total' => $data['total'], - 'base_total' => $data['base_total'], - 'tax_percent' => $data['tax_percent'], - 'tax_amount' => $data['tax_amount'], - 'base_tax_amount' => $data['base_tax_amount'], - 'discount_percent' => $data['discount_percent'], - 'discount_amount' => $data['discount_amount'], + 'product' => $this->productRepository->find($data['product_id']), + 'sku' => $data['sku'], + 'type' => $data['type'], + 'name' => $data['name'], + 'weight' => $data['weight'], + 'total_weight' => $data['total_weight'], + 'qty_ordered' => $data['quantity'], + 'price' => $data['price'], + 'base_price' => $data['base_price'], + 'total' => $data['total'], + 'base_total' => $data['base_total'], + 'tax_percent' => $data['tax_percent'], + 'tax_amount' => $data['tax_amount'], + 'base_tax_amount' => $data['base_tax_amount'], + 'discount_percent' => $data['discount_percent'], + 'discount_amount' => $data['discount_amount'], 'base_discount_amount' => $data['base_discount_amount'], - 'additional' => $data['additional'], + 'additional' => $data['additional'], ]; if (isset($data['children']) && $data['children']) { @@ -921,15 +977,18 @@ class Cart { * Move a wishlist item to cart * * @param WishlistItem $wishlistItem + * * @return boolean */ public function moveToCart($wishlistItem) { - if (! $wishlistItem->product->getTypeInstance()->canBeMovedFromWishlistToCart($wishlistItem)) + if (!$wishlistItem->product->getTypeInstance()->canBeMovedFromWishlistToCart($wishlistItem)) { return false; + } - if (! $wishlistItem->additional) + if (!$wishlistItem->additional) { $wishlistItem->additional = ['product_id' => $wishlistItem->product_id]; + } request()->merge($wishlistItem->additional); @@ -948,6 +1007,7 @@ class Cart { * Function to move a already added product to wishlist will run only on customer authentication. * * @param integer $itemId + * * @return boolean|void */ public function moveToWishlist($itemId) @@ -956,34 +1016,38 @@ class Cart { $cartItem = $cart->items()->find($itemId); - if (! $cartItem) + if (!$cartItem) { return false; + } $wishlistItems = $this->wishlistRepository->findWhere([ - 'customer_id' => $this->getCurrentCustomer()->user()->id, - 'product_id' => $cartItem->product_id - ]); + 'customer_id' => $this->getCurrentCustomer()->user()->id, + 'product_id' => $cartItem->product_id, + ]); $found = false; foreach ($wishlistItems as $wishlistItem) { - if ($cartItem->product->getTypeInstance()->compareOptions($cartItem->additional, $wishlistItem->item_options)) + if ($cartItem->product->getTypeInstance()->compareOptions($cartItem->additional, + $wishlistItem->item_options)) { $found = true; + } } - if (! $found) { + if (!$found) { $this->wishlistRepository->create([ - 'channel_id' => $cart->channel_id, - 'customer_id' => $this->getCurrentCustomer()->user()->id, - 'product_id' => $cartItem->product_id, - 'additional' => $cartItem->additional - ]); + 'channel_id' => $cart->channel_id, + 'customer_id' => $this->getCurrentCustomer()->user()->id, + 'product_id' => $cartItem->product_id, + 'additional' => $cartItem->additional, + ]); } $result = $this->cartItemRepository->delete($itemId); - if (! $cart->items()->count()) + if (!$cart->items()->count()) { $this->cartRepository->delete($cart->id); + } $this->collectTotals(); @@ -994,6 +1058,7 @@ class Cart { * Set coupon code to the cart * * @param string $code + * * @return Cart */ public function setCouponCode($code) diff --git a/packages/Webkul/Checkout/src/Helpers/Tax.php b/packages/Webkul/Checkout/src/Helpers/Tax.php new file mode 100644 index 000000000..2b4a28523 --- /dev/null +++ b/packages/Webkul/Checkout/src/Helpers/Tax.php @@ -0,0 +1,31 @@ +items as $item) { + $taxRate = (string)round((float)$item->tax_percent, self::TAX_PRECISION); + + if (array_key_exists($taxRate, $taxes)) { + $taxes[$taxRate] += $asBase ? $item->base_tax_amount : $item->tax_amount; + } else { + $taxes += [$taxRate => $asBase ? $item->base_tax_amount : $item->tax_amount]; + } + } + + return $taxes; + } +} \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 70d5d87d6..c1feb3508 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -18,10 +18,12 @@ @endif @if ($cart->base_tax_total) + @foreach (Webkul\Checkout\Helpers\Tax::getTaxRatesWithAmount($cart, false) as $taxRate => $taxAmount )
- - + +
+ @endforeach @endif
base_discount_amount && $cart->base_discount_amount > 0) style="display: block;" @else style="display: none;" @endif> diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php index 9e913b50b..a3b952743 100644 --- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php @@ -123,7 +123,7 @@ @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -161,12 +161,14 @@
+ @foreach (Webkul\Checkout\Helpers\Tax::getTaxRatesWithAmount($order, true) as $taxRate => $baseTaxAmount )
- {{ __('shop::app.mail.order.tax') }} - - {{ core()->formatBasePrice($order->base_tax_amount) }} + {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} % + + {{ core()->formatBasePrice($baseTaxAmount) }}
+ @endforeach @if ($order->discount_amount > 0)
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php index 55b0d5264..8cba444fe 100755 --- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php @@ -115,10 +115,10 @@ {{ $item->name }} - + @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -146,7 +146,7 @@ {{ core()->formatPrice($invoice->sub_total, $invoice->order_currency_code) }}
- + @if ($order->shipping_address)
{{ __('shop::app.mail.order.shipping-handling') }} @@ -156,12 +156,14 @@
@endif -
- {{ __('shop::app.mail.order.tax') }} - - {{ core()->formatPrice($invoice->tax_amount, $invoice->order_currency_code) }} + @foreach ($order->getTaxRatesWithAmount(false) as $taxRate => $taxAmount) +
+ {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} % + + {{ core()->formatPrice($taxAmount, $order->order_currency_code) }} -
+
+ @endforeach @if ($invoice->discount_amount > 0)
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php index 2d848b5ca..f2ca139b0 100755 --- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php @@ -116,10 +116,10 @@ {{ $item->name }} - + @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -156,12 +156,14 @@
@endif + @foreach (Webkul\Checkout\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
- {{ __('shop::app.mail.order.tax') }} - - {{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }} + {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} % + + {{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
+ @endforeach @if ($order->discount_amount > 0)
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-refund.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-refund.blade.php index d80d9937d..604d2f65b 100644 --- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-refund.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-refund.blade.php @@ -115,10 +115,10 @@ {{ $item->name }} - + @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -158,7 +158,7 @@
@endif - +@php(//ToDo: taxes) @if ($refund->tax_amount > 0)
{{ __('shop::app.mail.order.tax') }} diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php index cd6b9600e..19e677626 100644 --- a/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php @@ -119,7 +119,7 @@ @if (isset($item->additional['attributes']))
- + @foreach ($item->additional['attributes'] as $attribute) {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach @@ -157,12 +157,14 @@
-
- {{ __('shop::app.mail.order.cancel.tax') }} - - {{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }} + @foreach (Webkul\Checkout\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount ) +
+ {{ __('shop::app.mail.order.cancel.tax') }} {{ $taxRate }} % + + {{ core()->formatPrice($taxAmount, $order->order_currency_code) }} -
+
+ @endforeach @if ($order->discount_amount > 0)