Submit
Path:
~
/
/
usr
/
local
/
sitepad
/
editor
/
site-data
/
plugins
/
kkart-pro
/
packages
/
kkart-blocks
/
src
/
StoreApi
/
Routes
/
File Content:
CartItems.php
<?php namespace Automattic\Kkart\Blocks\StoreApi\Routes; use Automattic\Kkart\Blocks\StoreApi\Utilities\CartController; /** * CartItems class. * * @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions. */ class CartItems extends AbstractRoute { /** * Get the path of this REST route. * * @return string */ public function get_path() { return '/cart/items'; } /** * Get method arguments for this REST route. * * @return array An array of endpoints. */ public function get_args() { return [ [ 'methods' => \WP_REST_Server::READABLE, 'callback' => [ $this, 'get_response' ], 'permission_callback' => '__return_true', 'args' => [ 'context' => $this->get_context_param( [ 'default' => 'view' ] ), ], ], [ 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_response' ), 'permission_callback' => '__return_true', 'args' => $this->schema->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), ], [ 'methods' => \WP_REST_Server::DELETABLE, 'callback' => [ $this, 'get_response' ], 'permission_callback' => '__return_true', ], 'schema' => [ $this->schema, 'get_public_item_schema' ], ]; } /** * Get a collection of cart items. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response */ protected function get_route_response( \WP_REST_Request $request ) { $controller = new CartController(); $cart_items = $controller->get_cart_items(); $items = []; foreach ( $cart_items as $cart_item ) { $data = $this->prepare_item_for_response( $cart_item, $request ); $items[] = $this->prepare_response_for_collection( $data ); } $response = rest_ensure_response( $items ); return $response; } /** * Creates one item from the collection. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response */ protected function get_route_post_response( \WP_REST_Request $request ) { // Do not allow key to be specified during creation. if ( ! empty( $request['key'] ) ) { throw new RouteException( 'kkart_rest_cart_item_exists', __( 'Cannot create an existing cart item.', 'kkart' ), 400 ); } $controller = new CartController(); $result = $controller->add_to_cart( [ 'id' => $request['id'], 'quantity' => $request['quantity'], 'variation' => $request['variation'], ] ); $response = rest_ensure_response( $this->prepare_item_for_response( $controller->get_cart_item( $result ), $request ) ); $response->set_status( 201 ); return $response; } /** * Deletes all items in the cart. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response */ protected function get_route_delete_response( \WP_REST_Request $request ) { $controller = new CartController(); $controller->empty_cart(); return new \WP_REST_Response( [], 200 ); } /** * Prepare links for the request. * * @param array $cart_item Object to prepare. * @param \WP_REST_Request $request Request object. * @return array */ protected function prepare_links( $cart_item, $request ) { $base = $this->get_namespace() . $this->get_path(); $links = array( 'self' => array( 'href' => rest_url( trailingslashit( $base ) . $cart_item['key'] ), ), 'collection' => array( 'href' => rest_url( $base ), ), ); return $links; } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
AbstractCartRoute.php
2379 bytes
0644
AbstractRoute.php
8333 bytes
0644
AbstractTermsRoute.php
4776 bytes
0644
Cart.php
1347 bytes
0644
CartAddItem.php
2948 bytes
0644
CartApplyCoupon.php
1882 bytes
0644
CartCoupons.php
3823 bytes
0644
CartCouponsByCode.php
2469 bytes
0644
CartItems.php
3699 bytes
0644
CartItemsByKey.php
3903 bytes
0644
CartRemoveCoupon.php
2261 bytes
0644
CartRemoveItem.php
1721 bytes
0644
CartSelectShippingRate.php
2487 bytes
0644
CartUpdateItem.php
1739 bytes
0644
CartUpdateShipping.php
7330 bytes
0644
Checkout.php
17224 bytes
0644
ProductAttributeTerms.php
1607 bytes
0644
ProductAttributes.php
1390 bytes
0644
ProductAttributesById.php
1679 bytes
0644
ProductCategories.php
1136 bytes
0644
ProductCategoriesById.php
1651 bytes
0644
ProductCollectionData.php
5548 bytes
0644
ProductReviews.php
6618 bytes
0644
ProductTags.php
1118 bytes
0644
Products.php
12968 bytes
0644
ProductsById.php
1593 bytes
0644
RouteException.php
1393 bytes
0644
RouteInterface.php
551 bytes
0644
N4ST4R_ID | Naxtarrr