invoice fx

This commit is contained in:
merdan 2022-11-17 12:29:01 +05:00
parent 0adc050a14
commit 79c1183612
2 changed files with 46 additions and 1 deletions

View File

@ -5,6 +5,7 @@ namespace Sarga\API\Http\Resources\Checkout;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Log;
use Sarga\API\Http\Resources\Customer\AddressResource;
use Webkul\CartRule\Repositories\CartRuleRepository;
use Webkul\Marketplace\Repositories\ProductRepository;
use Webkul\Tax\Helpers\Tax;
@ -13,6 +14,7 @@ class CartResource extends JsonResource
public function __construct($resource)
{
$this->sellerProductRepository = app(ProductRepository::class);
$this->cartRuleRepository = app(CartRuleRepository::class);
parent::__construct($resource);
}
/**
@ -46,7 +48,8 @@ class CartResource extends JsonResource
'payment' => new CartPaymentResource($this->payment),
'billing_address' => new AddressResource($this->billing_address),
'shipping_address' => new AddressResource($this->shipping_address),
'formatted_discounted_sub_total' => core()->formatPrice($this->base_sub_total - $this->base_discount_amount, $this->cart_currency_code)
'formatted_discounted_sub_total' => core()->formatPrice($this->base_sub_total - $this->base_discount_amount, $this->cart_currency_code),
'cart_rules' => $this->cartRules(),
];
}
@ -72,6 +75,23 @@ class CartResource extends JsonResource
return $result;
}
private function cartRules(){
$ruleResources = array();
if($this->applied_cart_rule_ids){
$rule_ids =implode(',',$this->applied_cart_rule_ids);
$cols = ['id','name','description','action_type','amount'];
$cartRules = $this->cartRuleRepository->findWhereIn('applied_cart_rule_ids',$rule_ids,$cols);
foreach($cartRules as $rule){
$ruleResources [] = new CartRuleResource($rule,$this->cart_currency_code);
}
}
return $ruleResources;
}
private function groupByVendors($items){
$data = array();
foreach($items as $item){

View File

@ -0,0 +1,25 @@
<?php
namespace Sarga\API\Http\Resources\Checkout;
use Illuminate\Http\Resources\Json\JsonResource;
class CartRuleResource extends JsonResource
{
public function __construct($resource,$currency){
parent::__construct($resource);
$this->currency = $currency;
}
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'action_type' => $this->action_type,
'amount' => str_contains($this->action_type,'fixed')? core()->formatPrice($this->discount_amount, $this->currency):$this->discount_amount.'%'
];
}
}