From c66c64c384541ab40d898bb0a702cc99e1a04d81 Mon Sep 17 00:00:00 2001 From: devsabbirhossain Date: Tue, 14 Jan 2025 18:15:50 +0600 Subject: [PATCH] seperate pro features --- .gitignore | 2 +- assets/css/frontend.scss | 12 +++++++ assets/js/frontend.js | 44 +++++++++++++++++++------ bin/build.sh | 50 ++++++++++++++++++++++++++++ includes/Admin/Admin.php | 4 +-- includes/Controllers/Helpers.php | 28 ++++++++++++++++ includes/Plugin.php | 4 +++ includes/Products.php | 15 +++++---- languages/wc-variation-images.pot | 55 ++++++++++++++++++------------- package-lock.json | 4 +-- 10 files changed, 174 insertions(+), 44 deletions(-) create mode 100755 bin/build.sh diff --git a/.gitignore b/.gitignore index 41e3772..d9f6f48 100755 --- a/.gitignore +++ b/.gitignore @@ -53,5 +53,5 @@ languages/*. # Build related files /bin/strauss.phar -/bin +#/bin build diff --git a/assets/css/frontend.scss b/assets/css/frontend.scss index 35367e8..c146b34 100644 --- a/assets/css/frontend.scss +++ b/assets/css/frontend.scss @@ -242,3 +242,15 @@ .light-box-icon:hover { background-color: rgba(0, 0, 0, 0.8); } + +.admin-bar { + .fancybox-toolbar{ + margin-top: 30px; + } + .fancybox-progress { + margin-top: 31px; + } + .fancybox-infobar { + margin-top: 30px; + } +} diff --git a/assets/js/frontend.js b/assets/js/frontend.js index a808591..8f24f7b 100644 --- a/assets/js/frontend.js +++ b/assets/js/frontend.js @@ -103,32 +103,56 @@ }); function load_slider() { + var slider_settings = JSON.parse( WC_VARIATION_IMAGES.i18n.slider_data ); + var enable_slider = "no" === slider_settings.enable_slider ? false : { delay: slider_settings.slider_delay, disableOnInteraction: false } + var navigation = "no" === slider_settings.hide_navigation ? false : { + nextEl: ".swiper-button-next", + prevEl: ".swiper-button-prev", + } var swiper = new Swiper(".mySwiper", { - loop: true, - spaceBetween: 10, - slidesPerView: 4, + loop: slider_settings.loop ? slider_settings.loop : false, + spaceBetween: slider_settings.items_space ? slider_settings.items_space : 4, + slidesPerView: slider_settings.items_per_page ? slider_settings.items_per_page : 4, freeMode: true, watchSlidesProgress: true, }); var swiper2 = new Swiper(".mySwiper2", { - loop: true, - spaceBetween: 10, - navigation: { - nextEl: ".swiper-button-next", - prevEl: ".swiper-button-prev", + loop: slider_settings.loop ? slider_settings.loop : false, + navigation: navigation, + autoplay: enable_slider, + effect: 'fade', + fadeEffect: { + crossFade: true }, thumbs: { swiper: swiper, }, }); + if( "no" === slider_settings.hide_navigation ) { + $(".swiper-button-next").hide(); + $(".swiper-button-prev").hide(); + } + + var lightbox_data = JSON.parse( WC_VARIATION_IMAGES.i18n.lightbox_data ); $("[data-fancybox='gallery']").fancybox({ loop: true, protect: true, buttons: [ - 'fullScreen', - 'close' + "zoom", + lightbox_data.slideShow, + lightbox_data.fullScreen, + lightbox_data.share, + "close" ], + zoom: { + enabled: true, + duration: 300 + }, + thumbs: { + autoStart: true, + axis: "x", + }, }); } diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..e5c2899 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,50 @@ +#!/bin/sh +SLUG=$(node -p "require('./package.json').name") +VERSION=$(node -p "require('./package.json').version") +WORKING_DIR=$(pwd) +ZIP_DIR=/tmp/${SLUG} + +# If slug is not set, exit +if [ -z "$SLUG" ]; then + echo "Slug not set. Exiting." + exit 1 +fi +echo "➤ Preparing zip for $VERSION of $SLUG..." + +echo "➤ Building plugin..." +composer install +composer update --no-dev +npm install && npm run build +echo "✓ Plugin built!" + +# if directory already exists, delete it +if [ -d "$ZIP_DIR" ]; then + rm -rf $ZIP_DIR +fi + +echo "➤ Creating ZIP directory..." +mkdir -p "$ZIP_DIR" +echo "✓ ZIP directory created!" + +echo "➤ Copying files..." +# If .distignore file exists, use it to exclude files from the SVN repo, otherwise use the default. +if [[ -r "$WORKING_DIR/.distignore" ]]; then + echo "ℹ︎ Using .distignore" + rsync -rc --exclude-from="$WORKING_DIR/.distignore" "$WORKING_DIR/" "$ZIP_DIR/" --delete --delete-excluded + echo "✓ Files copied!" +fi + +# Remove empty directories from trunk +find "$ZIP_DIR/" -type d -empty -delete + +ZIP_NAME="$SLUG-v$VERSION.zip" +echo "➤ Creating ZIP file..." +# cd to the one level above the ZIP directory and zip it up +cd "$ZIP_DIR/.." || exit 1 +zip -q -r "$ZIP_NAME" "${SLUG}/" +mv "$ZIP_NAME" "$WORKING_DIR/" +echo "✓ ZIP file created!" + +echo "➤ Cleaning up..." +rm -rf "$ZIP_DIR" +echo "✓ Done!" diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index c624c96..75c5939 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -108,8 +108,8 @@ public function admin_template_js() { public function admin_menu() { add_submenu_page( 'woocommerce', - __( 'Variation Image', 'wc-variation-images' ), - __( 'Variation Image', 'wc-variation-images' ), + __( 'Variation Images', 'wc-variation-images' ), + __( 'Variation Images', 'wc-variation-images' ), 'manage_options', 'wc-variation-images', array( Settings::class, 'output' ) diff --git a/includes/Controllers/Helpers.php b/includes/Controllers/Helpers.php index dcc1b3f..fd03d2a 100644 --- a/includes/Controllers/Helpers.php +++ b/includes/Controllers/Helpers.php @@ -25,4 +25,32 @@ public static function gallery_position_list() { return apply_filters( 'wc_variation_images_gallery_positions', $positions ); } + + /** + * Lightbox Settings. + * + * @since 1.0.0 + * @return string + */ + public static function get_lightbox_data() { + $lightbox_config = array(); + + $lightbox_config = apply_filters( 'wc_variation_images_lightbox_config', $lightbox_config ); + $lightbox_config = wp_json_encode( $lightbox_config ); + return $lightbox_config; + } + + /** + * Slider Settings. + * + * @since 1.0.0 + * @return string + */ + public static function get_slider_data() { + $slider_config = array(); + + $slider_config = apply_filters( 'wc_variation_images_slider_config', $slider_config ); + $slider_config = wp_json_encode( $slider_config ); + return $slider_config; + } } diff --git a/includes/Plugin.php b/includes/Plugin.php index 7bbe8ca..4ad4d92 100644 --- a/includes/Plugin.php +++ b/includes/Plugin.php @@ -2,6 +2,8 @@ namespace WooCommerceVariationImages; +use WooCommerceVariationImages\Controllers\Helpers; + defined( 'ABSPATH' ) || exit; /** @@ -155,6 +157,8 @@ public function frontend_scripts_handler() { 'nonce' => wp_create_nonce( 'wc_variation_images_ajax' ), 'i18n' => array( 'hide_image_zoom' => get_option( 'wc_variation_images_hide_image_zoom', 'no' ), + 'lightbox_data' => Helpers::get_lightbox_data(), + 'slider_data' => Helpers::get_slider_data(), ), ) ); diff --git a/includes/Products.php b/includes/Products.php index 1ee75d5..cc0815e 100644 --- a/includes/Products.php +++ b/includes/Products.php @@ -24,7 +24,7 @@ public function __construct() { add_filter( 'wc_get_template', array( $this, 'gallery_template_override' ), 60, 2 ); add_action( 'wp', array( $this, 'wc_variation_images_gallery_control' ), 100 ); add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'wc_variation_images_upload_images' ), 10, 3 ); - add_action( 'woocommerce_product_thumbnails', array( $this, 'replace_variable_product_image' ) ); + /** add_action( 'woocommerce_product_thumbnails', array( $this, 'replace_variable_product_image' ) ); */ } /** @@ -44,11 +44,14 @@ public function gallery_template_override( $template, $template_name ) { return $old_template; } - if ( 'single-product/product-image.php' === $template_name ) { - if ( 'no' === get_option( 'wc_variation_images_hide_image_slider', 'no' ) ) { - $template = WC_VARIATION_IMAGES_TEMPLATES_DIR . '/product-image-slider.php'; - } else { - $template = WC_VARIATION_IMAGES_TEMPLATES_DIR . '/product-image.php'; + $product = wc_get_product(); + if ( 'variable' === $product->get_type() ) { + if ( 'single-product/product-image.php' === $template_name ) { + if ( 'no' === get_option( 'wc_variation_images_hide_image_slider', 'no' ) ) { + $template = WC_VARIATION_IMAGES_TEMPLATES_DIR . '/product-image-slider.php'; + } else { + $template = WC_VARIATION_IMAGES_TEMPLATES_DIR . '/product-image.php'; + } } } diff --git a/languages/wc-variation-images.pot b/languages/wc-variation-images.pot index 79dade5..95fb0d9 100644 --- a/languages/wc-variation-images.pot +++ b/languages/wc-variation-images.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: WC Variation Images 1.2.0\n" "Report-Msgid-Bugs-To: https://pluginever.com/support/\n" -"POT-Creation-Date: 2025-01-07 08:50:36+00:00\n" +"POT-Creation-Date: 2025-01-12 04:34:21+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -25,7 +25,8 @@ msgstr "" "X-Generator: grunt-wp-i18n 1.0.3\n" #: includes/Admin/Admin.php:78 includes/Admin/Admin.php:80 -#: includes/Products.php:81 +#: includes/Admin/Admin.php:111 includes/Admin/Admin.php:112 +#: includes/Products.php:147 msgid "Variation Images" msgstr "" @@ -43,10 +44,6 @@ msgid "" "remove the image. Click and drag image to re-order the image position." msgstr "" -#: includes/Admin/Admin.php:111 includes/Admin/Admin.php:112 -msgid "Variation Image" -msgstr "" - #: includes/Admin/Admin.php:131 #. translators: 1: Plugin name 2: WordPress msgid "" @@ -63,53 +60,61 @@ msgstr "" msgid "Version %s" msgstr "" -#: includes/Admin/Settings.php:23 +#: includes/Admin/Settings.php:25 msgid "General" msgstr "" -#: includes/Admin/Settings.php:42 -msgid "General settings" +#: includes/Admin/Settings.php:44 +msgid "Gallery settings" msgstr "" -#: includes/Admin/Settings.php:44 +#: includes/Admin/Settings.php:46 msgid "The following options affect how the plugin will work." msgstr "" -#: includes/Admin/Settings.php:49 +#: includes/Admin/Settings.php:51 msgid "Hide Image Zoom" msgstr "" -#: includes/Admin/Settings.php:50 +#: includes/Admin/Settings.php:52 msgid "Hide image zoom for variable product" msgstr "" -#: includes/Admin/Settings.php:54 includes/Admin/Settings.php:65 -#: includes/Admin/Settings.php:76 +#: includes/Admin/Settings.php:56 includes/Admin/Settings.php:68 +#: includes/Admin/Settings.php:80 msgid "No" msgstr "" -#: includes/Admin/Settings.php:55 includes/Admin/Settings.php:66 -#: includes/Admin/Settings.php:77 +#: includes/Admin/Settings.php:57 includes/Admin/Settings.php:69 +#: includes/Admin/Settings.php:81 msgid "Yes" msgstr "" -#: includes/Admin/Settings.php:60 +#: includes/Admin/Settings.php:63 msgid "Hide Lightbox" msgstr "" -#: includes/Admin/Settings.php:61 +#: includes/Admin/Settings.php:64 msgid "Hide image lightbox for variable product" msgstr "" -#: includes/Admin/Settings.php:71 +#: includes/Admin/Settings.php:75 msgid "Hide Image Slider" msgstr "" -#: includes/Admin/Settings.php:72 +#: includes/Admin/Settings.php:76 msgid "Hide image slider for variable product" msgstr "" -#: includes/Admin/Settings.php:120 +#: includes/Admin/Settings.php:87 +msgid "Gallery Position" +msgstr "" + +#: includes/Admin/Settings.php:88 includes/Admin/Settings.php:89 +msgid "Set Gallery image position" +msgstr "" + +#: includes/Admin/Settings.php:134 #: vendor-prefixed/byteever/bytekit-plugin/src/Traits/HasPlugin.php:216 msgid "Documentation" msgstr "" @@ -186,6 +191,10 @@ msgstr "" msgid "Upgrade now" msgstr "" +#: includes/Controllers/Helpers.php:23 +msgid "Bottom" +msgstr "" + #: includes/Plugin.php:106 #. translators: 1: plugin name 2: WooCommerce msgid "%1$s requires %2$s to be installed and active." @@ -195,11 +204,11 @@ msgstr "" msgid "WooCommerce" msgstr "" -#: includes/Products.php:105 +#: includes/Products.php:171 msgid "Add Variation Images" msgstr "" -#: includes/functions.php:98 +#: includes/functions.php:102 templates/product-image.php:75 msgid "Awaiting product image" msgstr "" diff --git a/package-lock.json b/package-lock.json index 27c07f4..30980f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wc-variation-images", - "version": "1.1.1", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "wc-variation-images", - "version": "1.1.1", + "version": "1.2.0", "devDependencies": { "@lodder/time-grunt": "^4.0.0", "@wordpress/scripts": "^27.9.0",