Create_Wishlist::handle_request( $args )

Summary

No summary available.

Source

File: src/BigCommerce/Accounts/Wishlists/Actions/Create_Wishlist.php

	public function handle_request( $args ) {
		$redirect = get_the_permalink( get_option( Wishlist_Page::NAME, 0 ) );
		try {
			$submission = $this->sanitize_request( $args, $_POST );
			$request    = new WishlistRequest( [
				'customer_id' => $this->get_customer_id( get_current_user_id() ),
				'name'        => $submission['name'],
				'is_public'   => $submission['public'],
				'items'       => array_map( function ( $product_id ) {
					return new WishlistItem( [ 'product_id' => $product_id ] );
				}, $submission['items'] ),
			] );
			$response   = $this->wishlists->createWishlist( $request );

			$wishlist = new Wishlist( $response->getData() );
			$redirect = $wishlist->user_url();

			do_action( 'bigcommerce/form/success', __( 'Wish List created', 'bigcommerce' ), $submission, $redirect, [] );
		} catch ( \Exception $e ) {
			do_action( 'bigcommerce/form/error', new \WP_Error( $e->getCode(), $e->getMessage() ), $_POST, $redirect, [] );
		}
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.