Plugin Directory

Changeset 2595933


Ignore:
Timestamp:
09/09/2021 12:19:47 AM (4 years ago)
Author:
santerref
Message:

Release new version 2.0.1

Location:
mag-products-integration/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • mag-products-integration/trunk/includes/class-admin.php

    r2595518 r2595933  
    173173            <tbody>
    174174            <tr valign="top">
    175                 <td><code>product</code></td>
     175                <td><code>products</code></td>
    176176                <td><strong><?php _e( 'Yes', 'wp-storefront' ) ?></strong></td>
    177                 <td><?php _e( 'The product SKU.', 'wp-storefront' ) ?></td>
     177                <td><?php _e( 'The product SKU or SKUs comma separated for multiple products. The list is sorted by name ascendent.', 'wp-storefront' ) ?></td>
    178178                <td></td>
    179179            </tr>
     
    242242                <td><?php _e( 'No', 'wp-storefront' ) ?></td>
    243243                <td><?php _e( 'Show product short description.', 'wp-storefront' ) ?></td>
     244                <td>true</td>
     245            </tr>
     246            <tr valign="top">
     247                <td><code>url_html_suffix</code></td>
     248                <td><?php _e( 'No', 'wp-storefront' ) ?></td>
     249                <td><?php _e( 'Add the ".html" suffix to all product URLs.', 'wp-storefront' ) ?></td>
    244250                <td>true</td>
    245251            </tr>
  • mag-products-integration/trunk/includes/class-parameters-bag.php

    r2595518 r2595933  
    7777            'class'            => '',
    7878            'product'          => '',
     79            'products'         => '',
    7980            'store'            => null,
    8081            'platform'         => '',
     
    8283            'prefix'           => '',
    8384            'suffix'           => '$',
     85            'url_html_suffix'  => true,
    8486            'image_width'      => '',
    8587            'image_height'     => '',
  • mag-products-integration/trunk/includes/class-plugin.php

    r2595518 r2595933  
    162162
    163163    /**
    164      * The plugin is ready when a valid API endpoint is available.
    165      *
    166      * @return string Valid Magento REST API endpoint or empty string.
    167      * @since 1.0.0
    168      *
    169      */
    170     public function is_ready() {
    171         $is_ready = $this->get_store_manager()->get_store()->ready();
    172 
    173         return $is_ready;
    174     }
    175 
    176     /**
    177164     * Function executed on plugin activation.
    178165     * Update plugin's options to set default values.
     
    246233        $shortcode_cache_id = sha1( serialize( $atts ) );
    247234
    248         $products       = array();
    249         $parameters_bag = Parameters_Bag::createFromShortcode( $atts );
     235        $products = array();
     236        $parameters_bag  = Parameters_Bag::createFromShortcode( $atts );
    250237        if ( Plugin::get_instance()->get_cache()->is_enabled() ) {
    251238            if ( ! Plugin::get_instance()->get_cache()->is_expired( $shortcode_cache_id ) ) {
     
    254241        }
    255242
    256         $platform = $parameters_bag->get( 'platform' );
    257         $product  = $parameters_bag->get( 'product' );
    258         if ( empty( $platform ) || empty( $product ) ) {
    259             return '';
    260         }
    261 
    262243        if ( empty( $products ) ) {
    263             $product = $this->store_manager->get_store( $platform )->get_product( $parameters_bag );
    264             if ( $product instanceof Product ) {
    265                 $products = array( $product );
    266             } elseif ( $product instanceof \WP_Error ) {
    267                 return '<p class="wp-storefront-error">' . $product->get_error_message() . '</p>';
    268             }
     244            $platform    = $parameters_bag->get( 'platform' );
     245            $product_ids = $parameters_bag->get( 'products', $parameters_bag->get( 'product' ) );
     246            if ( empty( $platform ) || empty( $product_ids ) ) {
     247                return '';
     248            }
     249
     250            $products = $this->store_manager->get_store( $platform )->get_products( $parameters_bag );
     251            if ( $products instanceof \WP_Error ) {
     252                return '<p class="wp-storefront-error">' . $products->get_error_message() . '</p>';
     253            }
     254            Plugin::get_instance()->get_cache()->set_cached_products( $products, $shortcode_cache_id );
    269255        }
    270256
     
    293279                                'image_height'       => $parameters_bag->get( 'image_width', 0, 'int' ),
    294280                                'title'              => $parameters_bag->get( 'title', 'h2', 'string' ),
    295                                 'show_description'   => $parameters_bag->get( 'description', true, 'boolean' ),
     281                                'show_description'   => $parameters_bag->get( 'show_description', true, 'boolean' ),
    296282                                'description_length' => $parameters_bag->get( 'description_length', 0, 'int' ),
    297283                                'prefix'             => $parameters_bag->get( 'prefix', '', 'string' ),
  • mag-products-integration/trunk/includes/class-product.php

    r2595518 r2595933  
    127127        ob_start(); ?>
    128128        <img
    129                 src="<?php esc_attr_e( $this->get_image_url() ) ?>"
    130                 alt="<?php esc_attr_e( $this->get_name() ) ?>"
    131                 <?php echo $width ? 'width="' . esc_attr( $width ) . '"' : '' ?>
    132                 <?php echo $height ? 'width="' . esc_attr( $height ) . '"' : '' ?>
     129            src="<?php esc_attr_e( $this->get_image_url() ) ?>"
     130            alt="<?php esc_attr_e( $this->get_name() ) ?>"
     131            <?php echo $width ? 'width="' . esc_attr( $width ) . '"' : '' ?>
     132            <?php echo $height ? 'width="' . esc_attr( $height ) . '"' : '' ?>
    133133        />
    134134        <?php
  • mag-products-integration/trunk/includes/stores/class-store-interface.php

    r2595518 r2595933  
    5454
    5555    /**
    56      * Fetch a single product from e-commerce platform.
     56     * Fetch multiple products by their SKUs or IDs.
    5757     *
    58      * @param Parameters_Bag $parameters_bag Parsed parameters from the [wpsf_product] shortcode.
     58     * @param Parameters_Bag $parameters_bag Parsed parameters from the [wp-storefront] shortcode.
    5959     *
    60      * @return Product
    61      * @since 2.0.0
     60     * @return Product[] Array of products.
     61     * @since 2.0.1
    6262     */
    63     public function get_product( Parameters_Bag $parameters_bag );
     63    public function get_products( Parameters_Bag $parameters_bag );
    6464}
  • mag-products-integration/trunk/includes/stores/class-store-magento2.php

    r2595518 r2595933  
    3131            <td>
    3232                <input type="text" class="regular-text" name="wp_storefront_m2_base_url"
    33                        value="<?php esc_attr_e( get_option( 'wp_storefront_m2_base_url' ) ); ?>"/>
     33                       value="<?php esc_attr_e( get_option( 'wp_storefront_m2_base_url' ) ); ?>"/>
    3434            </td>
    3535        </tr>
     
    3838            <td>
    3939                <input type="password" class="regular-text" name="wp_storefront_m2_access_token"
    40                        value="<?php esc_attr_e( get_option( 'wp_storefront_m2_access_token' ) ); ?>"/>
     40                       value="<?php esc_attr_e( get_option( 'wp_storefront_m2_access_token' ) ); ?>"/>
    4141            </td>
    4242        </tr>
     
    4747     * @inheritdoc
    4848     */
    49     public function get_product( Parameters_Bag $parameters_bag ) {
    50         $product = null;
    51 
    52         $path = '/rest/all/V1/products/' . $parameters_bag->get( 'product' );
     49    public function get_products( Parameters_Bag $parameters_bag ) {
     50        $products = array();
     51        $skus     = array_map( function ( $sku ) {
     52            return trim( $sku );
     53        }, explode( ',', $parameters_bag->get( 'products', $parameters_bag->get( 'product' ) ) ) );
     54
     55        $path = '/rest/all/V1/products';
    5356        if ( $parameters_bag->has( 'store' ) ) {
    54             $path = '/rest/' . $parameters_bag->get( 'store' ) . '/V1/products/' . $parameters_bag->get( 'product' );
     57            $path = '/rest/' . $parameters_bag->get( 'store' ) . '/V1/products';
    5558        }
    5659        $url = Url_Utils::build_url(
    57                 get_option( 'wp_storefront_m2_base_url' ),
    58                 $path
     60            get_option( 'wp_storefront_m2_base_url' ),
     61            $path,
     62            array(
     63                'searchCriteria[pageSize]'                                    => count( $skus ),
     64                'searchCriteria[filterGroups][0][filters][0][value]'          => implode( ',', $skus ),
     65                'searchCriteria[filterGroups][0][filters][0][condition_type]' => 'in',
     66                'searchCriteria[filterGroups][0][filters][0][field]'          => 'sku',
     67                'searchCriteria[sortOrders][0][field]'                        => 'name',
     68                'searchCriteria[sortOrders][0][direction]'                    => 'asc'
     69            )
    5970        );
    6071
    6172        if ( $url ) {
    6273            $response = wp_remote_get( $url, [
    63                     'headers' => [
    64                             'Authorization' => 'Bearer ' . get_option( 'wp_storefront_m2_access_token' ),
    65                     ],
     74                'headers' => array(
     75                    'Authorization' => 'Bearer ' . get_option( 'wp_storefront_m2_access_token' ),
     76                ),
    6677            ] );
    6778
    6879            if ( is_array( $response ) && ! empty( $response['body'] ) && $response['response']['code'] == 200 ) {
    69                 $data    = json_decode( $response['body'], true );
    70                 $product = new Product( [
    71                         'name'              => $data['name'],
    72                         'sku'               => $data['sku'],
    73                         'image_url'         => $this->get_image_url( get_option( 'wp_storefront_m2_base_url' ), $data ),
    74                         'url'               => $this->get_url( get_option( 'wp_storefront_m2_base_url' ), $data ),
    75                         'short_description' => $this->get_custom_attribute( Array_Utils::value( $data, 'custom_attributes', [], 'array' ), 'short_description', '' ),
    76                         'price'             => Array_Utils::value( $data, 'price' ),
    77                         'special_price'     => $this->get_special_price( $data ),
    78                         'raw_data'          => $data
    79                 ] );
    80             }
    81         }
    82 
    83         return $product;
     80                $data = json_decode( $response['body'], true );
     81                if ( isset( $data['items'] ) ) {
     82                    foreach ( $data['items'] as $item ) {
     83                        $products[] = new Product( [
     84                            'name'              => $item['name'],
     85                            'sku'               => $item['sku'],
     86                            'image_url'         => $this->get_image_url( get_option( 'wp_storefront_m2_base_url' ), $item ),
     87                            'url'               => $this->get_url( get_option( 'wp_storefront_m2_base_url' ), $item, $parameters_bag ),
     88                            'short_description' => $this->get_custom_attribute( Array_Utils::value( $item, 'custom_attributes', [], 'array' ), 'short_description', '' ),
     89                            'price'             => Array_Utils::value( $item, 'price' ),
     90                            'special_price'     => $this->get_special_price( $item ),
     91                            'raw_data'          => $item
     92                        ] );
     93                    }
     94                }
     95            }
     96        }
     97
     98        return $products;
    8499    }
    85100
     
    191206     * @param string $base_url The base URL of the Magento 2 store.
    192207     * @param array $product The REST API response data.
     208     * @param Parameters_Bag $parameters_bag The shortcode attributes.
    193209     *
    194210     * @return string The product URL without categories.
    195211     * @since 2.0.0
    196212     */
    197     protected function get_url( $base_url, array $product ) {
     213    protected function get_url( $base_url, array $product, Parameters_Bag $parameters_bag ) {
    198214        $url_key = $this->get_custom_attribute( Array_Utils::value( $product, 'custom_attributes', [], 'array' ), 'url_key', false );
    199215        $url     = '';
    200216
    201217        if ( $url_key ) {
    202             $url = $base_url . '/' . $url_key . '.html';
    203         }
    204 
    205         return $url;
     218            $url = $base_url . '/' . $url_key . ($parameters_bag->get( 'url_html_suffix', true, 'boolean' ) ? '.html' : '');
     219        }
     220
     221        return apply_filters( 'wp_storefront_product_url', $url );
    206222    }
    207223
  • mag-products-integration/trunk/readme.txt

    r2595750 r2595933  
    44Requires at least: 4.6
    55Tested up to: 5.8
    6 Stable tag: 2.0.0
     6Stable tag: 2.0.1
    77License: GPLv2 or later
    88
    9 Drive more visitors to your online store with WP Storefront. A product showcase for Magento 2 that let you show your products into your contents.
     9Drive more visitors to your online store with WP Storefront. A product showcase for Magento 2 that let you show your products into your articles and page.
    1010
    1111== Description ==
     
    4646
    4747== Changelog ==
     48
     49= 2.0.1 =
     50* NEW You can now show multiple products by separating multiple SKUs by commas
     51* FIX New shortcode attribute to remove the ".html" suffix to the URL: url_html_suffix="false"
     52* FIX You can now hide the description with the show_description attribute
     53* FIX Cached products not working
    4854
    4955= 2.0.0 =
  • mag-products-integration/trunk/wp-storefront.php

    r2595518 r2595933  
    1212Plugin URI: https://wordpress.org/plugins/mag-products-integration/
    1313Description: Display products from your favourite Ecommerce platform directly into your articles and pages.
    14 Version: 2.0.0
     14Version: 2.0.1
    1515Requires at least: 4.6
    1616Author: Francis Santerre
     
    2020*/
    2121
    22 define( 'WP_STOREFRONT_PLUGIN_VERSION', '2.0.0' );
     22define( 'WP_STOREFRONT_PLUGIN_VERSION', '2.0.1' );
    2323define( 'WP_STOREFRONT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    2424
Note: See TracChangeset for help on using the changeset viewer.