Merge pull request #17926 from woocommerce/add/search-functionality-extensions-page

Adds search functionality to extensions page
This commit is contained in:
Gerhard Potgieter 2017-12-08 10:48:38 +02:00 committed by GitHub
commit 0c5a0b06cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 424 additions and 43 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,36 @@
.wc_addons_wrap {
h1.search-form-title {
clear: left;
padding: 0;
}
form.search-form {
clear: both;
display: block;
position: relative;
margin-top: 1em;
width: 100%;
input {
border: none;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
height: 53px;
padding-left: 50px;
width: 100%;
}
button {
background: none;
border: none;
cursor: pointer;
height: 53px;
position: absolute;
width: 53px;
}
}
.update-plugins .update-count {
background-color: #d54e21;
border-radius: 10px;
@ -36,7 +66,18 @@
.addons-featured {
max-width: 1140px;
margin: -1%;
}
ul.subsubsub.subsubsub {
margin: -2px 0 12px;
}
.subsubsub li::after {
content: '|';
}
.subsubsub li:last-child::after {
content: '';
}
.addons-banner-block-item-icon,
@ -50,7 +91,7 @@
.addons-wcs-banner-block {
background: #ffffff;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
margin: 2% 1% 0;
margin: 2% 0;
max-width: 1140px;
padding: 20px;
}
@ -437,6 +478,7 @@
.storefront {
background: url('../images/storefront-bg.jpg') bottom right #f6f6f6;
border: 1px solid #ddd;
margin-top: 1em;
padding: 20px;
overflow: hidden;
zoom: 1;

View File

@ -4,7 +4,11 @@ msgid ""
msgstr ""
"Project-Id-Version: WooCommerce 3.3-dev\n"
"Report-Msgid-Bugs-To: https://github.com/woocommerce/woocommerce/issues\n"
<<<<<<< HEAD
"POT-Creation-Date: 2017-12-07 17:02:20+00:00\n"
=======
"POT-Creation-Date: 2017-12-07 16:50:27+00:00\n"
>>>>>>> master
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
@ -6198,35 +6202,59 @@ msgstr ""
msgid "Items"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:128
#: includes/admin/class-wc-admin-addons.php:156
msgid "Need a fresh look? Try Storefront child themes"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:132
#: includes/admin/class-wc-admin-addons.php:160
msgid "View more Storefront child themes"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:137
#: includes/admin/class-wc-admin-addons.php:165
msgid "Need a theme? Try Storefront"
msgstr ""
<<<<<<< HEAD
#: includes/admin/class-wc-admin-addons.php:364
#: includes/admin/class-wc-admin-addons.php:535
=======
#: includes/admin/class-wc-admin-addons.php:338
#: includes/admin/class-wc-admin-addons.php:502
>>>>>>> master
#: includes/admin/class-wc-admin-setup-wizard.php:615
msgid "WooCommerce Services"
msgstr ""
<<<<<<< HEAD
#: includes/admin/class-wc-admin-addons.php:365
msgid "Buy discounted shipping labels — then print them from your dashboard."
msgstr ""
#: includes/admin/class-wc-admin-addons.php:366
=======
#: includes/admin/class-wc-admin-addons.php:339
msgid "Buy discounted shipping labels — then print them from your dashboard."
msgstr ""
#: includes/admin/class-wc-admin-addons.php:340
>>>>>>> master
msgid ""
"Integrate your store with USPS to buy discounted shipping labels, and print "
"them directly from your WooCommerce dashboard. Powered by WooCommerce "
"Services."
msgstr ""
<<<<<<< HEAD
#: includes/admin/class-wc-admin-addons.php:367
msgid "Free - Install now"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:376
msgid "Show Canada Post shipping rates"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:377
=======
#: includes/admin/class-wc-admin-addons.php:341
msgid "Free - Install now"
msgstr ""
@ -6236,16 +6264,25 @@ msgid "Show Canada Post shipping rates"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:351
>>>>>>> master
msgid ""
"Display live rates from Canada Post at checkout to make shipping a breeze. "
"Powered by WooCommerce Services."
msgstr ""
<<<<<<< HEAD
#: includes/admin/class-wc-admin-addons.php:478
msgid "Free"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:480
=======
#: includes/admin/class-wc-admin-addons.php:452
msgid "Free"
msgstr ""
#: includes/admin/class-wc-admin-addons.php:454
>>>>>>> master
#: includes/admin/helper/class-wc-helper.php:331
msgid "Installed"
msgstr ""
@ -12797,6 +12834,7 @@ msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:88
msgid "Manage stock"
<<<<<<< HEAD
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:89
@ -13028,6 +13066,239 @@ msgstr ""
msgid "Enable AJAX add to cart buttons on archives"
msgstr ""
=======
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:89
msgid "Enable stock management"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:96
msgid "Hold stock (minutes)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:97
msgid ""
"Hold stock (for unpaid orders) for x minutes. When this limit is reached, "
"the pending order will be cancelled. Leave blank to disable."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:111
msgid "Notifications"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:112
msgid "Enable low stock notifications"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:122
msgid "Enable out of stock notifications"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:132
msgid "Notification recipient(s)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:133
msgid "Enter recipients (comma separated) that will receive this notification."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:144
msgid "Low stock threshold"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:145
msgid "When product stock reaches this amount you will be notified via email."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:160
msgid "Out of stock threshold"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:161
msgid ""
"When product stock reaches this amount the stock status will change to "
"\"out of stock\" and you will be notified via email. This setting does not "
"affect existing \"in stock\" products."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:175
msgid "Out of stock visibility"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:176
msgid "Hide out of stock items from the catalog"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:183
msgid "Stock display format"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:184
msgid "This controls how stock quantities are displayed on the frontend."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:191
msgid "Always show quantity remaining in stock e.g. \"12 in stock\""
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:192
msgid "Only show quantity remaining in stock when low e.g. \"Only 2 left in stock\""
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:193
msgid "Never show quantity remaining in stock"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:214
msgid "File download method"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:217
#. translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile
msgid ""
"Forcing downloads will keep URLs hidden, but some servers may serve large "
"files unreliably. If supported, %1$s / %2$s can be used to serve downloads "
"instead (server requires %3$s)."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:229
msgid "Force downloads"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:230
msgid "X-Accel-Redirect/X-Sendfile"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:231
msgid "Redirect only"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:237
msgid "Access restriction"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:238
msgid "Downloads require login"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:242
msgid "This setting does not apply to guest purchases."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:248
msgid "Grant access to downloadable products after payment"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:252
msgid ""
"Enable this option to grant access to downloads when orders are "
"\"processing\", rather than \"completed\"."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:267
msgid "Shop pages"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:273
msgid "Shop page"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:274
msgid ""
"The base page can also be used in your <a href=\"%s\">product "
"permalinks</a>."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:280
msgid ""
"This sets the base page of your shop - this is where your product archive "
"will be."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:283
msgid "Shop page display"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:284
msgid "This controls what is shown on the product archive."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:291
#: includes/admin/settings/class-wc-settings-products.php:306
msgid "Show products"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:292
msgid "Show categories"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:293
msgid "Show categories &amp; products"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:298
msgid "Default category display"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:299
msgid "This controls what is shown on category archives."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:307
msgid "Show subcategories"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:308
msgid "Show subcategories &amp; products"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:313
msgid "Default product sorting"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:314
msgid "This controls the default sort order of the catalog."
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:321
msgid "Default sorting (custom ordering + name)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:322
msgid "Popularity (sales)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:323
#: includes/widgets/class-wc-widget-rating-filter.php:30
msgid "Average rating"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:324
msgid "Sort by most recent"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:325
msgid "Sort by price (asc)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:326
msgid "Sort by price (desc)"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:331
msgid "Add to cart behaviour"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:332
msgid "Redirect to the cart page after successful addition"
msgstr ""
#: includes/admin/settings/class-wc-settings-products.php:339
msgid "Enable AJAX add to cart buttons on archives"
msgstr ""
>>>>>>> master
#: includes/admin/settings/class-wc-settings-products.php:351
msgid "Measurements"
msgstr ""
@ -13877,32 +14148,40 @@ msgstr ""
msgid "Itemized"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:82
#: includes/admin/views/html-admin-page-addons.php:41
msgid "Showing search results for: %s"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:53
msgid "Enter a search term and press enter"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:107
msgid ""
"Our catalog of WooCommerce Extensions can be found on WooCommerce.com here: "
"<a href=\"%s\">WooCommerce Extensions Catalog</a>"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:88
#: includes/admin/views/html-admin-page-addons.php:113
msgid "Looking for a WooCommerce theme?"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:89
#: includes/admin/views/html-admin-page-addons.php:114
msgid "We recommend Storefront, the <em>official</em> WooCommerce theme."
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:90
#: includes/admin/views/html-admin-page-addons.php:115
msgid ""
"Storefront is an intuitive, flexible and <strong>free</strong> WordPress "
"theme offering deep integration with WooCommerce and many of the most "
"popular customer-facing extensions."
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:92
#: includes/admin/views/html-admin-page-addons.php:117
msgid "Read all about it"
msgstr ""
#: includes/admin/views/html-admin-page-addons.php:93
#: includes/admin/views/html-admin-page-addons.php:118
msgid "Download &amp; install"
msgstr ""

View File

@ -39,36 +39,64 @@ class WC_Admin_Addons {
}
}
/**
* Build url parameter string
*
* @param string $category
* @param string $term
* @param string $country
*
* @return string url parameter string
*/
public static function build_parameter_string( $category, $term, $country ) {
$paramters = array(
'category' => $category,
'term' => $term,
'country' => $country,
);
return '?' . http_build_query( $paramters );
}
/**
* Call API to get extensions
*
* @param string $category
* @param string $term
* @param string $country
*
* @return array of extensions
*/
public static function get_extension_data( $category, $term, $country ) {
$parameters = self::build_parameter_string( $category, $term, $country );
$raw_extensions = wp_remote_get(
'https://woocommerce.com/wp-json/wccom-extensions/1.0/search' . $parameters
);
if ( ! is_wp_error( $raw_extensions ) ) {
$addons = json_decode( wp_remote_retrieve_body( $raw_extensions ) )->products;
}
return $addons;
}
/**
* Get sections for the addons screen
*
* @return array of objects
*/
public static function get_sections() {
if ( false === ( $sections = get_transient( 'wc_addons_sections' ) ) ) {
$raw_sections = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/addon-sections.json', array( 'user-agent' => 'WooCommerce Addons Page' ) );
$addon_sections = get_transient( 'wc_addons_sections' );
if ( false === ( $addon_sections ) ) {
$raw_sections = wp_safe_remote_get(
'https://woocommerce.com/wp-json/wccom-extensions/1.0/categories'
);
if ( ! is_wp_error( $raw_sections ) ) {
$sections = json_decode( wp_remote_retrieve_body( $raw_sections ) );
if ( $sections ) {
set_transient( 'wc_addons_sections', $sections, WEEK_IN_SECONDS );
$addon_sections = json_decode( wp_remote_retrieve_body( $raw_sections ) );
if ( $addon_sections ) {
set_transient( 'wc_addons_sections', $addon_sections, WEEK_IN_SECONDS );
}
}
}
$addon_sections = array();
if ( $sections ) {
foreach ( $sections as $sections_id => $section ) {
if ( empty( $sections_id ) ) {
continue;
}
$addon_sections[ $sections_id ] = new stdClass;
$addon_sections[ $sections_id ]->title = wc_clean( $section->title );
$addon_sections[ $sections_id ]->endpoint = wc_clean( $section->endpoint );
}
}
return apply_filters( 'woocommerce_addons_sections', $addon_sections );
}
@ -477,15 +505,22 @@ class WC_Admin_Addons {
$sections = self::get_sections();
$theme = wp_get_theme();
$section_keys = array_keys( $sections );
$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : '_featured';
$addons = array();
if ( '_featured' !== $current_section ) {
$category = isset( $_GET['section'] ) ? $_GET['section'] : null;
$term = isset( $_GET['search'] ) ? $_GET['search'] : null;
$country = WC()->countries->get_base_country();
$addons = self::get_extension_data( $category, $term, $country );
}
/**
* Addon page view.
*
* @uses $addons
* @uses $sections
* @uses $theme
* @uses $section_keys
* @uses $current_section
*/
include_once( dirname( __FILE__ ) . '/views/html-admin-page-addons.php' );

View File

@ -25,19 +25,44 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php if ( $sections ) : ?>
<ul class="subsubsub">
<?php foreach ( $sections as $section_id => $section ) : ?>
<li><a class="<?php echo $current_section === $section_id ? 'current' : ''; ?>" href="<?php echo admin_url( 'admin.php?page=wc-addons&section=' . esc_attr( $section_id ) ); ?>"><?php echo esc_html( $section->title ); ?></a><?php echo ( end( $section_keys ) !== $section_id ) ? ' |' : ''; ?></li>
<?php foreach ( $sections as $section ) : ?>
<li>
<a
class="<?php echo $current_section === $section->slug ? 'current' : ''; ?>"
href="<?php echo admin_url( 'admin.php?page=wc-addons&section=' . esc_attr( $section->slug ) ); ?>">
<?php echo esc_html( $section->label ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<br class="clear" />
<?php if ( 'featured' === $current_section ) : ?>
<?php if ( isset( $_GET['search'] ) ) : ?>
<h1 class="search-form-title" >
<?php printf( __( 'Showing search results for: %s', 'woocommerce' ), '<strong>' . esc_html( $_GET['search'] ) . '</strong>' ); ?>
</h1>
<?php endif; ?>
<form class="search-form" method="GET">
<button type="submit">
<span class="dashicons dashicons-search"></span>
</button>
<input
type="text"
name="search"
value="<?php echo esc_attr( isset( $_GET['search'] ) ? $_GET['search'] : '' ); ?>"
placeholder="<?php _e( 'Enter a search term and press enter', 'woocommerce' ); ?>">
<input type="hidden" name="page" value="wc-addons">
<?php $page_section = ( isset( $_GET['section'] ) && '_featured' !== $_GET['section'] ) ? $_GET['section'] : '_all'; ?>
<input type="hidden" name="section" value="<?php echo esc_attr( $page_section ); ?>">
</form>
<?php if ( '_featured' === $current_section ) : ?>
<div class="addons-featured">
<?php
$featured = WC_Admin_Addons::get_featured();
?>
</div>
<?php endif; ?>
<?php if ( 'featured' !== $current_section && $addons = WC_Admin_Addons::get_section_data( $current_section ) ) : ?>
<?php if ( '_featured' !== $current_section && $addons ) : ?>
<?php if ( 'shipping_methods' === $current_section ) : ?>
<div class="addons-shipping-methods">
<?php WC_Admin_Addons::output_wcs_banner_block(); ?>
@ -67,7 +92,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<li class="product">
<a href="<?php echo esc_attr( $addon->link ); ?>">
<?php if ( ! empty( $addon->image ) ) : ?>
<img src="<?php echo esc_attr( $addon->image ); ?>"/>
<img src="<?php echo esc_url( $addon->image ); ?>"/>
<?php else : ?>
<h2><?php echo esc_html( $addon->title ); ?></h2>
<?php endif; ?>
@ -82,7 +107,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<p><?php printf( __( 'Our catalog of WooCommerce Extensions can be found on WooCommerce.com here: <a href="%s">WooCommerce Extensions Catalog</a>', 'woocommerce' ), 'https://woocommerce.com/product-category/woocommerce-extensions/' ); ?></p>
<?php endif; ?>
<?php if ( 'Storefront' !== $theme['Name'] && 'featured' !== $current_section ) : ?>
<?php if ( 'Storefront' !== $theme['Name'] && '_featured' !== $current_section ) : ?>
<div class="storefront">
<a href="<?php echo esc_url( 'https://woocommerce.com/storefront/' ); ?>" target="_blank"><img src="<?php echo WC()->plugin_url(); ?>/assets/images/storefront.png" alt="Storefront" /></a>
<h2><?php _e( 'Looking for a WooCommerce theme?', 'woocommerce' ); ?></h2>