Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo Matteo Riggio committed Oct 16, 2020
1 parent 0354466 commit f62f442
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/app/Http/Controllers/Api/Brand/ReadController.php
Expand Up @@ -48,6 +48,8 @@ public function getListPaginated( Request $request )

$query->orderBy($sort, $direction);

$total = $query->count();

if ( $limit ) {
$query->take($limit);
}
Expand All @@ -58,7 +60,7 @@ public function getListPaginated( Request $request )

$brands = $query->get();

return response()->json( [ 'result' => 'ok', 'brands' => $brands ]);
return response()->json( [ 'result' => 'ok', 'brands' => $brands, 'total' => $total ]);
}


Expand Down
5 changes: 3 additions & 2 deletions src/app/Http/Controllers/Api/Campaign/ReadController.php
Expand Up @@ -28,7 +28,6 @@ public function getListPaginated( Request $request )
$sort = $request->input('sort');
$direction = $request->input('direction');


if ( !$sort ) {
$sort = 'id';
}
Expand All @@ -41,6 +40,8 @@ public function getListPaginated( Request $request )
$query->with('campaign_template');
$query->orderBy($sort, $direction);

$total = $query->count();

if ( $limit ) {
$query->take($limit);
}
Expand All @@ -57,7 +58,7 @@ public function getListPaginated( Request $request )
}
}

return response()->json( [ 'result' => 'ok', 'campaigns' => $campaigns ]);
return response()->json( [ 'result' => 'ok', 'campaigns' => $campaigns, 'total' => $total ]);
}


Expand Down
Expand Up @@ -38,6 +38,8 @@ public function getListPaginated( Request $request )
$query = CampaignTemplate::query();
$query->orderBy($sort, $direction);

$total = $query->count();

if ( $limit ) {
$query->take($limit);
}
Expand All @@ -48,7 +50,7 @@ public function getListPaginated( Request $request )

$campaignTemplates = $query->get();

return response()->json( [ 'result' => 'ok', 'campaign_templates' => $campaignTemplates ]);
return response()->json( [ 'result' => 'ok', 'campaign_templates' => $campaignTemplates, 'total' => $total ]);
}


Expand Down
6 changes: 4 additions & 2 deletions src/app/Http/Controllers/Api/DiscountCode/ReadController.php
Expand Up @@ -44,6 +44,8 @@ public function getListPaginated( Request $request )
$query->with('customer.profile');
$query->orderBy($sort, $direction);

$total = $query->count();

if ( $limit ) {
$query->take($limit);
}
Expand All @@ -52,9 +54,9 @@ public function getListPaginated( Request $request )
$query->skip($offset);
}

$products = $query->get();
$discountCodes = $query->get();

return response()->json( [ 'result' => 'ok', 'discount_codes' => $products ]);
return response()->json( [ 'result' => 'ok', 'discount_codes' => $discountCodes, 'total' => $total ]);
}


Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/Api/Order/ReadController.php
Expand Up @@ -83,6 +83,7 @@ public function getListPaginated( Request $request )
$query->orderBy($sort, $direction);
}

$total = $query->count();

if ( $limit ) {
$query->take($limit);
Expand All @@ -93,7 +94,6 @@ public function getListPaginated( Request $request )
}

$orders = $query->get();
$total = ( $filtersActive ? $orders->count() : Order::count() );

return response()->json( [ 'result' => 'ok', 'orders' => $orders, 'total' => $total ]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/Http/Controllers/Api/Product/ReadController.php
Expand Up @@ -68,7 +68,7 @@ public function getListPaginated( Request $request )

}

$totalCountQuery = clone $query;
$total = $query->count();

$query->orderBy($sort, $direction);

Expand All @@ -82,7 +82,7 @@ public function getListPaginated( Request $request )

$products = $query->get();

return response()->json( [ 'result' => 'ok', 'products' => $products, 'total' => $totalCountQuery->count() ]);
return response()->json( [ 'result' => 'ok', 'products' => $products, 'total' => $total ]);
}


Expand Down
Expand Up @@ -37,6 +37,7 @@ private function _redirectHome( Request $request )
$request->session()->remove('shipping');
}

// TODO: redirect to shop cart
return redirect('/');
}

Expand Down Expand Up @@ -470,7 +471,7 @@ public function getShipping( Request $request, $countryCode = null )

return $request->wantsJson() ? json_encode([
'result' => 'ok',
'shipping_options' => view( $view )->with([ 'shippingOptions' => $shippingOptions, 'total' => $totals['total'] ])->render()
'shipping_options' => view( $view )->with([ 'shippingOptions' => $shippingOptions, 'totalPartial' => $totals['totalPartial'] ])->render()
]) : redirect()->back();
}

Expand Down
6 changes: 5 additions & 1 deletion src/app/Product.php
Expand Up @@ -103,7 +103,11 @@ public function fill(array $attributes)

// Main image
if ( isset($image) && is_array($image) && count($image) > 0 ) {
$attributes['image'] = $image[0]['id'];
if ( isset($image[0]['id']) ) {
$attributes['image'] = $image[0]['id'];
} else {
$attributes['image'] = $image[0];
}
} else if ( isset($image) && is_string($image) ) {
$attributes['image'] = ( substr($image, 0, 4) == 'http' ? $image : null );
} else {
Expand Down
7 changes: 6 additions & 1 deletion src/resources/lang/en-GB/ecommerce_cart.php
Expand Up @@ -14,6 +14,11 @@
'max_quantity_reached' => 'Max quantity reached!',

'free_shipping' => 'Free',
'shipping_not_calculated' => '<small>Calculated on checkout</small>'
'shipping_not_calculated' => '<small>Calculated on checkout</small>',

'discount_code_form_title' => 'Coupon Code',
'discount_code_form_placeholder' => 'Coupon Code',
'discount_code_form_apply_cta_label' => 'Apply',
'discount_code_form_remove_cta_label' => 'Remove',

];
7 changes: 6 additions & 1 deletion src/resources/lang/it-IT/ecommerce_cart.php
Expand Up @@ -14,5 +14,10 @@
'max_quantity_reached' => 'Quantità massima raggiunta!',

'free_shipping' => 'Gratuita',
'shipping_not_calculated' => '<small>Calcolata alla cassa</small>'
'shipping_not_calculated' => '<small>Calcolata alla cassa</small>',

'discount_code_form_title' => 'Codice Sconto',
'discount_code_form_placeholder' => 'Codice Sconto',
'discount_code_form_apply_cta_label' => 'Applica',
'discount_code_form_remove_cta_label' => 'Rimuovi',
];
@@ -0,0 +1,19 @@
<form class="discount-code-form"
action="<?php echo ( config('factotum.shop_base_url') ? '/' . config('factotum.shop_base_url') : ''); ?>/cart/apply-discount-code"
method="post">

<p class="title">@lang('factotum::ecommerce_cart.discount_code_form_title')</p>

<div class="field">
<input type="text" name="discount_code" required
placeholder="@lang('factotum::ecommerce_cart.discount_code_form_placeholder')">

<button type="submit"
name="apply_discount_code">@lang('factotum::ecommerce_cart.discount_code_form_apply_cta_label')</button>

<span class="discount_code_applied_response"></span>
</div>

<button class="remove_discount_code hidden">@lang('factotum::ecommerce_cart.discount_code_form_remove_cta_label')</button>

</form>
20 changes: 10 additions & 10 deletions src/routes/web/ecommerce/cart.php
Expand Up @@ -12,20 +12,20 @@
'prefix' => 'cart'
], function() {

$middlewares = [];

if ( !config('factotum.guest_cart') ) {
Route::group([
'middleware' => 'auth'
], function() {
Route::get('', 'ReadController@readCart');
Route::post('/add-product', 'UpdateController@addProduct');
Route::post('/remove-product', 'UpdateController@removeProduct');
Route::post('/drop-product', 'UpdateController@dropProduct');
});
} else {
$middlewares['middleware'] = 'auth';
}

Route::group($middlewares, function() {
Route::get('', 'ReadController@readCart');
Route::post('/add-product', 'UpdateController@addProduct');
Route::post('/remove-product', 'UpdateController@removeProduct');
Route::post('/drop-product', 'UpdateController@dropProduct');
}

Route::post('/apply-discount-code', 'UpdateController@applyDiscountCode');
Route::post('/remove-discount-code', 'UpdateController@removeDiscountCode');
});

});

0 comments on commit f62f442

Please sign in to comment.