I have a Magento v1.9.2.3 webshop and I'm also adding my products to my Facebook shopping page.
I thought I could use the form action url from my webshop as the payment url in FB shopping: my-webshop/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuc2NyYXB3ZWJzaG9wLm5sL3N0ZXJyZW5iZWVsZC1rbmlwdmVsbGVuLmh0bWw_X19fU0lEPVU,/product/5130/form_key/bO1glkQ2GyvpRd7m/
But after reading I (and trying) I understand the form_key is changed after every cache clear/refresh (which we do very regularly). So I need a more flexible solution.
How can I solve this? I can't imagine I'm the first to try this. Should I create a new php page that will do this or ... ?
Thanks for any advice.
EDIT
I created a new php page in the root of my webshop and added these lines:
$product = Mage::getModel('catalog/product')->load(5130);
echo Mage::helper('checkout/cart')->getAddUrl($product, array('qty'=>1, 'form_key'=>Mage::getSingleton('core/session')->getFormKey()));
The resulting url is my-webshop/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuc2NyYXB3ZWJzaG9wLm5sL0FkZFRvQ2FydC5waHA,/product/5130/form_key/lPCvzei32zLtxqxp/qty/1/
but according to the form url it should be my-webshop/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuc2NyYXB3ZWJzaG9wLm5sL3NhbGUvc3RlcnJlbmJlZWxkLWtuaXB2ZWxsZW4uaHRtbD9fX19TSUQ9VQ,,/product/5130/form_key/kqe8DtKacPrJzjgN/
Notice the difference of the form_key
?!?!?
The resulting URL is not working, but the form url is. So this is not a working solution.
Found something else and added these lines of code:
try {
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$product = Mage::getModel('catalog/product')->load(5130);
$parameter = array('product' => '5130',
'qty' => '1',
'form_key' => Mage::getSingleton('core/session')->getFormKey()
);
$request = new Varien_Object();
$request->setData($parameter);
$cart->addProduct($product, $request);
$cart->save();
Mage::getSingleton('customer/session')->setCartWasUpdated(true);
echo 'product added<br>';
} catch (Exception $e) {
print_r($e->getMessage());
}
product added
was printed but when I go to my cart it is still empty.
So this is not working either.
I would really much appreciate if someone would help me out.