lodos Posted October 16 Share Posted October 16 (edited) I found such a topic on the official site. https://invisioncommunity.com/forums/topic/410594-send-visitor-to-forum-with-specific-theme-selected/?do=findComment&comment=2723035 <?php $_SERVER['SCRIPT_FILENAME'] = __FILE__; $path = ''; $_GET['app'] = 'core'; $_GET['module'] = 'system'; $_GET['controller'] = 'theme'; require_once $path . 'init.php'; if (\IPS\Request::i()->id) { $_SERVER['HTTP_REFERER'] = ''; $disp = \IPS\Dispatcher\Front::i(); \IPS\Request::i()->csrfKey = \IPS\Session::i()->csrfKey; $disp->run(); } else { die("No ID passed"); } exit(); Can a product from the store be added directly to the card using a similar method? How should I go about this? Thanks already for your help. Edited October 16 by lodos Link to comment Share on other sites More sharing options...
Management terabyte Posted October 16 Management Share Posted October 16 It should be possible. You need to replace the $_GET values, add an eventual do value, and obviously the product ID as well. I'm on my phone right now, so I can't look up the values, but you can get them by looking at the "Add to Cart" button's URL. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! > Link to comment Share on other sites More sharing options...
lodos Posted October 16 Author Share Posted October 16 27 minutes ago, terabyte said: It should be possible. You need to replace the $_GET values, add an eventual do value, and obviously the product ID as well. I'm on my phone right now, so I can't look up the values, but you can get them by looking at the "Add to Cart" button's URL. Thank you for your kind response. To be honest, I don't have much experience in this regard. Could you please share the complete working code whenever it's convenient for you? Respects... Link to comment Share on other sites More sharing options...
lodos Posted October 16 Author Share Posted October 16 I worked on this today, but I couldn't succeed completely. When I click on a link like the following, it takes me to the cart page but does not add the product to the cart. I'm not sure where I'm making a mistake. Can you help me solve this problem? http://www.site.com/purchase.php?id=2 My code <?php $_SERVER['SCRIPT_FILENAME'] = __FILE__; $path = ''; $_GET['app'] = 'nexus'; $_GET['module'] = 'store'; $_GET['controller'] = 'cart'; require_once $path . 'init.php'; if (\IPS\Request::i()->id) { $_SERVER['HTTP_REFERER'] = ''; $disp = \IPS\Dispatcher\External::i(); \IPS\Request::i()->csrfKey = \IPS\Session::i()->csrfKey; $disp->run(); } else { die("No ID passed"); } exit(); Link to comment Share on other sites More sharing options...
ArashDev Posted October 18 Share Posted October 18 hi check following steps: CSRF Token: This code uses a CSRF token to validate the request. Ensure that the CSRF token is set correctly. Otherwise, the request might be invalid. Server Communication: Check if this code is being sent to your server correctly and that the necessary settings (such as the path to the init.php file) are configured correctly. Link to comment Share on other sites More sharing options...
Management terabyte Posted October 19 Management Share Posted October 19 Try with this code: <?php $_SERVER['SCRIPT_FILENAME'] = __FILE__; $path = ''; $_GET['app'] = 'nexus'; $_GET['module'] = 'store'; $_GET['controller'] = 'product'; require_once $path . 'init.php'; $productID = (int) \IPS\Request::i()->id; if ( $productID ) { # This value is required to submit the form or the product won't be added to the cart $fieldName = "package_{$productID}_submitted"; \IPS\Request::i()->$fieldName = 1; # This value is required for the quantity you want to add to the cart. You can adjust it, or even use an extra variable in the URL to control it \IPS\Request::i()->quantity = 1; # Load external dispatcher and run it $disp = \IPS\Dispatcher\External::i(); \IPS\Request::i()->csrfKey = \IPS\Session::i()->csrfKey; $disp->run(); } else { die("No ID passed"); } exit(); I did a quick test locally and it seems to work just fine for a simple product with no extra fields. Depending on the product you might need additional values in the request. For example, if the product you're trying to add has custom fields that must be filled. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! > Link to comment Share on other sites More sharing options...
lodos Posted October 19 Author Share Posted October 19 Really thank you so much. As you said, it works smoothly for products that do not have extra settings. However, unfortunately it does not work for products where there are renewals and a custom field. I would be grateful if you could help me in this regard. Respects... Link to comment Share on other sites More sharing options...
Management terabyte Posted October 20 Management Share Posted October 20 After the quantity row add also this code: \IPS\Request::i()->renewal_term = X; Replace X with the number of the option you want to add, counting from 0. For example, based on your screenshot, you need to replace X with 0 for $15/6 months and 1 for $30/1 year. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! > Link to comment Share on other sites More sharing options...
lodos Posted October 20 Author Share Posted October 20 Thank you for your guidance and help. It is currently working smoothly. 😉 Respects... terabyte 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now