diff --git a/src/Docs/V1/Admin/Controllers/Marketing/Promotions/CartRuleController.php b/src/Docs/V1/Admin/Controllers/Marketing/Promotions/CartRuleController.php index 24c61cf..ff0ec1f 100644 --- a/src/Docs/V1/Admin/Controllers/Marketing/Promotions/CartRuleController.php +++ b/src/Docs/V1/Admin/Controllers/Marketing/Promotions/CartRuleController.php @@ -718,4 +718,85 @@ public function getConditionAttributes() public function createProductQuantityRule() { } + + /** + * @OA\Get( + * path="/api/v1/admin/promotions/cart-rules/{id}/product-quantity-rules", + * operationId="getProductQuantityRules", + * tags={"CartRules"}, + * summary="Get product quantity rules", + * description="Get product quantity rules", + * security={ {"sanctum_admin": {} }}, + * + * @OA\Parameter( + * name="id", + * description="cart rule ID", + * required=true, + * in="path", + * + * @OA\Schema( + * type="integer" + * ) + * ), + * + * @OA\Response( + * response=200, + * description="Successful operation", + * + * @OA\JsonContent( + * + * @OA\Property( + * property="data", + * type="array", + * + * @OA\Items( + * type="object", + * + * @OA\Property( + * property="id", + * type="integer", + * example=1 + * ), + * @OA\Property( + * property="product_id", + * type="integer", + * example=1 + * ), + * @OA\Property( + * property="rules", + * type="object", + * example={{ + * "value": "2", + * "operator": "==", + * "attribute": { + * "cart_item|item_qty", + * "product|attribute_family_id" + * }, + * "attribute_type": "integer", + * "action_type": "by_percent", + * "price": "10.50" + * }} + * ), + * @OA\Property( + * property="created_at", + * type="string", + * format="date-time", + * example="2023-05-25T12:00:00Z" + * ), + * @OA\Property( + * property="updated_at", + * type="string", + * format="date-time", + * example="2023-05-25T12:00:00Z" + * ) + * ) + * ) + * ) + * + * ) + * ) + */ + public function getProductQuantityRules() + { + } } \ No newline at end of file diff --git a/src/Http/Controllers/Api/V1/Admin/Marketing/Promotions/CartRuleController.php b/src/Http/Controllers/Api/V1/Admin/Marketing/Promotions/CartRuleController.php index 6d91f86..3cdfb29 100644 --- a/src/Http/Controllers/Api/V1/Admin/Marketing/Promotions/CartRuleController.php +++ b/src/Http/Controllers/Api/V1/Admin/Marketing/Promotions/CartRuleController.php @@ -305,8 +305,6 @@ public function createProductQuantityRule($product_id, Request $request){ $product_family_id = $product->attribute_family_id; - - // create a new cart rule for the product quantity $request->validate([ 'product_id' => 'required|integer', @@ -342,4 +340,30 @@ public function createProductQuantityRule($product_id, Request $request){ } + /** + * + * Get all Rules for the Product Quantity + * + * @param int $product_id + * + * + */ + public function getProductQuantityRules($product_id){ + $product = app(\Webkul\Product\Repositories\ProductRepository::class)->findOrFail($product_id); + if(!$product){ + return response()->json([ + 'message' => trans('admin::app.marketing.promotions.cart-rules.product-not-found') + ], 404); + } + + $rules = app(\Webkul\CartRule\Repositories\CartRuleRepository::class)->findWhere([ + 'product_id' => $product_id + ]); + + return response()->json([ + 'data' => CartRuleResource::collection($rules) + ]); + + } + }