From 047d10c062c336066112c0a7ea6846197afcc8c7 Mon Sep 17 00:00:00 2001 From: Deepak3642 Date: Tue, 7 May 2024 10:13:50 +0600 Subject: [PATCH] apply function erroe fixed --- README.md | 24 +++++++++++++----------- src/Services/CouponService.php | 5 +++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 79d104a..5cac342 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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) ]); ``` @@ -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) ]); ``` diff --git a/src/Services/CouponService.php b/src/Services/CouponService.php index 2e1acac..1d7ed30 100644 --- a/src/Services/CouponService.php +++ b/src/Services/CouponService.php @@ -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 { @@ -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()