Plugin Directory

Changeset 2768599


Ignore:
Timestamp:
08/09/2022 10:45:51 PM (4 years ago)
Author:
setaryapp
Message:

Update to version 0.2.0 from GitHub

Location:
setary
Files:
2 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • setary/tags/0.2.0/README.md

    r2767149 r2768599  
    33Tested up to: 6.0.1
    44Requires PHP: 5.6
    5 Stable tag: 0.1.1
     5Stable tag: 0.2.0
    66License: MIT
    77License URI: https://opensource.org/licenses/MIT
     
    5353
    5454== Changelog ==
     55= v0.2.0 (2022-08-09) =
     56* [new] Ability to [edit product categories](https://setary.com/docs/update-product-categories/?utm_source=setary&utm_medium=changelog).
     57
    5558= v0.1.1 (2022-08-03) =
    5659* [fix] Correct permission check when first connecting to Setary.
  • setary/tags/0.2.0/inc/bootstrap.php

    r2767149 r2768599  
    1717function init() {
    1818    add_filter( 'woocommerce_rest_api_get_rest_namespaces', __NAMESPACE__ . '\\get_rest_namespaces' );
     19
     20    $product_controller = new Product_Controller();
     21
     22    add_filter( 'woocommerce_rest_pre_insert_product_object', array( $product_controller, 'pre_insert_product_object' ), 10, 3 );
     23    add_filter( 'woocommerce_rest_pre_insert_product_variation_object', array( $product_controller, 'pre_insert_product_object' ), 10, 3 );
     24    add_filter( 'rest_exposed_cors_headers', array( $product_controller, 'rest_exposed_cors_headers' ) );
    1925}
    2026
  • setary/tags/0.2.0/inc/class-products-with-variations.php

    r2767149 r2768599  
    7373     */
    7474    protected function get_product_data( $product, $context = 'view' ) {
    75 
    7675        $request = new \WP_REST_Request( '', '', [ 'context' => $context ] );
    7776
     
    163162        unset( $item['variations'] );
    164163
     164        $item['formatted_categories'] = $this->format_categories( $item );
     165
    165166        return $item;
    166167    }
     
    175176    protected function prepare_links( $object, $request ) {
    176177        // Remove links from response.
    177         return null;
     178        return array();
    178179    }
    179180
     
    219220        $response->header( 'X-WP-Total', $query_results['total'] );
    220221        $response->header( 'X-WP-TotalPages', (int) $max_pages );
     222        $response->header( 'X-Setary-PluginVersion', SETARY_VERSION );
    221223
    222224        $base          = $this->rest_base;
     
    252254        return $response;
    253255    }
     256
     257    /**
     258     * Format categories for response.
     259     *
     260     * @return string
     261     */
     262    public function format_categories( $item = array() ) {
     263        // Get a formatted list of categories for the product. Display hierarchical categories like "Parent Category > Child Category".
     264        $categories = [];
     265
     266        foreach ( $item['categories'] as $category ) {
     267            $category_structure = array(
     268                $category['name'],
     269            );
     270
     271            $parents = get_ancestors( $category['id'], 'product_cat' );
     272
     273            if ( ! empty( $parents ) ) {
     274                foreach( $parents as $parent ) {
     275                    $category_structure[] = get_term( $parent, 'product_cat' )->name;
     276                }
     277            }
     278
     279            $category_structure = array_reverse( $category_structure );
     280
     281            $categories[] = implode( ' > ', $category_structure );
     282        }
     283
     284        return implode( ' | ', $categories );
     285    }
    254286}
  • setary/tags/0.2.0/setary.php

    r2767149 r2768599  
    1010 * Author:            Setary
    1111 *
    12  * Version:           0.1.1
     12 * Version:           0.2.0
    1313 * Requires at least: 5.7
    1414 * Tested up to:      6.0.1
     
    2222define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2323define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    24 define( 'SETARY_VERSION', '0.1.1' );
     24define( 'SETARY_VERSION', '0.2.0' );
    2525
    2626add_action( 'plugins_loaded', __NAMESPACE__ . '\\plugins_loaded' );
     
    3636    }
    3737
     38    include_once __DIR__ . '/inc/class-product-controller.php';
    3839    include_once __DIR__ . '/inc/class-products-with-variations.php';
    3940    include_once __DIR__ . '/inc/class-info.php';
  • setary/trunk/README.md

    r2767149 r2768599  
    33Tested up to: 6.0.1
    44Requires PHP: 5.6
    5 Stable tag: 0.1.1
     5Stable tag: 0.2.0
    66License: MIT
    77License URI: https://opensource.org/licenses/MIT
     
    5353
    5454== Changelog ==
     55= v0.2.0 (2022-08-09) =
     56* [new] Ability to [edit product categories](https://setary.com/docs/update-product-categories/?utm_source=setary&utm_medium=changelog).
     57
    5558= v0.1.1 (2022-08-03) =
    5659* [fix] Correct permission check when first connecting to Setary.
  • setary/trunk/inc/bootstrap.php

    r2767149 r2768599  
    1717function init() {
    1818    add_filter( 'woocommerce_rest_api_get_rest_namespaces', __NAMESPACE__ . '\\get_rest_namespaces' );
     19
     20    $product_controller = new Product_Controller();
     21
     22    add_filter( 'woocommerce_rest_pre_insert_product_object', array( $product_controller, 'pre_insert_product_object' ), 10, 3 );
     23    add_filter( 'woocommerce_rest_pre_insert_product_variation_object', array( $product_controller, 'pre_insert_product_object' ), 10, 3 );
     24    add_filter( 'rest_exposed_cors_headers', array( $product_controller, 'rest_exposed_cors_headers' ) );
    1925}
    2026
  • setary/trunk/inc/class-products-with-variations.php

    r2767149 r2768599  
    7373     */
    7474    protected function get_product_data( $product, $context = 'view' ) {
    75 
    7675        $request = new \WP_REST_Request( '', '', [ 'context' => $context ] );
    7776
     
    163162        unset( $item['variations'] );
    164163
     164        $item['formatted_categories'] = $this->format_categories( $item );
     165
    165166        return $item;
    166167    }
     
    175176    protected function prepare_links( $object, $request ) {
    176177        // Remove links from response.
    177         return null;
     178        return array();
    178179    }
    179180
     
    219220        $response->header( 'X-WP-Total', $query_results['total'] );
    220221        $response->header( 'X-WP-TotalPages', (int) $max_pages );
     222        $response->header( 'X-Setary-PluginVersion', SETARY_VERSION );
    221223
    222224        $base          = $this->rest_base;
     
    252254        return $response;
    253255    }
     256
     257    /**
     258     * Format categories for response.
     259     *
     260     * @return string
     261     */
     262    public function format_categories( $item = array() ) {
     263        // Get a formatted list of categories for the product. Display hierarchical categories like "Parent Category > Child Category".
     264        $categories = [];
     265
     266        foreach ( $item['categories'] as $category ) {
     267            $category_structure = array(
     268                $category['name'],
     269            );
     270
     271            $parents = get_ancestors( $category['id'], 'product_cat' );
     272
     273            if ( ! empty( $parents ) ) {
     274                foreach( $parents as $parent ) {
     275                    $category_structure[] = get_term( $parent, 'product_cat' )->name;
     276                }
     277            }
     278
     279            $category_structure = array_reverse( $category_structure );
     280
     281            $categories[] = implode( ' > ', $category_structure );
     282        }
     283
     284        return implode( ' | ', $categories );
     285    }
    254286}
  • setary/trunk/setary.php

    r2767149 r2768599  
    1010 * Author:            Setary
    1111 *
    12  * Version:           0.1.1
     12 * Version:           0.2.0
    1313 * Requires at least: 5.7
    1414 * Tested up to:      6.0.1
     
    2222define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2323define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    24 define( 'SETARY_VERSION', '0.1.1' );
     24define( 'SETARY_VERSION', '0.2.0' );
    2525
    2626add_action( 'plugins_loaded', __NAMESPACE__ . '\\plugins_loaded' );
     
    3636    }
    3737
     38    include_once __DIR__ . '/inc/class-product-controller.php';
    3839    include_once __DIR__ . '/inc/class-products-with-variations.php';
    3940    include_once __DIR__ . '/inc/class-info.php';
Note: See TracChangeset for help on using the changeset viewer.