Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function __construct(
- MagentoCatalogModelProductOption $option
- )
- {
- $this->option = $option;
- }
- $valuesArray = array();
- //add as many options you want, here we add two
- $valuesArray[] = array(
- "title" => "Option1",
- "price_type" => "fixed",
- "price" => 9.99,
- "sku" => $product->getSku(),
- "sort_order" =>; 1,
- );
- $valuesArray[] = array(
- "title" => "Option2",
- "price_type" => "fixed",
- "price" => 1.99,
- "sku" => $product->getSku(),
- "sort_order" => 2,
- );
- //now we create options and set type
- $options[] = array(
- "sort_order" => 1,
- "title" => "Options",
- "type" => "radio",
- "is_require" => 1,
- "values" => $valuesArray,
- );
- $product->unsetOptions();
- $product->setHasOptions(1);
- $product->setCanSaveCustomOptions(true);
- $product->getResource()->save($product);
- $product->setOptions(array());
- foreach ($options as $arrayOption) {
- $option = $this->option->create()
- ->setProductId($product->getId())
- ->setStoreId($product->getStoreId())
- ->addData($arrayOption);
- $option->save();
- $options[] = $option;
- $product->addOption($option);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement