Tom S. Posted April 27, 2018 Share Posted April 27, 2018 I would like to be able to add an item to a users cart programmatically. Is there a built in function that can add a specific store item to the cart session? $_SESSION['cart'] For example, so I could create my own 'Add to cart' button outside of the product store page. Link to comment Share on other sites More sharing options...
Adriano Faria Posted April 27, 2018 Share Posted April 27, 2018 Take a look at IPS\nexus\Package\Product::addToCart(). /** * Add To Cart * * @param \IPS\nexus\extensions\nexus\Item\Package $item The item * @param array $values Values from form * @param string $memberCurrency The currency being used * @return array Additional items to add */ public function addToCart( \IPS\nexus\extensions\nexus\Item\Package $item, array $values, $memberCurrency ) { if ( $this->subscription ) { if ( $item->quantity > 1 ) { \IPS\Output::i()->error( 'err_subscription_qty', '1X247/2', 403, '' ); } if ( $this->_memberHasPurchasedSubscription( \IPS\Member::loggedIn() ) ) { \IPS\Output::i()->error( 'err_subscription_bought', '1X247/1', 403, '' ); } if ( isset( $_SESSION['cart'] ) ) { foreach ( $_SESSION['cart'] as $_item ) { if ( $_item->id === $this->id ) { \IPS\Output::i()->error( 'err_subscription_in_cart', '1X247/3', 403, '' ); } } } } return parent::addToCart( $item, $values, $memberCurrency ); } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.