Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public function __construct(
  2. MagentoCatalogModelProductOption $option
  3. )
  4.  
  5. {
  6. $this->option = $option;
  7. }
  8.  
  9.  
  10. $valuesArray = array();
  11. //add as many options you want, here we add two
  12. $valuesArray[] = array(
  13. "title" => "Option1",
  14. "price_type" => "fixed",
  15. "price" => 9.99,
  16. "sku" => $product->getSku(),
  17. "sort_order" =>; 1,
  18. );
  19. $valuesArray[] = array(
  20. "title" => "Option2",
  21. "price_type" => "fixed",
  22. "price" => 1.99,
  23. "sku" => $product->getSku(),
  24. "sort_order" => 2,
  25. );
  26. //now we create options and set type
  27. $options[] = array(
  28. "sort_order" => 1,
  29. "title" => "Options",
  30. "type" => "radio",
  31. "is_require" => 1,
  32. "values" => $valuesArray,
  33. );
  34. $product->unsetOptions();
  35. $product->setHasOptions(1);
  36. $product->setCanSaveCustomOptions(true);
  37. $product->getResource()->save($product);
  38. $product->setOptions(array());
  39. foreach ($options as $arrayOption) {
  40. $option = $this->option->create()
  41. ->setProductId($product->getId())
  42. ->setStoreId($product->getStoreId())
  43. ->addData($arrayOption);
  44. $option->save();
  45. $options[] = $option;
  46. $product->addOption($option);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement