Revert "Look up product by sku"

This commit is contained in:
Claudio Sanches 2014-11-27 10:06:28 -02:00
parent 2c6debf1f4
commit 7a62f75eca
1 changed files with 0 additions and 69 deletions

View File

@ -66,11 +66,6 @@ class WC_API_Products extends WC_API_Resource {
array( array( $this, 'get_product_category' ), WC_API_Server::READABLE ),
);
# GET /products/sku/<product sku>
$routes[ $this->base . '/sku/(?P<sku>\d+)' ] = array(
array( array( $this, 'get_product_by_sku' ), WC_API_Server::READABLE ),
);
return $routes;
}
@ -1813,68 +1808,4 @@ class WC_API_Products extends WC_API_Resource {
*/
}
/**
* Get the product for a given sku
*
* @since 2.2.8
* @param int $sku the product sku
* @param string $fields
* @return array
*/
public function get_product_by_sku( $sku, $fields = null, $filter = array(), $page = 1 ) {
// get all products
$filter['page'] = $page;
$query = $this->query_products( $filter );
$products = array();
// itterate over product collection
foreach ( $query->posts as $product_id ) {
if ( ! $this->is_readable( $product_id ) ) {
continue;
}
// temp variable to hold the current product in memory
$tmp_product = $this->get_product( $product_id, $fields );
// match product sku with user defined sku
if( (int) $sku == (int) $tmp_product['product']['sku'] ){
// validate the id
$id = $this->validate_request( $tmp_product['product']['id'], 'product', 'read' );
if ( is_wp_error($id) ) {
$products[] = current( $id );
}
else {
$products[] = current( $this->get_product( $product_id, $fields ) );
}
}
}
// check sku was found, do not return empty results
switch ( sizeof($products) ) {
case 0 :
return new WP_Error( 'woocommerce_api_invalid_sku', "Error - sku {$id} not found", array( 'status' => 404 ) );
break;
default:
return array( 'products' => $products );
break;
}
}
}