Plugin Directory

Changeset 2460774


Ignore:
Timestamp:
01/22/2021 07:00:54 AM (5 years ago)
Author:
everlytic
Message:

Update to version 1.3 from GitHub

Location:
everlytic
Files:
12 added
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • everlytic/tags/1.3/index.php

    r2394349 r2460774  
    2727require_once plugin_dir_path(__FILE__) . 'src/EvConstants.php';
    2828require_once plugin_dir_path(__FILE__) . 'src/Events/AbandonedCart/EvCart.php';
     29require_once plugin_dir_path(__FILE__) . 'src/Coupons/EvCouponRepository.php';
     30require_once plugin_dir_path(__FILE__) . 'src/Coupons/EvCoupons.php';
    2931require_once plugin_dir_path(__FILE__) . 'src/Events/AbandonedCart/EvAbandonedCartHydrator.php';
    3032require_once plugin_dir_path(__FILE__) . 'src/EvConstants.php';
     
    9597                new EvProducts()
    9698            ),
     99            new EvCoupons(
     100                new EvCouponRepository()
     101            ),
    97102            new EvUserSyncer(
    98103                new EvUserRepository(),
  • everlytic/tags/1.3/src/EvPluginDeactivator.php

    r2394223 r2460774  
    3333        $this->databaseDeleter->delete();
    3434        $this->evProductTrackingDeleter->delete();
    35         $timestamp = wp_next_scheduled('evAbandonedCartCronJob');
    36         wp_unschedule_event($timestamp, 'evAbandonedCartCronJob');
    3735        delete_option('ev_db_version');
    3836        delete_option('ev_store_hash');
  • everlytic/tags/1.3/src/Events/AbandonedCart/EvCart.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../../Traits/EvAuthenticationTrait.php';
    23
    34class EvCart
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    69     * @var EvProducts
     
    3033    public function get($requestData)
    3134    {
    32         if (is_user_logged_in() === false) {
    33             return new WP_REST_Response('User not logged in', 404);
     35        if ($this->authenticate() === false) {
     36            return new WP_REST_Response($this->getError(), 401);
    3437        }
     38
    3539        $parameters = $requestData->get_params();
    3640        $email = $parameters['customer_email'];
  • everlytic/tags/1.3/src/Events/AbandonedCart/EvDispatcher.php

    r2394223 r2460774  
    2727    public function schedule()
    2828    {
    29         if(wp_next_scheduled('evAbandonedCartCronJob') === false) {
    30             wp_schedule_event(time(),'one_minute','evAbandonedCartCronJob');
     29        if (false === as_next_scheduled_action('ev_abandoned_cart_scheduler')) {
     30            as_schedule_recurring_action( time(), 60, 'ev_abandoned_cart_scheduler');
    3131        }
    3232    }
  • everlytic/tags/1.3/src/EverlyticWoocommerce.php

    r2407293 r2460774  
    7070     */
    7171    private $cart;
     72
     73    /**
     74     * @var EvCoupons
     75     */
     76    private $coupons;
    7277
    7378    /**
     
    103108     * @param EvHTTPClient $evHTTPClient
    104109     * @param EvCart $cart
     110     * @param EvCoupons $coupons
    105111     * @param EvUserSyncer $evUserSyncer
     112     * @param EvProductCategories $evProductCategories
    106113     * @param EvProductSearch $evProductSearch
    107      * @param EvProductCategories $evProductCategories
    108114     * @param EvAbandonedCartHydrator $abandonedCartHydrator
    109115     */
     
    120126        EvHTTPClient $evHTTPClient,
    121127        EvCart $cart,
     128        EvCoupons $coupons,
    122129        EvUserSyncer $evUserSyncer,
    123130        EvProductCategories $evProductCategories,
     
    136143        $this->evHTTPClient = $evHTTPClient;
    137144        $this->cart = $cart;
     145        $this->coupons = $coupons;
    138146        $this->userSyncer = $evUserSyncer;
    139147        $this->evProductCategories = $evProductCategories;
     
    150158        add_action('init', [$this, 'registerUserSyncScheduler']);
    151159        add_action('ev_user_sync_scheduler', [$this, 'runUserSyncTask']);
     160        add_action('init', [$this, 'abandonedCartCronScheduler']);
     161        add_action('ev_abandoned_cart_scheduler', [$this->dispatcher, 'dispatcher']);
    152162        add_action('template_redirect', [$this->cartLogger, 'initialize']);
    153163        add_action('template_redirect', [$this->abandonedCartHydrator, 'hydrate']);
    154164        add_action('rest_api_init', [$this, 'registerRoutes']);
    155         add_filter('cron_schedules', [$this, 'abandonedCartCronInterval']);
    156165        add_action('wp', [$this->dispatcher, 'schedule']);
    157166        add_filter('woocommerce_product_data_store_cpt_get_products_query', [$this->evProductSearch, 'handleEVCustomSearch'], 10, 2 );
    158         add_action('evAbandonedCartCronJob', [$this->dispatcher, 'dispatcher']);
    159167        add_action('woocommerce_created_customer', [$this, 'createLastUpdate'], 10, 3 );
    160168
     
    190198     * @return mixed
    191199     */
    192     public function abandonedCartCronInterval($schedules)
    193     {
    194         $schedules['one_minute'] = array(
    195             'interval' => 60,
    196             'display' => esc_html__('Every One Minute'),
    197         );
    198         return $schedules;
     200    public function abandonedCartCronScheduler()
     201    {
     202        if (false === as_next_scheduled_action('ev_abandoned_cart_scheduler')) {
     203            as_schedule_recurring_action( time(), 60, 'ev_abandoned_cart_scheduler');
     204        }
    199205    }
    200206
     
    257263                'methods' => WP_REST_Server::CREATABLE,
    258264                'callback' => [$this->cart, 'get'],
     265                'permission_callback' => '__return_true'
     266            ]
     267        );
     268
     269        register_rest_route(self::API_NAMESPACE, '/coupons', [
     270                'methods' => WP_REST_Server::READABLE,
     271                'callback' => [$this->coupons, 'get'],
    259272                'permission_callback' => '__return_true'
    260273            ]
  • everlytic/tags/1.3/src/Product/EvFeaturedProducts.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23require_once plugin_dir_path( __FILE__ ) . 'Utilities/EvFormatter.php';
    34
    45class EvFeaturedProducts
    56{
     7    use EvAuthenticationTrait;
     8
     9    /**
     10     * @return array|WP_REST_Response|null
     11     */
    612    public function get()
    713    {
     14        if ($this->authenticate() === false) {
     15            return new WP_REST_Response($this->getError(), 401);
     16        }
     17
    818        $posts = wc_get_products([
    9             'post_type'      => 'product',
     19            'post_type' => 'product',
    1020            'posts_per_page' => 10,
    1121            'post_status' => 'publish',
    12             'post__in'  => wc_get_featured_product_ids(),
     22            'post__in' => wc_get_featured_product_ids(),
    1323        ]);
    1424
  • everlytic/tags/1.3/src/Product/EvProductCategories.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23
    34class EvProductCategories
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    6      * @return array
     9     * @return array[]|WP_REST_Response
    710     */
    811    public function get()
    912    {
     13        if ($this->authenticate() === false) {
     14            return new WP_REST_Response($this->getError(), 401);
     15        }
     16
    1017        $args = [
    11             'taxonomy'     => 'product_cat',
    12             'orderby'      => 'name',
    13             'show_count'   => 0,
    14             'pad_counts'   => 0,
     18            'taxonomy' => 'product_cat',
     19            'orderby' => 'name',
     20            'show_count' => 0,
     21            'pad_counts' => 0,
    1522            'hierarchical' => 1,
    16             'title_li'     => '',
    17             'hide_empty'   => 0
     23            'title_li' => '',
     24            'hide_empty' => 0
    1825        ];
    1926
  • everlytic/tags/1.3/src/Product/EvProductSearch.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23
    34class EvProductSearch
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    69     * @var array
     
    811    private $argument = [];
    912
     13    /**
     14     * @param $requestData
     15     * @return array|WP_REST_Response
     16     */
    1017    public function search($requestData)
    1118    {
     19        if ($this->authenticate() === false) {
     20            return new WP_REST_Response($this->getError(), 401);
     21        }
     22
    1223        $this->argument = ['status' => 'publish', 'limit' => 30, 'post_type' => 'product'];
    1324        $parameters = json_decode($requestData->get_body());
     
    1829        $this->setPriceRange($parameters);
    1930        $this->setReturnOrder($parameters);
     31
    2032        return EvFormatter::formatProducts(wc_get_products($this->argument), [], false);
    2133    }
  • everlytic/tags/1.3/src/Product/EvProducts.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23require_once plugin_dir_path( __FILE__ ) . 'Utilities/EvFormatter.php';
    34
    45class EvProducts
    56{
     7    use EvAuthenticationTrait;
     8
     9    /**
     10     * @param $requestData
     11     * @return array|WP_REST_Response|null
     12     */
    613    public function get($requestData)
    714    {
     15        if ($this->authenticate() === false) {
     16            return new WP_REST_Response($this->getError(), 401);
     17        }
     18
    819        $parameters = $requestData->get_params();
    920        $posts = wc_get_products([
     
    3546    }
    3647
     48    /**
     49     * @param $ids
     50     * @return array|WP_REST_Response|null
     51     */
    3752    public function getByIds($ids)
    3853    {
     54        if ($this->authenticate() === false) {
     55            return new WP_REST_Response($this->getError(), 401);
     56        }
     57
    3958        if (empty($ids)) {
    4059            return null;
  • everlytic/tags/1.3/src/Store/EvStoreDetailsSaver.php

    r2394223 r2460774  
    1717    public function save($requestData)
    1818    {
     19        if ($this->authenticateStoreSetup() === false) {
     20            return new WP_REST_Response('Incorrect store setup', 401);
     21        }
     22
    1923        $parameters = $requestData->get_params();
     24
    2025        return $this->isInvalid($parameters)
    2126            ? $this->handleFailure($parameters)
    2227            : $this->handleSuccess($parameters);
     28    }
     29
     30    private function authenticateStoreSetup()
     31    {
     32        if (get_option("ev_install_url") === false &&
     33            get_option('ev_store_hash') === false &&
     34            get_option('ev_customer_hash') === false
     35        ) {
     36            $hasReferer = (is_null($_SERVER["HTTP_REFERER"]) === false &&
     37                empty($_SERVER["HTTP_REFERER"]) === false) ? parse_url($_SERVER["HTTP_REFERER"])['host'] : false;
     38            $hasInstallUrl = (is_null($_REQUEST['ev_install_url']) === false &&
     39                empty($_REQUEST['ev_install_url']) === false) ? parse_url($_REQUEST['ev_install_url'])['host'] : false;
     40
     41            return $hasReferer === $hasInstallUrl;
     42        }
    2343    }
    2444
  • everlytic/trunk/index.php

    r2394349 r2460774  
    2727require_once plugin_dir_path(__FILE__) . 'src/EvConstants.php';
    2828require_once plugin_dir_path(__FILE__) . 'src/Events/AbandonedCart/EvCart.php';
     29require_once plugin_dir_path(__FILE__) . 'src/Coupons/EvCouponRepository.php';
     30require_once plugin_dir_path(__FILE__) . 'src/Coupons/EvCoupons.php';
    2931require_once plugin_dir_path(__FILE__) . 'src/Events/AbandonedCart/EvAbandonedCartHydrator.php';
    3032require_once plugin_dir_path(__FILE__) . 'src/EvConstants.php';
     
    9597                new EvProducts()
    9698            ),
     99            new EvCoupons(
     100                new EvCouponRepository()
     101            ),
    97102            new EvUserSyncer(
    98103                new EvUserRepository(),
  • everlytic/trunk/src/EvPluginDeactivator.php

    r2394223 r2460774  
    3333        $this->databaseDeleter->delete();
    3434        $this->evProductTrackingDeleter->delete();
    35         $timestamp = wp_next_scheduled('evAbandonedCartCronJob');
    36         wp_unschedule_event($timestamp, 'evAbandonedCartCronJob');
    3735        delete_option('ev_db_version');
    3836        delete_option('ev_store_hash');
  • everlytic/trunk/src/Events/AbandonedCart/EvCart.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../../Traits/EvAuthenticationTrait.php';
    23
    34class EvCart
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    69     * @var EvProducts
     
    3033    public function get($requestData)
    3134    {
    32         if (is_user_logged_in() === false) {
    33             return new WP_REST_Response('User not logged in', 404);
     35        if ($this->authenticate() === false) {
     36            return new WP_REST_Response($this->getError(), 401);
    3437        }
     38
    3539        $parameters = $requestData->get_params();
    3640        $email = $parameters['customer_email'];
  • everlytic/trunk/src/Events/AbandonedCart/EvDispatcher.php

    r2394223 r2460774  
    2727    public function schedule()
    2828    {
    29         if(wp_next_scheduled('evAbandonedCartCronJob') === false) {
    30             wp_schedule_event(time(),'one_minute','evAbandonedCartCronJob');
     29        if (false === as_next_scheduled_action('ev_abandoned_cart_scheduler')) {
     30            as_schedule_recurring_action( time(), 60, 'ev_abandoned_cart_scheduler');
    3131        }
    3232    }
  • everlytic/trunk/src/EverlyticWoocommerce.php

    r2407293 r2460774  
    7070     */
    7171    private $cart;
     72
     73    /**
     74     * @var EvCoupons
     75     */
     76    private $coupons;
    7277
    7378    /**
     
    103108     * @param EvHTTPClient $evHTTPClient
    104109     * @param EvCart $cart
     110     * @param EvCoupons $coupons
    105111     * @param EvUserSyncer $evUserSyncer
     112     * @param EvProductCategories $evProductCategories
    106113     * @param EvProductSearch $evProductSearch
    107      * @param EvProductCategories $evProductCategories
    108114     * @param EvAbandonedCartHydrator $abandonedCartHydrator
    109115     */
     
    120126        EvHTTPClient $evHTTPClient,
    121127        EvCart $cart,
     128        EvCoupons $coupons,
    122129        EvUserSyncer $evUserSyncer,
    123130        EvProductCategories $evProductCategories,
     
    136143        $this->evHTTPClient = $evHTTPClient;
    137144        $this->cart = $cart;
     145        $this->coupons = $coupons;
    138146        $this->userSyncer = $evUserSyncer;
    139147        $this->evProductCategories = $evProductCategories;
     
    150158        add_action('init', [$this, 'registerUserSyncScheduler']);
    151159        add_action('ev_user_sync_scheduler', [$this, 'runUserSyncTask']);
     160        add_action('init', [$this, 'abandonedCartCronScheduler']);
     161        add_action('ev_abandoned_cart_scheduler', [$this->dispatcher, 'dispatcher']);
    152162        add_action('template_redirect', [$this->cartLogger, 'initialize']);
    153163        add_action('template_redirect', [$this->abandonedCartHydrator, 'hydrate']);
    154164        add_action('rest_api_init', [$this, 'registerRoutes']);
    155         add_filter('cron_schedules', [$this, 'abandonedCartCronInterval']);
    156165        add_action('wp', [$this->dispatcher, 'schedule']);
    157166        add_filter('woocommerce_product_data_store_cpt_get_products_query', [$this->evProductSearch, 'handleEVCustomSearch'], 10, 2 );
    158         add_action('evAbandonedCartCronJob', [$this->dispatcher, 'dispatcher']);
    159167        add_action('woocommerce_created_customer', [$this, 'createLastUpdate'], 10, 3 );
    160168
     
    190198     * @return mixed
    191199     */
    192     public function abandonedCartCronInterval($schedules)
    193     {
    194         $schedules['one_minute'] = array(
    195             'interval' => 60,
    196             'display' => esc_html__('Every One Minute'),
    197         );
    198         return $schedules;
     200    public function abandonedCartCronScheduler()
     201    {
     202        if (false === as_next_scheduled_action('ev_abandoned_cart_scheduler')) {
     203            as_schedule_recurring_action( time(), 60, 'ev_abandoned_cart_scheduler');
     204        }
    199205    }
    200206
     
    257263                'methods' => WP_REST_Server::CREATABLE,
    258264                'callback' => [$this->cart, 'get'],
     265                'permission_callback' => '__return_true'
     266            ]
     267        );
     268
     269        register_rest_route(self::API_NAMESPACE, '/coupons', [
     270                'methods' => WP_REST_Server::READABLE,
     271                'callback' => [$this->coupons, 'get'],
    259272                'permission_callback' => '__return_true'
    260273            ]
  • everlytic/trunk/src/Product/EvFeaturedProducts.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23require_once plugin_dir_path( __FILE__ ) . 'Utilities/EvFormatter.php';
    34
    45class EvFeaturedProducts
    56{
     7    use EvAuthenticationTrait;
     8
     9    /**
     10     * @return array|WP_REST_Response|null
     11     */
    612    public function get()
    713    {
     14        if ($this->authenticate() === false) {
     15            return new WP_REST_Response($this->getError(), 401);
     16        }
     17
    818        $posts = wc_get_products([
    9             'post_type'      => 'product',
     19            'post_type' => 'product',
    1020            'posts_per_page' => 10,
    1121            'post_status' => 'publish',
    12             'post__in'  => wc_get_featured_product_ids(),
     22            'post__in' => wc_get_featured_product_ids(),
    1323        ]);
    1424
  • everlytic/trunk/src/Product/EvProductCategories.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23
    34class EvProductCategories
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    6      * @return array
     9     * @return array[]|WP_REST_Response
    710     */
    811    public function get()
    912    {
     13        if ($this->authenticate() === false) {
     14            return new WP_REST_Response($this->getError(), 401);
     15        }
     16
    1017        $args = [
    11             'taxonomy'     => 'product_cat',
    12             'orderby'      => 'name',
    13             'show_count'   => 0,
    14             'pad_counts'   => 0,
     18            'taxonomy' => 'product_cat',
     19            'orderby' => 'name',
     20            'show_count' => 0,
     21            'pad_counts' => 0,
    1522            'hierarchical' => 1,
    16             'title_li'     => '',
    17             'hide_empty'   => 0
     23            'title_li' => '',
     24            'hide_empty' => 0
    1825        ];
    1926
  • everlytic/trunk/src/Product/EvProductSearch.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23
    34class EvProductSearch
    45{
     6    use EvAuthenticationTrait;
     7
    58    /**
    69     * @var array
     
    811    private $argument = [];
    912
     13    /**
     14     * @param $requestData
     15     * @return array|WP_REST_Response
     16     */
    1017    public function search($requestData)
    1118    {
     19        if ($this->authenticate() === false) {
     20            return new WP_REST_Response($this->getError(), 401);
     21        }
     22
    1223        $this->argument = ['status' => 'publish', 'limit' => 30, 'post_type' => 'product'];
    1324        $parameters = json_decode($requestData->get_body());
     
    1829        $this->setPriceRange($parameters);
    1930        $this->setReturnOrder($parameters);
     31
    2032        return EvFormatter::formatProducts(wc_get_products($this->argument), [], false);
    2133    }
  • everlytic/trunk/src/Product/EvProducts.php

    r2394223 r2460774  
    11<?php
     2require_once plugin_dir_path(__FILE__) . '../Traits/EvAuthenticationTrait.php';
    23require_once plugin_dir_path( __FILE__ ) . 'Utilities/EvFormatter.php';
    34
    45class EvProducts
    56{
     7    use EvAuthenticationTrait;
     8
     9    /**
     10     * @param $requestData
     11     * @return array|WP_REST_Response|null
     12     */
    613    public function get($requestData)
    714    {
     15        if ($this->authenticate() === false) {
     16            return new WP_REST_Response($this->getError(), 401);
     17        }
     18
    819        $parameters = $requestData->get_params();
    920        $posts = wc_get_products([
     
    3546    }
    3647
     48    /**
     49     * @param $ids
     50     * @return array|WP_REST_Response|null
     51     */
    3752    public function getByIds($ids)
    3853    {
     54        if ($this->authenticate() === false) {
     55            return new WP_REST_Response($this->getError(), 401);
     56        }
     57
    3958        if (empty($ids)) {
    4059            return null;
  • everlytic/trunk/src/Store/EvStoreDetailsSaver.php

    r2394223 r2460774  
    1717    public function save($requestData)
    1818    {
     19        if ($this->authenticateStoreSetup() === false) {
     20            return new WP_REST_Response('Incorrect store setup', 401);
     21        }
     22
    1923        $parameters = $requestData->get_params();
     24
    2025        return $this->isInvalid($parameters)
    2126            ? $this->handleFailure($parameters)
    2227            : $this->handleSuccess($parameters);
     28    }
     29
     30    private function authenticateStoreSetup()
     31    {
     32        if (get_option("ev_install_url") === false &&
     33            get_option('ev_store_hash') === false &&
     34            get_option('ev_customer_hash') === false
     35        ) {
     36            $hasReferer = (is_null($_SERVER["HTTP_REFERER"]) === false &&
     37                empty($_SERVER["HTTP_REFERER"]) === false) ? parse_url($_SERVER["HTTP_REFERER"])['host'] : false;
     38            $hasInstallUrl = (is_null($_REQUEST['ev_install_url']) === false &&
     39                empty($_REQUEST['ev_install_url']) === false) ? parse_url($_REQUEST['ev_install_url'])['host'] : false;
     40
     41            return $hasReferer === $hasInstallUrl;
     42        }
    2343    }
    2444
Note: See TracChangeset for help on using the changeset viewer.