Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/CC-73-simp…
Browse files Browse the repository at this point in the history
…lify-cart_hash
  • Loading branch information
ggwicz committed Nov 14, 2019
2 parents e5503bb + 01d887d commit f3fc1e9
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 888 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.DS_Store
/vendor/*
/node_modules/*
.nvimrc
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
},
"require": {
"webdevstudios/oops-wp": "^0.1",
"composer/installers": "^1.6",
"firebase/php-jwt": "^5.0"
"composer/installers": "^1.6"
},
"archive": {
"exclude": [
Expand Down
314 changes: 136 additions & 178 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/AbandonedCarts/CartHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function save_cart_data( $user_id, $customer_data ) {
$user_id,
$customer_data['billing']['email'],
maybe_serialize( [
'products' => WC()->cart->get_cart(),
'products' => array_values( WC()->cart->get_cart() ),
'coupons' => WC()->cart->get_applied_coupons(),
'customer' => $customer_data,
'shipping_method' => WC()->checkout()->get_posted_data()['shipping_method'],
Expand Down
61 changes: 0 additions & 61 deletions src/Ajax/GenerateSecretKey.php

This file was deleted.

6 changes: 1 addition & 5 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
use WebDevStudios\CCForWoo\AbandonedCarts\CartHandler;
use WebDevStudios\CCForWoo\AbandonedCarts\CartsTable;
use WebDevStudios\CCForWoo\AbandonedCarts\CartRecovery;
use WebDevStudios\CCForWoo\Ajax\GenerateSecretKey;
use WebDevStudios\CCForWoo\Rest\V1\Registrar as RestRegistrar;
use WebDevStudios\CCForWoo\Rest\V1\AuthHandler as RestAuthHandler;
use WebDevStudios\CCForWoo\Rest\Registrar as RestRegistrar;

/**
* "Core" plugin class.
Expand Down Expand Up @@ -79,8 +77,6 @@ final class Plugin extends ServiceRegistrar {
CartsTable::class,
CartRecovery::class,
RestRegistrar::class,
RestAuthHandler::class,
GenerateSecretKey::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<?php
/**
* REST API endpoint for collection of Abandoned Carts.
* Controller for wc/cc-woo/abandoned-carts endpoint.
*
* @author George Gecewicz <george.gecewicz@webdevstudios.com>
* @package WebDevStudios\CCForWoo\Rest\V1
* @package WebDevStudios\CCForWoo\Rest\AbandonedCarts
* @since 2019-10-16
*/

namespace WebDevStudios\CCForWoo\Rest\V1\Endpoints;
namespace WebDevStudios\CCForWoo\Rest\AbandonedCarts;

use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Controller;
use WP_REST_Response;
use WP_Error;
use WC_Product;

use WebDevStudios\CCForWoo\AbandonedCarts\CartsTable;
use WebDevStudios\CCForWoo\AbandonedCarts\Cart;
use WebDevStudios\CCForWoo\Rest\V1\Registrar;
use WebDevStudios\CCForWoo\Rest\Registrar;

/**
* Class AbandonedCarts
* Class AbandonedCarts\Controller
*
* @author George Gecewicz <george.gecewicz@webdevstudios.com>
* @package WebDevStudios\CCForWoo\Rest\V1
* @package WebDevStudios\CCForWoo\Rest\AbandonedCarts
* @since 2019-10-16
*/
class AbandonedCarts extends WP_REST_Controller {
class Controller extends WP_REST_Controller {

/**
* This endpoint's rest base.
Expand Down Expand Up @@ -55,17 +54,37 @@ public function __construct() {
*/
public function register_routes() {
register_rest_route(
Registrar::$namespace, '/' . $this->rest_base,
Registrar::$namespace,
'/' . $this->rest_base,
[
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_items' ],
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_items' ],
'permission_callback' => [ $this, 'get_items_permissions_check' ],
'args' => Schema::get_collection_params(),
],
'schema' => null,
'schema' => [ '\WebDevStudios\CCForWoo\Rest\AbandonedCarts\Schema', 'get_public_item_schema' ],
]
);
}

/**
* Check whether a given request has permission to show abandoned carts.
*
* @author George Gecewicz <george.gecewicz@webdevstudios.com>
* @since 2019-11-12
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
return new WP_Error( 'cc-woo-rest-not-allowed', esc_html__( 'Sorry, you cannot list resources.', 'cc-woo' ), [ 'status' => rest_authorization_required_code() ] );
}

return true;
}

/**
* Register the Abandoned Carts endpoint.
*
Expand Down Expand Up @@ -188,7 +207,7 @@ private function get_cart_data( int $per_page, int $offset, string $date_min, st
);
// phpcs:enable WordPress.DB.PreparedSQL

return $this->prepare_cart_data_for_api( $data );
return $this->prepare_cart_data_for_api_response( $data );
}

/**
Expand Down Expand Up @@ -230,7 +249,7 @@ private function get_dates_where( string $date_min, string $date_max ) : string
* @param array $data The carts whose fields need preparation.
* @return array
*/
private function prepare_cart_data_for_api( array $data ) {
private function prepare_cart_data_for_api_response( array $data ) {
foreach ( $data as $cart ) {
$cart->cart_contents = maybe_unserialize( $cart->cart_contents );
$cart->cart_contents = $this->get_additional_product_fields( $cart->cart_contents );
Expand Down
Loading

0 comments on commit f3fc1e9

Please sign in to comment.