Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. /**
  2. * Before save type related data
  3. *
  4. * @param MagentoCatalogModelProduct $product
  5. * @return $this
  6. */
  7. public function beforeSave($product)
  8. {
  9. parent::beforeSave($product);
  10.  
  11. $options[] = array(
  12. "sort_order" => 1,
  13. "title" => "Select Date",
  14. "type" => "date",
  15. "is_require" => 1,
  16. "price_type" => "fixed"
  17. );
  18. $product->unsetOptions();
  19. $product->setHasOptions(1);
  20. $product->setCanSaveCustomOptions(true);
  21. $product->getResource()->save($product);
  22. $product->setOptions(array());
  23. foreach ($options as $arrayOption) {
  24. $option = $this->_objectManager->create('MagentoCatalogModelProductOption')
  25. ->setProductId($product->getId())
  26. ->setStoreId($product->getStoreId())
  27. ->addData($arrayOption);
  28. $option->save();
  29. $options[] = $option;
  30. $product->addOption($option);
  31. }
  32.  
  33. return $this;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement