Yes, it definitely is. With a cart, there shouldn’t be an underscore, should there? i.e. a single purchase will have ‘item_number’. If there are multiple items in your cart, they would be ‘item_number1’, ‘item_number2’, etc. At least, that’s what PayPal was doing when this module was written, and if it’s still working with the native tags, it would appear they still do.
Without either of those patterns present in the data returned by PayPal, the SCM will not process any purchases.
Just to pop in on this but I’m pretty sure that PayPal expects the underscore. This page here seems to say so? I could be reading it wrong though?
Also wouldn’t the native Simple Commerce Module tags always output item_name without a number at the end as the items are being passed one at a time to PayPal? I might be wrong on that too though? 😉
Best wishes,
Mark
Looks like it Mark; when items are added to your cart one at a time though via the standard SCM method, PayPal builds them without the underscore, which is why the payment is still processed. PayPal sends the form fields as item_number1, item_number2, etc. in that case. When you send via the method your plugin does, however, it appears to send them back with the underscore. I love PayPal!
There’s a “Successful Purchase” code block around line 455 of mod.simple_commerce.php:
if ($this->post['num_cart_items'] != '' && $this->post['num_cart_items'] > 0 && isset($_POST['item_number1']))
{
for($i=1; $i <= $this->post['num_cart_items']; ++$i)
{
if (($item_id = $IN->GBL('item_number'.$i, 'POST')) !== FALSE)
{
$qnty = (isset($_POST['quantity'.$i]) && is_numeric($_POST['quantity'.$i])) ? $_POST['quantity'.$i] : 1;
You can try changing that to the following and see if it allows these purchases to come through:
if ($this->post['num_cart_items'] != '' && $this->post['num_cart_items'] > 0 && isset($_POST['item_number_1']))
{
for($i=1; $i <= $this->post['num_cart_items']; ++$i)
{
if (($item_id = $IN->GBL('item_number_'.$i, 'POST')) !== FALSE)
{
$qnty = (isset($_POST['quantity_'.$i]) && is_numeric($_POST['quantity_'.$i])) ? $_POST['quantity_'.$i] : 1;
Of course, I have no idea if they will be consistent and send quantity with an underscore or not (and do not have time to dive into their support area at the moment), so I’d double check your quantities are correct.
Hi Derek,
Thanks for the code but as mentioned before the plugin doesn’t actually control any of the final output, that is entirely down to the site designer so the fields in Matt’s form above will have been dynamically coded by himself.
In that case does it simply mean that if the fields are coded in the form as item_name1 etc then it should all work. I guess that should be okay shouldn’t it?
Best wishes,
Mark
Hi there Thanks for your interest in this. I’ve been away over the weekend so a bit slow getting back to it.
Unfortunately, neither fix works.
Changing the mod.simple_commerce.php doesn’t result in purchases showing and removing the underscores means that either the shopping cart shows as empty when it gets to Paypal (if you remove underscores from all of the required variables) or the item_number_ variable doesn’t get passed through (if you remove the underscore from only that one).
I still think the main problem is the fact that the SCM doesn’t log ppurchases from users who aren’t logged in. I suppose I could try & ‘hack’ that by using the logmein plugin, but seeing as these fixes haven’t worked, that won’t work either…
:o/
M.
I still think the main problem is the fact that the SCM doesn’t log ppurchases from users who aren’t logged in.
I didn’t realise you were trying this with logged-out users? If that is the case then unfortunately that would definitely be the problem as the Simple Commerce Module wouldn’t be able to know who purchased an item and when the information gets sent back to it then it wouldn’t know what to do with it.
I thought that people were going to be logged-in on your site prior to purchasing though? Is this not something that you can enforce as that should clear up your problems with this pretty quickly.
Best wishes,
Mark
I’ve been testing purchases as a logged-in user, and they still don’t show unfortunately.
I’m not (nor will the client be) in favour of enforcing registration before using the shop - that’s a sure-fire way to put some people off.
What I meant when I mentioned the problem (as I see it) with not registering purchases from non-logged-in users, I was speaking generally… I would rather have the modules register all purchases, that’s all.
M.
Mark is correct, the solution most use is a very simple logged_in conditional. If you’re logged in, you are shown the add to cart / purchase buttons. If you are not logged in, you are shown a link to login. Simple Commerce is designed to work with the member module. To alter this, you wouldn’t have to hack the module, though, as there are hooks available that would enable your changes to work by writing an Extension.
Ok, I do understand - it’s obviously more useful if you can get people to register before making purchases (and there are other member-only functions on the site, such as the ability to contribute content) but I’m just very conscious that buying anything from the shop should be as easy as possible.
It still doesn’t show any purchases when I am logged in though.
M (o;
I think it’s just called ‘Shopping Cart Plugin’. It’s very good, I must say - it allows you to send the site user’s purchases to a 3rd party payment consolidator.
One thing though - you can still use Paypal, using the ‘Cart Upload’ function, but unfortunately the response back won’t register purchases with the SCM, which is a little annoying. I think I may know a way to fix it but it requires a bit of software enegineering, which is not my area of expertise.
Nothing wrong with Mark’s plugin though - I thoroughly recommend that. Very easy to install and set up with your templates.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.