php - Add option value to product, then to cart with Magento -
i searched around while , came wit solutions added whole new option sets products in magento store.
what i'm trying accomplish way add simple product cart. simple product has predifined custom options (free text fields) has filled php function.
so, how can this? let's have product id "111" , 1 custom option.
$qty = '1'; $product = mage::getmodel('catalog/product')->load("111"); // set option value in product model? $cart = mage::helper('checkout/cart')->getcart(); $cart->addproduct($product, $qty); // set option value while passing product car? $cart->save();
thanks in advance hinds.
btw: setting option values via querystring relativly easy seen here.
you don't set custom option on product model, pass in through second argument $cart->addproduct($product, $params)
.
the set have project, requires external app add magento cart, use $params
array of following format:
$params = array( 'product' => 1, // $product->getid() 'qty' => 1, 'options' => array( 34 => "value", 35 => "other value", 53 => "some other value" ) );
the $params['options']
contains custom option information. keys custom option ids, can see them if inspect custom options section of product screen firebug, or similar.
the $params['product']
may redundant, wrote script while ago earlier version of magento.
also, i'm sure standard add cart events fire when add way, you'll need set them off yourself. there may side effects.
Comments
Post a Comment