class-wc-product-data-store-interface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Product Data Store Interface
  4. *
  5. * @version 3.0.0
  6. * @package WooCommerce/Interface
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. exit;
  10. }
  11. /**
  12. * WC Product Data Store Interface
  13. *
  14. * Functions that must be defined by product store classes.
  15. *
  16. * @version 3.0.0
  17. */
  18. interface WC_Product_Data_Store_Interface {
  19. /**
  20. * Returns an array of on sale products, as an array of objects with an
  21. * ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
  22. *
  23. * @return array
  24. */
  25. public function get_on_sale_products();
  26. /**
  27. * Returns a list of product IDs ( id as key => parent as value) that are
  28. * featured. Uses get_posts instead of wc_get_products since we want
  29. * some extra meta queries and ALL products (posts_per_page = -1).
  30. *
  31. * @return array
  32. */
  33. public function get_featured_product_ids();
  34. /**
  35. * Check if product sku is found for any other product IDs.
  36. *
  37. * @param int $product_id Product ID.
  38. * @param string $sku SKU.
  39. * @return bool
  40. */
  41. public function is_existing_sku( $product_id, $sku );
  42. /**
  43. * Return product ID based on SKU.
  44. *
  45. * @param string $sku SKU.
  46. * @return int
  47. */
  48. public function get_product_id_by_sku( $sku );
  49. /**
  50. * Returns an array of IDs of products that have sales starting soon.
  51. *
  52. * @return array
  53. */
  54. public function get_starting_sales();
  55. /**
  56. * Returns an array of IDs of products that have sales which are due to end.
  57. *
  58. * @return array
  59. */
  60. public function get_ending_sales();
  61. /**
  62. * Find a matching (enabled) variation within a variable product.
  63. *
  64. * @param WC_Product $product Variable product object.
  65. * @param array $match_attributes Array of attributes we want to try to match.
  66. * @return int Matching variation ID or 0.
  67. */
  68. public function find_matching_product_variation( $product, $match_attributes = array() );
  69. /**
  70. * Make sure all variations have a sort order set so they can be reordered correctly.
  71. *
  72. * @param int $parent_id Parent ID.
  73. */
  74. public function sort_all_product_variations( $parent_id );
  75. /**
  76. * Return a list of related products (using data like categories and IDs).
  77. *
  78. * @param array $cats_array List of categories IDs.
  79. * @param array $tags_array List of tags IDs.
  80. * @param array $exclude_ids Excluded IDs.
  81. * @param int $limit Limit of results.
  82. * @param int $product_id Product ID.
  83. * @return array
  84. */
  85. public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id );
  86. /**
  87. * Update a product's stock amount directly.
  88. *
  89. * Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).
  90. *
  91. * @param int $product_id_with_stock Product ID.
  92. * @param int|null $stock_quantity Stock quantity to update to.
  93. * @param string $operation Either set, increase or decrease.
  94. */
  95. public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' );
  96. /**
  97. * Update a product's sale count directly.
  98. *
  99. * Uses queries rather than update_post_meta so we can do this in one query for performance.
  100. *
  101. * @param int $product_id Product ID.
  102. * @param int|null $quantity Stock quantity to use for update.
  103. * @param string $operation Either set, increase or decrease.
  104. */
  105. public function update_product_sales( $product_id, $quantity = null, $operation = 'set' );
  106. /**
  107. * Get shipping class ID by slug.
  108. *
  109. * @param string $slug Shipping class slug.
  110. * @return int|false
  111. */
  112. public function get_shipping_class_id_by_slug( $slug );
  113. /**
  114. * Returns an array of products.
  115. *
  116. * @param array $args @see wc_get_products.
  117. * @return array
  118. */
  119. public function get_products( $args = array() );
  120. /**
  121. * Get the product type based on product ID.
  122. *
  123. * @param int $product_id Product ID.
  124. * @return bool|string
  125. */
  126. public function get_product_type( $product_id );
  127. }