Jump to content

Recommended Posts

Posted (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 by lodos
  • Management
Posted

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! >

Posted
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...

Posted

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();

image.thumb.png.7df47e3da1a1d7cc16903cc1c04a59a2.png

Posted

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.

  • Management
Posted

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! >

Posted

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.

image.thumb.png.1c1e5be2d4e8b946c7b6fc9333262a13.png

 

Respects...

  • Management
Posted

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! >

Posted

Thank you for your guidance and help. It is currently working smoothly. 😉

Respects...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.