I have a singlepage (php) with any items (loaded in Magento), the idea is:
- The user access to singlepage.magentodomain.com.
- User press click on "buy now".
- User sees the magento checkout page, with item selected.
The HTML can contain the ID product and send it to Magento from HTTP verbs (POST, GET, etc.) or something else, but I not found information about this.
My Magento version is: 1.9.2.4.
Update (2016-03-9)
I found the next questions:
- Magento 1.9.0.1 add a product to the cart by URL? - Magento Stack Exchange
- magento 1.9 - Unable to add product in cart with custom option via querystring - Magento Stack Exchange
- Adding a Product to the Cart via Querystring using SKU in magento 1.9 - Magento Stack Exchange
- How can I call a block method from a script file? - Magento Stack Exchange
Based on this and @St0iK's answer, I developed the following:
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$_product = Mage::getModel('catalog/product')->load(11);
$formKey = Mage::getSingleton('core/session')->getFormKey();
The next code get the "submit url":
Option 1
$submitUrl = Mage::app()
->getLayout()
->createBlock('catalog/product_view')
->getSubmitUrl($_product);
Option 2
$submitUrl = Mage::helper('checkout/cart')->getAddUrl($_product);
HTML
<form action="<?php echo $submitUrl; ?>" method="post">
<input type="hidden" name="related_product" id="related-products-field" value=""/>
<input type="hidden" name="form_key" value="<?php echo $formKey; ?>">
<input type="hidden" name="product" value="11">
<input type="hidden" name="qty" value="1">
<button type="submit">Buy now</button>
</form>
Request information (after submit)
- Request URL: http://domain.dev/checkout/cart/add/uenc/aHR0cDovL21kci5kZXYvc2luZ2xlLnBocA,,/product/11/form_key/Md2JmzgTZLzWiX9l/
- Request Method: POST
- Status Code: 302 Found
- Remote Address: 127.0.53.53:80
- Response Headers
- Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
- Connection: Keep-Alive
- Content-Length: 0
- Content-Type: text/html; charset=UTF-8
- Date: Wed, 09 Mar 2016 16:21:29 GMT
- Expires: Thu, 19 Nov 1981 08:52:00 GMT
- Keep-Alive: timeout=5, max=100
- Location: http://domain.dev/checkout/cart/
- Pragma: no-cache
- Server: Apache/2.4.12 (Ubuntu)
- Set-Cookie: frontend=5umonnllqprpt57a6vd6lapvb2; expires=Wed, 09-Mar-2016 17:21:30 GMT; Max-Age=3600; path=/; domain=domain.dev; HttpOnly
- X-Frame-Options: SAMEORIGIN
- Request Headers
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
- Accept-Encoding: gzip, deflate
- Accept-Language: es-ES,es;q=0.8,en;q=0.6
- Cache-Control: no-cache
- Connection: keep-alive
- Content-Length: 59
- Content-Type: application/x-www-form-urlencoded
- Cookie: __atuvc=17%7C10; PHPSESSID=cn17rnrbf1h2va76edb1iqmoq5
- Host: domain.dev
- Origin: http://domain.dev
- Pragma: no-cache
- Referer: http://domain.dev/single.php
- Upgrade-Insecure-Requests: 1
- User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36
- Form Data
- related_product:
- form_key: Md2JmzgTZLzWiX9l
- product: 11
- qty: 1