Skip to content

Commit

Permalink
Gift Coupon Code Feature - updates
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Jun 3, 2017
1 parent 6857a9b commit a88ebea
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_ENV=local
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
Expand Down
312 changes: 184 additions & 128 deletions modules/base/Mage2/Cart/views/cart/cart/view.blade.php

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions modules/base/Mage2/Cart/views/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@
|
*/

'email-address' => 'Email Address',
'password' => 'Password',
'remember-me' => 'Remember Me',
'login' => "Login",
'forgot-your-password' => 'Forgot your password?'
];
7 changes: 5 additions & 2 deletions modules/base/Mage2/Catalog/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ public function getAssignedVariationBytAttributeId($attributeId){
* @return float $taxAmount
*/

public function getTaxAmount() {
public function getTaxAmount($price = NULL) {

$defaultCountryId = Configuration::getConfiguration('mage2_tax_class_default_country_for_tax_calculation');
$taxRules = TaxRule::where('country_id','=',$defaultCountryId)->orderBy('priority','DESC')->first();
$price = $this->price;

if(null === $price) {
$price = $this->price;
}

$taxAmount = ($taxRules->percentage * $price / 100);

Expand Down
81 changes: 81 additions & 0 deletions modules/base/Mage2/Sale/Controllers/GiftCouponController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Mage2
*
* NOTICE OF LICENSE
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl-3.0.en.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://mage2.website for more information.
*
* @author Purvesh <[email protected]>
* @copyright 2016-2017 Mage2
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License v3.0
*/

namespace Mage2\Sale\Controllers;

use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Session;
use Mage2\Catalog\Models\Product;
use Mage2\Framework\System\Controllers\Controller;
use Mage2\Sale\Models\GiftCoupon;

class GiftCouponController extends Controller {

public function getCodeDiscount(Request $request) {

$code = $request->get('code');

if(true == empty($code)) {
return Response::json(['success' => false,'message' => "Code Can't be Empty"]);
}


$todayCarbonDate = Carbon::now();
$giftCoupon = GiftCoupon::whereCode($code)->whereStatus('ENABLED')->where('end_date','>',$todayCarbonDate )->first();
if(null === $giftCoupon ) {
return Response::json(['success' => false,'message' => "Invalid Coupon"]);
}

$cartItems = Session::get('cart');

foreach($cartItems as $id => $item) {

$product = Product::findorfail($id);

if(isset($item['gift_coupon_amount'])) {
$price = $product->price;
} else {
$price = $item['price'];
}



$couponDiscount = ($price * $giftCoupon->discount / 100);
$item['price'] = $price - $couponDiscount;
$item['gift_coupon_code'] = $giftCoupon->code;
$item['gift_coupon_amount'] = $couponDiscount;
$item['tax_amount'] = $product->getTaxAmount($item['price']);

$cartItems[$id] = $item;
}

Session::put('cart', $cartItems);
return Response::json(['success' => true]);


}
}
1 change: 0 additions & 1 deletion modules/base/Mage2/Sale/Models/.gitkeep

This file was deleted.

2 changes: 1 addition & 1 deletion modules/base/Mage2/Sale/Models/GiftCoupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class GiftCoupon extends BaseModel
{
protected $fillable = [ 'title', 'code', 'start_date','end_date','status'];
protected $fillable = [ 'title', 'code', 'discount' ,'start_date','end_date','status'];

protected $dates = ['start_date','end_date','created_at','updated_at'];

Expand Down
1 change: 0 additions & 1 deletion modules/base/Mage2/Sale/Requests/.gitkeep

This file was deleted.

6 changes: 3 additions & 3 deletions modules/base/Mage2/Sale/Requests/GiftCouponRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function rules()
{
$validationRule = [];

$validationRule['title'] = 'required|max:255';
$validationRule['code'] = 'required|max:255';

$validationRule['title'] = 'required|max:255';
$validationRule['code'] = 'required|max:255';
$validationRule['discount'] = 'required|between:0,99.99';

return $validationRule;
}
Expand Down
1 change: 1 addition & 0 deletions modules/base/Mage2/Sale/database/Mage2SaleSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function install() {
$table->increments('id');
$table->string('title');
$table->string('code');
$table->float('discount',6,2);
$table->timestamp('start_date');
$table->timestamp('end_date');
$table->enum('status',['ENABLED','DISABLED']);
Expand Down
2 changes: 1 addition & 1 deletion modules/base/Mage2/Sale/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@


Route::group(['middleware' => ['web'], 'namespace' => "Mage2\Sale\Controllers"], function () {

Route::post('/sale/get-code-discount', ['as' => 'get.code-discount','uses' => 'GiftCouponController@getCodeDiscount']);

});
1 change: 0 additions & 1 deletion modules/base/Mage2/Sale/views/admin/.gitkeep

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

{!! Form::text('title','Title',['autofocus'=>true,'class' => 'form-control']) !!}
{!! Form::text('code','Code') !!}
{!! Form::text('discount','Discount') !!}
{!! Form::text('start_date','Start Date') !!}
{!! Form::text('end_date','End Date') !!}
{!! Form::select('status','Status',['ENABLED' => 'Enabled','DISABLED' => 'Disabled']) !!}
Expand Down

0 comments on commit a88ebea

Please sign in to comment.