Steven Debock
asked on
Magento 1.9 - add to cart from CMS page with custom options
Hello Experts
I have a CMS page inside my magento 1.9 setup.
I have a virtual product (ID=17) with a dynamic custom options called "Name" (ID=3)
It has a recurring profile set to 1 year and period_frequency to 1
All i want is for that product to get its option "Name" filled from a variable inside the same .phtml file.
With a button that adds it directly to the shopping cart.
In this CMS page i call a block that links to an phtml page.
{{block type="core/template" name="domainCheck" template="catalog/product/ domainchec k.phtml"}}
Using this code in the phtml i cannot add the product because of the required options that are not specified.
This is a virtual product with a recurring profile and 1 custom option called Name
$buy outputs the following:
mysite.com/checkout/cart/a dd/uenc/aH R0cDovL2Ri aXRzLmJlL2 tlYmFiMi9k b21laW5uYW 1lbg,,/pro duct/17/fo rm_key/zig Na5gBINy5w Igl/
I have tried using all kind of query strings, with or without form keys. But nothing seems to be working.
The closest thing i can find on google is this url
magento.stackexchange.com/ questions/ 14718/add- virtual-pr oducts-to- cart-with- custom-opt ions-progr mmatically
Also using virtual products with recurring profiles. But with dropdown custom options (mine is a free text field)
So putting the code from the link above i get no result, nothing happens, and no errors are shown.
Help will be welcome, as i have no clue on how to continue to achieve what i want.
Kind Regards
I have a CMS page inside my magento 1.9 setup.
I have a virtual product (ID=17) with a dynamic custom options called "Name" (ID=3)
It has a recurring profile set to 1 year and period_frequency to 1
All i want is for that product to get its option "Name" filled from a variable inside the same .phtml file.
With a button that adds it directly to the shopping cart.
In this CMS page i call a block that links to an phtml page.
{{block type="core/template" name="domainCheck" template="catalog/product/
Using this code in the phtml i cannot add the product because of the required options that are not specified.
This is a virtual product with a recurring profile and 1 custom option called Name
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku',27005);
$buy = Mage::helper('checkout/cart')->getAddUrl($_product);
?>
<?php $buttonTitle = $this->__('Add to Cart');?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="parent.location='<?php echo $buy; ?>'"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<br/>
<?php endif; ?>
<?php echo $buy ?>
$buy outputs the following:
mysite.com/checkout/cart/a
I have tried using all kind of query strings, with or without form keys. But nothing seems to be working.
The closest thing i can find on google is this url
magento.stackexchange.com/
Also using virtual products with recurring profiles. But with dropdown custom options (mine is a free text field)
So putting the code from the link above i get no result, nothing happens, and no errors are shown.
$proid = 17;
$_product = Mage::getModel('catalog/product')->load($proid);
$_product->setIsRecurring('1');
$_product->setRecurringProfile(array(
'period_unit' => year,
'period_frequency' => 1
));
$_product->save();
$params = array(
'product' => $proid, // This would be $product->getId()
'qty' => 1,
);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($_product,$params);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Help will be welcome, as i have no clue on how to continue to achieve what i want.
Kind Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER