Skip to content

Commit

Permalink
fix the rules
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Dec 17, 2024
1 parent 7f6ffcc commit 4ada414
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
]);

}

}

0 comments on commit 4ada414

Please sign in to comment.