WC_GZD_Product_Factory

Product Factory Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-gzd-product-factory.php  
  1. class WC_GZD_Product_Factory extends WC_Product_Factory { 
  2.  
  3. /** 
  4. * get_product function. 
  5. * @param bool $the_product (default: false) 
  6. * @param array $args (default: array()) 
  7. * @return WC_Product|bool false if the product cannot be loaded 
  8. */ 
  9. public function get_product( $the_product = false, $args = array() ) { 
  10. $product = $this->get_product_standalone( $the_product, $args ); 
  11. if ( is_object( $product ) ) 
  12. $product->gzd_product = $this->get_gzd_product( $product ); 
  13. return $product; 
  14.  
  15. /** 
  16. * Gets product without injecting gzd_product. Only available as fallback 
  17. *  
  18. * @param bool $the_product (default: false) 
  19. * @param array $args (default: array()) 
  20. * @return WC_Product|bool false if the product cannot be loaded 
  21. */ 
  22. public function get_product_standalone( $the_product = false, $args = array() ) { 
  23. return parent::get_product( $the_product, $args ); 
  24.  
  25. /** 
  26. * Returns and locates the WC_GZD_Product Object based on product type.  
  27. *  
  28. * @param object $product WC_Product 
  29. * @return object WC_GZD_Product 
  30. */ 
  31. public function get_gzd_product( $product ) { 
  32.  
  33. $type = wc_gzd_get_crud_data( $product, 'product_type' ); 
  34. $classname = 'WC_GZD_Product_' . ucfirst( $type ); 
  35.  
  36. if ( class_exists( $classname ) ) 
  37. return new $classname( $product ); 
  38.  
  39. return new WC_GZD_Product( $product ); 
  40.