VBO action for commerce product

Public

This is sample code for commerce product Publish/Unpublish functionality.

</> CopyGet raw version
php
  1. function demo_action_info() {
  2. return array(
  3. 'demo_commerce_product_publish' => array(
  4. 'type' => 'entity',
  5. 'label' => t('Publish selected product'),
  6. 'configurable' => FALSE,
  7. 'triggers' => array('any'),
  8. ),
  9. 'demo_commerce_product_unpublish' => array(
  10. 'type' => 'entity',
  11. 'label' => t('Unpublish selected product'),
  12. 'configurable' => FALSE,
  13. 'triggers' => array('any'),
  14. ),
  15. );
  16. }
  17.  
  18. function demo_commerce_product_publish($entity, $context = array()) {
  19. $eload = entity_load('commerce_product', array($entity->product_id));
  20. $eload[$entity->product_id]->status = 1; // unpublish;
  21. entity_save('commerce_product', current($eload));
  22. entity_get_controller('commerce_product')->resetCache(array($entity->product_id));
  23. }
  24.  
  25. function demo_commerce_product_unpublish($entity, $context = array()) {
  26. $eload = entity_load('commerce_product', array($entity->product_id));
  27. $eload[$entity->product_id]->status = 0; // unpublish;
  28. entity_save('commerce_product', current($eload));
  29. entity_get_controller('commerce_product')->resetCache(array($entity->product_id));
  30. }