Hi All
my first question and its going to be focused around the handy little PayPal snippet by mark Hamstra
if anyone is not familiar with it then you can check it out here
http://rtfm.modx.com/display/ADDON/mhPayPal
he also wrote a handy blog about it back when it didn't have half the features it does now
https://www.markhamstra.com/modx-blog/2011/12/accepting-paypal-on-your-modx-site/
anyway ... on to my point
Currently the snippet does not allow for the user to pass in a quantity in the snippet. So if i wanted to make a "buy it now" button with a an item such as ...socks, i could only buy a pair at a time.
the snippet does allow for extra fields to be passed into the snippet which "i think" it reads from extra input fields i add to my formTpl.
below is my snippet call so far
[[!mhPayPal?
&amount=`[[*productprice]]`
&amountTax=`2.85`
&description=`[[*menutitle]] ([[+currency]][[+amount]])`
¤cies=`GBP,EUR,USD`
&formTpl=`priceTemplate`
&shipping=`1`
&extraRequiredFields=`quantity`
]]
I have made essentially a product page which allows the price to be edited in the manager tpl variable and i have passed my own form into it and stripped out the features i don't need (the donate field which allows the user to type in an amount they want to pay)
From the snippet it works perfectly and checks out to the Paypal express checkout with price, description and currency all working perfectly.
But now i want to be able to pass in a quantity so that the user could buy 2 socks or 3 socks
here is the code i have added to my formTpl which is used to gather data from
<div class="quantity">
<input type="text" name="quantity" value="[[+quantity:empty=`1`]]">
</div>
you can see i have added a "quantity" placeholder which i have then mentioned in my original snippet call above
&extraRequiredFields=`quantity`
extraRequiredFields
[string] Comma separated list of field names that are required and cannot be left empty, can be used to collect extra data about the user for use in a custom hook or the likes.
This is where i hit a roadblock
I don't know if my [[+quantity:empty=`1`]] is actually the correct syntax.
is my reference to that placeholder correct
&extraRequiredFields=`quantity` or
&extraRequiredFields=`[[+quantity]]`
What i want to accomplish
I want to be able to pass in that extra parameter that the user can type in and then use that to multiply the price by that amount.
Example
quantity = 5 (that the end user types in .. defaults to one if not changed)
price of item (which is defined by site owner &amount=`[[*productprice]]`)
submit form
goes into a hook which will take the price and multiple it by the quantity
Goes to checkout with final price.
the snippet does allow for
posthooks which allow for price changes prior to connecting to paypal
&postHooks
[string] Comma separated list of hooks to be executed after successfully submitting the form, but before connecting with PayPal to set up the payment. Could be used to (for example) calculate taxes before it is registered with PayPal, or to further validate the data.
I have looked into creating the hook but im not too familar with the modx api and reading from information passed into a snippet from another snippet.
if anyone can give a steer with the information below it would be a massive help.
Simply call a snippet in one of the hooks properties, and it will be executed.
Available in the $scriptProperties and as $variables are all the data available at that point. Configuration properties. $mhpp class.