Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Söderlund committed Mar 29, 2016
2 parents 1150a0c + 379bcda commit 59650ea
Show file tree
Hide file tree
Showing 11 changed files with 2,022 additions and 1 deletion.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion README.md

This file was deleted.

250 changes: 250 additions & 0 deletions classes/class-wc-settings-sizeme-measurements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php
/**
* SizeMe Measurements settings.
*
* Adds a SizeMe measurements tab in the WooCommerce settings page.
*
* @package SizeMe Measurements
* @since 1.0.0
*/

/**
* SizeMe Measurements is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* SizeMe Measurements is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SizeMe Measurements. If not, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Class WC_Settings_SizeMe_Measurements.
*
* Adds a SizeMe Measurements tab in the WooCommerce settings page.
*
* @since 1.0.0
*/
class WC_Settings_SizeMe_Measurements extends WC_Settings_Page {

/**
* Service is on.
*
* @since 1.0.0
*
* @var string SERVICE_STATUS_ON
*/
const SERVICE_STATUS_ON = 'on';

/**
* Service is off.
*
* @since 1.0.0
*
* @var string SERVICE_STATUS_OFF
*/
const SERVICE_STATUS_OFF = 'off';

/**
* Service is in test mode.
*
* @since 1.0.0
*
* @var string SERVICE_STATUS_TEST
*/
const SERVICE_STATUS_TEST = 'test';

/**
* Class constructor.
*
* Initializes the settings.
*
* @since 1.0.0
*
* @return WC_Settings_SizeMe_Measurements
*/
public function __construct() {
$this->id = 'sizeme_measurements';
$this->label = __( 'SizeMe Measurements', 'sizeme' );

parent::__construct();
}

/**
* Get sections.
*
* Returns the sections for the settings page.
*
* @since 1.0.0
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Settings', 'sizeme' ),
);

return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}

/**
* Get settings array.
*
* Returns the settings form.
*
* @since 1.0.0
*
* @return array
*/
public function get_settings() {

$settings = array(
array(
'title' => __( 'General settings', 'sizeme' ),
'type' => 'title',
'id' => 'general_settings',
),
array(
'title' => __( 'Custom size selection', 'sizeme' ),
'desc' => __( 'Use custom size selection ', 'sizeme' ),
'type' => 'checkbox',
'default' => 'no',
'id' => WC_SizeMe_Measurements::CUSTOM_SIZE_SELECTION_ID,
),
array(
'title' => __( 'Service status', 'sizeme' ),
'type' => 'select',
'options' => array(
'' => __( 'Select service status', 'sizeme' ),
self::SERVICE_STATUS_TEST => 'Test',
self::SERVICE_STATUS_ON => 'On',
self::SERVICE_STATUS_OFF => 'Off',
),
'id' => WC_SizeMe_Measurements::SERVICE_STATUS_ID,
),
array(
'type' => 'sectionend',
'id' => 'general_settings',
),
array(
'title' => __( 'Attribute settings', 'sizeme' ),
'type' => 'title',
'id' => 'attribute_settings',
),
array(
'title' => __( 'Product Size Attributes', 'sizeme' ),
'desc' => __( 'Select the attributes for sizes', 'sizeme' ),
'type' => 'multiselect',
'options' => self::load_size_attribute_options(),
'css' => 'width: 150px; height: 150px;',
'id' => 'size_attributes',
),
array(
'type' => 'sectionend',
'id' => 'attribute_settings',
),
array(
'title' => __( 'UI options', 'sizeme' ),
'type' => 'title',
'id' => 'ui_options',
),
array(
'title' => __( 'Append content to element', 'sizeme' ),
'type' => 'text',
'default' => get_option( WC_SizeMe_Measurements::APPEND_CONTENT_TO, '' ),
'id' => WC_SizeMe_Measurements::APPEND_CONTENT_TO,
),
array(
'title' => __( 'Append splash to element', 'sizeme' ),
'type' => 'text',
'default' => get_option( WC_SizeMe_Measurements::APPEND_SPLASH_TO, '' ),
'id' => WC_SizeMe_Measurements::APPEND_SPLASH_TO,
),
array(
'title' => __( 'Add to cart element', 'sizeme' ),
'type' => 'text',
'default' => get_option( WC_SizeMe_Measurements::ADD_TO_CART_ELEMENT, '' ),
'id' => WC_SizeMe_Measurements::ADD_TO_CART_ELEMENT,
),
array(
'title' => __( 'Add to cart event', 'sizeme' ),
'type' => 'text',
'default' => get_option( WC_SizeMe_Measurements::ADD_TO_CART_EVENT, '' ),
'id' => WC_SizeMe_Measurements::ADD_TO_CART_EVENT,
),
array(
'title' => __( 'Size selection container element', 'sizeme' ),
'type' => 'text',
'default' => get_option( WC_SizeMe_Measurements::SIZE_SELECTION_CONTAINER_ELEMENT, '' ),
'id' => WC_SizeMe_Measurements::SIZE_SELECTION_CONTAINER_ELEMENT,
),
array(
'type' => 'sectionend',
'id' => 'ui_options',
),

);

return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}

/**
* Output the settings.
*
* Outputs the settings form.
*
* @since 1.0.0
*/
public function output() {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
}

/**
* Save settings.
*
* Saves the settings form in the wp_options table.
*
* @since 1.0.0
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}

/**
* Load the size attribute options.
*
* Return a list of attribute_name => attribute_label.
*
* @since 1.0.0
*
* @return array
*/
public function load_size_attribute_options() {
$taxonomies = wc_get_attribute_taxonomies();
$result = array();
foreach ( $taxonomies as $taxonomy ) {
// Skip the SizeMe attributes in the list.
if ( strpos( $taxonomy->attribute_name, 'sm_' ) === 0
|| strpos( $taxonomy->attribute_name, 'smi_' ) === 0
) {
continue;
}
$result[ $taxonomy->attribute_name ] = $taxonomy->attribute_label;
}

return $result;
}
}

return new WC_Settings_SizeMe_Measurements();
121 changes: 121 additions & 0 deletions classes/class-wc-sizeme-measurements-attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* SizeMe Measurements attributes.
*
* Handles SizeMe measurements attributes.
*
* @package SizeMe Measurements
* @since 1.0.0
*/

/**
* SizeMe Measurements is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* SizeMe Measurements is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SizeMe Measurements. If not, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Class WC_SizeMe_Measurements_Attributes.
*
* Adds functionality to add and get SizeMe Measurements attributes.
*
* @package SizeMe Measurements
* @since 1.0.0
*/
class WC_SizeMe_Measurements_Attributes {

/**
* The item type attribute name.
*
* @since 1.0.0
*
* @var string ITEM_TYPE
*/
const ITEM_TYPE = 'smi_item_type';

/**
* The item layer attribute name.
*
* @since 1.0.0
*
* @var string ITEM_LAYER
*/
const ITEM_LAYER = 'smi_item_layer';

/**
* The item thickness attribute name.
*
* @since 1.0.0
*
* @var string ITEM_THICKNESS
*/
const ITEM_THICKNESS = 'smi_item_thickness';

/**
* The item stretch attribute name.
*
* @var string ITEM_STRETCH
*/
const ITEM_STRETCH = 'smi_item_stretch';

/**
* Attributes used for SizeMe Measurements.
*
* @since 1.0.0
*
* @var array List of attributes.
*/
protected static $attributes = array(
'smi_item_type',
'smi_item_layer',
'smi_item_thickness',
'smi_item_stretch',
'sm_chest',
'sm_waist',
'sm_sleeve',
'sm_sleeve_top_width',
'sm_wrist_width',
'sm_underbust',
'sm_neck_opening_width',
'sm_shoulder_width',
'sm_front_height',
'sm_pant_waist',
'sm_hips',
'sm_inseam',
'sm_outseam',
'sm_thigh_width',
'sm_knee_width',
'sm_calf_width',
'sm_pant_sleeve_width',
'sm_shoe_inside_length',
'sm_shoe_inside_width',
'sm_hat_width',
'sm_hood_height',
);

/**
* Get attribute names.
*
* Returns the SizeMe Measurement attribute names.
*
* @since 1.0.0
*
* @return array The attribute names, e.g. sm_chest, sm_waist.
*/
public static function get_attribute_names() {
return self::$attributes;
}
}
Loading

0 comments on commit 59650ea

Please sign in to comment.