Skip to content

Commit

Permalink
Productwise Delivery Charge
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsumon4u committed Sep 4, 2024
1 parent 06c18fb commit d24d8b0
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 87 deletions.
2 changes: 1 addition & 1 deletion 7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN apt-get update \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& npm install -g npm@8.19.4 \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null \
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ProductController extends Controller
*/
public function __invoke(Request $request)
{
return DataTables::of($request->has('order') ? Product::whereNull('parent_id')->get() : Product::whereNull('parent_id')->latest('id'))
$query = $request->has('order') ? Product::whereNull('parent_id') : Product::whereNull('parent_id')->latest('id');

return DataTables::eloquent($query)
->addIndexColumn()
->addColumn('image', function (Product $product) {
return '<img src="' . asset(optional($product->base_image)->src) . '" width="100" height="100" />';
Expand Down
12 changes: 11 additions & 1 deletion app/Http/Livewire/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ private function shippingCost()
{
$shipping_cost = 0;
if ($this->shipping) {
$shipping_cost = setting('delivery_charge')->{$this->shipping == 'Inside Dhaka' ? 'inside_dhaka' : 'outside_dhaka'} ?? config('services.shipping.' . $this->shipping);
if (! setting('show_option')->productwise_delivery_charge) {
$shipping_cost = setting('delivery_charge')->{$this->shipping == 'Inside Dhaka' ? 'inside_dhaka' : 'outside_dhaka'} ?? config('services.shipping.' . $this->shipping);
} else {
$shipping_cost = collect($this->cart)->sum(function ($item) {
if ($this->shipping == 'Inside Dhaka') {
return $item['shipping_inside'] * (setting('show_option')->quantitywise_delivery_charge ? $item['quantity'] : 1);
} else {
return $item['shipping_outside'] * (setting('show_option')->quantitywise_delivery_charge ? $item['quantity'] : 1);
}
});
}
}

$freeDelivery = setting('free_delivery');
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/ProductCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function addToCart()
'quantity' => 1,
'price' => $this->product->selling_price,
'max' => $this->product->should_track ? min($this->product->stock_count, $fraudQuantity) : $fraudQuantity,
'shipping_inside' => $this->product->shipping_inside,
'shipping_outside' => $this->product->shipping_outside,
];
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/ProductDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function addToCart()
'quantity' => $quantity = min($this->quantity, $this->maxQuantity),
'price' => $this->selectedVar->getPrice($quantity),
'max' => $this->maxQuantity,
'shipping_inside' => $this->selectedVar->shipping_inside,
'shipping_outside' => $this->selectedVar->shipping_outside,
];
}

Expand Down
3 changes: 3 additions & 0 deletions app/Http/Requests/ProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function rules()
'additional_images' => 'sometimes|array',
'desc_img' => 'required|boolean',
'desc_img_pos' => 'required_if:desc_img,1',
'shipping_inside' => 'nullable|integer',
'shipping_outside' => 'nullable|integer',
'delivery_text' => 'nullable',
];

if (!$this->isMethod('POST')) {
Expand Down
14 changes: 13 additions & 1 deletion app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Product extends Model

protected $fillable = [
'brand_id', 'name', 'slug', 'description', 'price', 'selling_price', 'wholesale', 'sku',
'should_track', 'stock_count', 'desc_img', 'desc_img_pos', 'is_active',
'should_track', 'stock_count', 'desc_img', 'desc_img_pos', 'is_active', 'shipping_inside', 'shipping_outside', 'delivery_text',
];

/**
Expand Down Expand Up @@ -85,6 +85,18 @@ public function getVarNameAttribute()
return $this->parent->name . ' [' . $this->name . ']';
}

public function getShippingInsideAttribute($value)
{
if (!$this->parent_id) return $value ?? setting('delivery_charge')->inside_dhaka;
return $value ?? $this->parent->shipping_inside ?? setting('delivery_charge')->inside_dhaka;
}

public function getShippingOutsideAttribute($value)
{
if (!$this->parent_id) return $value ?? setting('delivery_charge')->outside_dhaka;
return $value ?? $this->parent->shipping_outside ?? setting('delivery_charge')->outside_dhaka;
}

public function getCategoryAttribute()
{
if ($this->parent_id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddDeliveryColumnsToProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->integer('shipping_inside')->nullable();
$table->integer('shipping_outside')->nullable();
$table->text('delivery_text')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products', function (Blueprint $table) {
$table->dropColumn(['shipping_inside', 'shipping_outside', 'delivery_text']);
});
}
}
Loading

0 comments on commit d24d8b0

Please sign in to comment.