Skip to content

Commit 047d10c

Browse files
committed
apply function erroe fixed
1 parent 4ddcf34 commit 047d10c

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ coupons and coupon_histories two db table are created.
3333

3434
`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.
3535

36-
| Action Name | Method | Explanation |
37-
| ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
38-
| [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 |
39-
| [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 |
40-
| [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 |
41-
| [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 |
42-
| [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 |
43-
| [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 |
44-
| [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 |
45-
| [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 |
36+
| Action Name | Method | Explanation |
37+
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38+
| [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 |
39+
| [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 |
40+
| [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 |
41+
| [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 |
42+
| [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 |
43+
| [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 |
44+
| [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 |
45+
| [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 |
4646

4747
### 1. Create new coupon
4848

@@ -191,7 +191,7 @@ Coupon::validity("CBX23",1200,1,"app","192.168.0.1",5);
191191
$copuon->validity("CBX23",1200,1,"app","192.168.0.1",5);
192192
```
193193

194-
``note: validity() method first 3 method parameter are required others optional``
194+
`note: validity() method first 3 method parameter are required others optional`
195195

196196
### 6. Coupon apply
197197

@@ -205,6 +205,7 @@ Coupon::apply([
205205
"order_id" => "", // order id (required)
206206
"device_name" => "", // device name (optional)
207207
"ip_address" => "", // ip address (optional)
208+
"vendor_id" => "", // vendor id (optional)
208209
]);
209210
```
210211

@@ -218,6 +219,7 @@ $copuon->apply([
218219
"order_id" => "", // order id (required)
219220
"device_name" => "", // device name (optional)
220221
"ip_address" => "", // ip address (optional)
222+
"vendor_id" => "", // vendor id (optional)
221223
]);
222224
```
223225

src/Services/CouponService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ public function apply(array $data)
188188
$orderId = $data["order_id"];
189189
$deviceName = isset($data['device_name']) ? $data['device_name'] : null;
190190
$ipaddress = isset($data['ip_address']) ? $data['ip_address'] : null;
191+
$vendorId = isset($data['vendor_id']) ? $data['vendor_id'] : null;
191192
$skipFields = isset($data['skip']) ? $data['skip'] : [];
192193

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

196197
if (isset($couponValidity->id) && $couponValidity->id) {
197198
try {
@@ -237,7 +238,7 @@ public function addHistory(array $data)
237238

238239
$object_type = "product";
239240
if (isset($array['object_type']) && !empty($array['object_type'])) {
240-
$object_type = $array['object_type'];
241+
$object_type = $data['object_type'];
241242
}
242243

243244
$couponHistory = CouponHistory::query()

0 commit comments

Comments
 (0)