Skip to content

Commit

Permalink
apply function erroe fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakdeb committed May 7, 2024
1 parent 4ddcf34 commit 047d10c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ coupons and coupon_histories two db table are created.

`Note:` If you are using raw PHP or other PHP framework you can have to import `copuondiscount/database/sql` SQL file manually in your database.

| Action Name | Method | Explanation |
| ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Create Coupon](https://github.com/codeboxrcodehub/coupondiscount#1-create-new-coupon) | add($array) | Create coupon code by add() method it taken a array. Array formate given below |
| [Update Coupon](https://github.com/codeboxrcodehub/coupondiscount#2-update-coupon) | update($array,$couponId) | Coupon Update by update() method it's taken two parameter first parameter is an array and second parameter is coupon id |
| [Remove Coupon](https://github.com/codeboxrcodehub/coupondiscount#3-remove-coupon) | remove($couponId) | Coupon Remove by remove() method it's taken one parameter. Parameter is Coupon id |
| [Coupon List](https://github.com/codeboxrcodehub/coupondiscount#4-coupon-list) | list() | Fetch coupon list by list() method. You can chain any operation in Eluquarant after this method. For example: `list()->where('status',1)->get();`,`list()->take(5)->get();`,`list()->first();` etc |
| [Coupon Validity](https://github.com/codeboxrcodehub/coupondiscount#5-coupon-validity-check) | validity($couponCode, float $amount, string $userId, string $deviceName = null, string $ipaddress = null, string $vendorId = null) | check coupon code validity by validity() method. It's take 6 parameter 3 parameter are required. 1st parameter is coupon code,second parameter is total amount,third parameter is user id,fourth parameter (optional) device name,fifth parameter (optional) is IP address and sixth parameter (optional) is vendor id or shop id |
| [Coupon Apply](https://github.com/codeboxrcodehub/coupondiscount#6-coupon-apply) | apply($array) | Apply coupon in a cart amount by apply() method. apply method taken one parameter is array, example given below |
| [Coupon History List](https://github.com/codeboxrcodehub/coupondiscount#7-coupon-history-list) | history() | Fetch coupon history list by history() method. You can chain any operation in Eluquarant after this method. For example: `history()->where('user_id',1)->get();`,`history()->take(5)->get();`,`history()->first();` etc |
| [Remove History](https://github.com/codeboxrcodehub/coupondiscount#8-delete-coupon-history) | historyDelete($historyId)| Coupon History Remove by historyDelete() method it's taken one parameter. Parameter is Coupon history id |
| Action Name | Method | Explanation |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Create Coupon](https://github.com/codeboxrcodehub/coupondiscount#1-create-new-coupon) | add($array) | Create coupon code by add() method it taken a array. Array formate given below |
| [Update Coupon](https://github.com/codeboxrcodehub/coupondiscount#2-update-coupon) | update($array,$couponId) | Coupon Update by update() method it's taken two parameter first parameter is an array and second parameter is coupon id |
| [Remove Coupon](https://github.com/codeboxrcodehub/coupondiscount#3-remove-coupon) | remove($couponId) | Coupon Remove by remove() method it's taken one parameter. Parameter is Coupon id |
| [Coupon List](https://github.com/codeboxrcodehub/coupondiscount#4-coupon-list) | list() | Fetch coupon list by list() method. You can chain any operation in Eluquarant after this method. For example: `list()->where('status',1)->get();`,`list()->take(5)->get();`,`list()->first();` etc |
| [Coupon Validity](https://github.com/codeboxrcodehub/coupondiscount#5-coupon-validity-check) | validity($couponCode, float $amount, string $userId, string $deviceName = null, string $ipaddress = null, string $vendorId = null) | check coupon code validity by validity() method. It's take 6 parameter 3 parameter are required. 1st parameter is coupon code,second parameter is total amount,third parameter is user id,fourth parameter (optional) device name,fifth parameter (optional) is IP address and sixth parameter (optional) is vendor id or shop id |
| [Coupon Apply](https://github.com/codeboxrcodehub/coupondiscount#6-coupon-apply) | apply($array) | Apply coupon in a cart amount by apply() method. apply method taken one parameter is array, example given below |
| [Coupon History List](https://github.com/codeboxrcodehub/coupondiscount#7-coupon-history-list) | history() | Fetch coupon history list by history() method. You can chain any operation in Eluquarant after this method. For example: `history()->where('user_id',1)->get();`,`history()->take(5)->get();`,`history()->first();` etc |
| [Remove History](https://github.com/codeboxrcodehub/coupondiscount#8-delete-coupon-history) | historyDelete($historyId) | Coupon History Remove by historyDelete() method it's taken one parameter. Parameter is Coupon history id |

### 1. Create new coupon

Expand Down Expand Up @@ -191,7 +191,7 @@ Coupon::validity("CBX23",1200,1,"app","192.168.0.1",5);
$copuon->validity("CBX23",1200,1,"app","192.168.0.1",5);
```

``note: validity() method first 3 method parameter are required others optional``
`note: validity() method first 3 method parameter are required others optional`

### 6. Coupon apply

Expand All @@ -205,6 +205,7 @@ Coupon::apply([
"order_id" => "", // order id (required)
"device_name" => "", // device name (optional)
"ip_address" => "", // ip address (optional)
"vendor_id" => "", // vendor id (optional)
]);
```

Expand All @@ -218,6 +219,7 @@ $copuon->apply([
"order_id" => "", // order id (required)
"device_name" => "", // device name (optional)
"ip_address" => "", // ip address (optional)
"vendor_id" => "", // vendor id (optional)
]);
```

Expand Down
5 changes: 3 additions & 2 deletions src/Services/CouponService.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ public function apply(array $data)
$orderId = $data["order_id"];
$deviceName = isset($data['device_name']) ? $data['device_name'] : null;
$ipaddress = isset($data['ip_address']) ? $data['ip_address'] : null;
$vendorId = isset($data['vendor_id']) ? $data['vendor_id'] : null;
$skipFields = isset($data['skip']) ? $data['skip'] : [];

// check applied coupon code code validity
$couponValidity = $this->validity($code, $amount, $userId, $deviceName, $ipaddress, $skipFields);
$couponValidity = $this->validity($code, $amount, $userId, $deviceName, $ipaddress,$vendorId, $skipFields);

if (isset($couponValidity->id) && $couponValidity->id) {
try {
Expand Down Expand Up @@ -237,7 +238,7 @@ public function addHistory(array $data)

$object_type = "product";
if (isset($array['object_type']) && !empty($array['object_type'])) {
$object_type = $array['object_type'];
$object_type = $data['object_type'];
}

$couponHistory = CouponHistory::query()
Expand Down

0 comments on commit 047d10c

Please sign in to comment.