Changeset 3667117
- Timestamp:
- 08/26/2026 01:32:05 PM (2 months ago)
- Location:
- darven-multiplos-precos-informativos/tags/4.0.0
- Files:
-
- 19 added
- 5 deleted
- 21 edited
- 1 copied
-
. (copied) (copied from darven-multiplos-precos-informativos/trunk )
-
admin/js (deleted)
-
build (added)
-
build/product-options (added)
-
build/product-options/index.asset.php (added)
-
build/product-options/index.js (added)
-
build/product-options/style-index-rtl.css (added)
-
build/product-options/style-index.css (added)
-
build/settings (added)
-
build/settings/index.asset.php (added)
-
build/settings/index.js (added)
-
build/settings/style-index-rtl.css (added)
-
build/settings/style-index.css (added)
-
darven-extra-price-info.php (modified) (3 diffs)
-
i18n (deleted)
-
languages/darven-multiplos-precos-informativos-pt_BR-darven-precos-parcelados-product-options.json (added)
-
languages/darven-multiplos-precos-informativos-pt_BR-darven-precos-parcelados-settings.json (added)
-
languages/darven-multiplos-precos-informativos-pt_BR.mo (added)
-
languages/darven-multiplos-precos-informativos-pt_BR.po (added)
-
languages/darven-multiplos-precos-informativos.pot (added)
-
public/css/styles.css (modified) (1 diff)
-
public/js/frontend.js (modified) (1 diff)
-
readme.txt (modified) (4 diffs)
-
src/Admin/Assets.php (modified) (1 diff)
-
src/Admin/LegacySettingsSync.php (deleted)
-
src/Admin/ProductOptionsController.php (modified) (3 diffs)
-
src/Admin/ReactPage.php (added)
-
src/Admin/SettingsFields (deleted)
-
src/Admin/SettingsPage.php (modified) (1 diff)
-
src/Admin/SettingsRestController.php (added)
-
src/Compatibility/LegacyProductSettingsAdapter.php (modified) (1 diff)
-
src/Compatibility/LegacySettingsAdapter.php (modified) (1 diff)
-
src/Frontend/Assets.php (modified) (2 diffs)
-
src/Frontend/InlineStyles.php (modified) (2 diffs)
-
src/Repositories/ProductSettingsRepository.php (modified) (3 diffs)
-
src/Repositories/SettingsRepository.php (modified) (9 diffs)
-
src/Repositories/SettingsSanitizer.php (added)
-
src/Services/InstallmentPriceFormatter.php (modified) (8 diffs)
-
src/Setup/Plugin.php (modified) (3 diffs)
-
src/Setup/TextDomainLoader.php (modified) (1 diff)
-
templates (deleted)
-
vendor/autoload.php (modified) (1 diff)
-
vendor/composer/autoload_classmap.php (modified) (2 diffs)
-
vendor/composer/autoload_real.php (modified) (2 diffs)
-
vendor/composer/autoload_static.php (modified) (4 diffs)
-
vendor/composer/platform_check.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
darven-multiplos-precos-informativos/tags/4.0.0/darven-extra-price-info.php
r3627241 r3667117 1 1 <?php 2 2 /* 3 * Plugin Name: Darven Múltiplos Preços Informativos3 * Plugin Name: Darven Preços Parcelados 4 4 * @package darven-extra-price-info 5 5 * Plugin URI: wordpress.org/plugins/darven-multiplos-precos-informativos/ 6 * Description: This plugin is used to show multiple prices for a product. Incash and installments price.7 * Version: 3.3.16 * Description: Displays cash and installment prices in WooCommerce. Previously: Darven Múltiplos Preços Informativos. 7 * Version: 4.0.0 8 8 * Author: Leticia Moreira 9 9 * Author URI: https://darven.wtf 10 * Text Domain: darven-epi 11 * Domain Path: /i18n/languages/ 12 * Requires PHP: 7.4 10 * Text Domain: darven-multiplos-precos-informativos 11 * Domain Path: /languages/ 12 * Requires at least: 5.0 13 * Requires PHP: 8.0 13 14 * Requires Plugins: woocommerce 14 15 */ … … 20 21 define( 'DARVEN_EPI_STYLES_PATH', '/' . str_replace( site_url() . '/', '', plugin_dir_url( __FILE__ ) ) ); 21 22 const DARVEN_EPI_ADMIN_PAGE = 'darven-epi-admin'; 22 const DARVEN_EPI_LANGUAGE_DOMAIN = 'darven- epi';23 const DARVEN_EPI_LANGUAGE_DOMAIN = 'darven-multiplos-precos-informativos'; 23 24 if ( ! defined( 'WPINC' ) ) { 24 25 die; 25 26 } 26 27 27 const DARVEN_EPI_VERSION = ' 3.3.1';28 const DARVEN_EPI_VERSION = '4.0.0'; 28 29 29 30 $darven_epi_autoload_file = DARVEN_EPI_DIR_PATH . 'vendor/autoload.php'; … … 34 35 static function (): void { 35 36 echo '<div class="notice notice-error"><p>' 36 . esc_html__( 'Darven Extra Price Info is missing its runtime dependencies.', 'darven-epi')37 . esc_html__( 'Darven Extra Price Info is missing its runtime dependencies.', DARVEN_EPI_LANGUAGE_DOMAIN ) 37 38 . '</p></div>'; 38 39 } -
darven-multiplos-precos-informativos/tags/4.0.0/public/css/styles.css
r3627068 r3667117 87 87 } 88 88 89 .darven-epi-installments-toggle:focus-visible { 90 outline: 3px solid #1f75cc; 91 outline-offset: 3px; 92 } 93 89 94 .darven-epi-installments-popup { 90 background-color:#FFFFFF; 91 border: dotted 1px black; 92 93 cursor:default; 94 display:none; 95 margin-top: 15px; 96 position:absolute; 97 text-align:left; 98 z-index:50; 99 padding: 25px 25px 20px; 100 } 101 102 label { 103 display: block; 104 margin-bottom: 3px; 105 padding-left: 15px; 106 text-indent: -15px; 107 } 108 109 .darven-epi-installments-popup p, 110 .darven-epi-installments-popup.div { 95 align-items: center; 96 cursor: default; 97 display: grid; 98 inset: 0; 99 justify-items: center; 100 padding: 20px; 101 position: fixed; 102 text-align: left; 103 z-index: 99999999; 104 } 105 106 .darven-epi-installments-popup[hidden] { 107 display: none; 108 } 109 110 .darven-epi-installments-backdrop { 111 background: rgba(0, 0, 0, 0.58); 112 cursor: pointer; 113 inset: 0; 114 position: absolute; 115 } 116 117 .darven-epi-installments-dialog { 118 animation: darven-epi-popup-in 160ms ease-out; 119 background-color: #fff; 120 border: 1px solid #d7d7d7; 121 border-radius: 8px; 122 box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3); 123 box-sizing: border-box; 124 max-height: calc(100vh - 40px); 125 max-width: 520px; 126 overflow: hidden; 127 padding: 48px 24px 24px; 128 position: relative; 129 width: 100%; 130 z-index: 1; 131 } 132 133 .darven-epi-installments-close { 134 align-items: center; 135 background: transparent; 136 border: 0; 137 border-radius: 4px; 138 color: inherit; 139 cursor: pointer; 140 display: flex; 141 font: inherit; 142 font-size: 28px; 143 height: 40px; 144 justify-content: center; 145 padding: 0; 146 position: absolute; 147 right: 8px; 148 top: 8px; 149 width: 40px; 150 } 151 152 .darven-epi-installments-close:focus-visible { 153 outline: 3px solid #1f75cc; 154 outline-offset: 3px; 155 } 156 157 .darven-epi-installments-table-wrap { 158 max-height: calc(100vh - 136px); 159 overflow: auto; 160 overscroll-behavior: contain; 161 } 162 163 .darven-epi-installments-title { 164 border: 0; 165 clip: rect(1px, 1px, 1px, 1px); 166 clip-path: inset(50%); 167 height: 1px; 168 margin: -1px; 169 overflow: hidden; 170 padding: 0; 171 position: absolute; 172 width: 1px; 173 word-wrap: normal; 174 } 175 176 .darven-epi-installments-popup p { 111 177 border-bottom: 1px solid #EFEFEF; 112 178 margin: 8px 0; 113 179 padding-bottom: 8px; 114 180 } 181 182 @keyframes darven-epi-popup-in { 183 184 from { 185 opacity: 0; 186 transform: translateY(8px); 187 } 188 189 to { 190 opacity: 1; 191 transform: translateY(0); 192 } 193 } 194 195 @media (max-width: 480px) { 196 197 .darven-epi-installments-popup { 198 padding: 12px; 199 } 200 201 .darven-epi-installments-dialog { 202 max-height: calc(100vh - 24px); 203 padding: 48px 16px 16px; 204 } 205 206 .darven-epi-installments-table-wrap { 207 max-height: calc(100vh - 112px); 208 } 209 } 210 211 @media (prefers-reduced-motion: reduce) { 212 213 .darven-epi-installments-dialog { 214 animation: none; 215 scroll-behavior: auto; 216 } 217 } -
darven-multiplos-precos-informativos/tags/4.0.0/public/js/frontend.js
r3627068 r3667117 1 ( function ( $) {1 ( function () { 2 2 'use strict'; 3 3 4 var toggleSelector = '.darven-epi-installments-toggle'; 4 const toggleSelector = '.darven-epi-installments-toggle'; 5 const popupSelector = '.darven-epi-installments-popup'; 6 const closeSelector = '.darven-epi-installments-close'; 7 const backdropSelector = '.darven-epi-installments-backdrop'; 8 let activeModal = null; 9 let activeTrigger = null; 5 10 6 function setExpanded( $toggle, expanded ) { 7 var $statement = $toggle.closest( '.darven-epi-installments-price-statement' ); 8 var $popup = $statement.find( '.darven-epi-installments-popup' ).first(); 9 10 $toggle 11 .toggleClass( 'selected', expanded ) 12 .attr( 'aria-expanded', expanded ? 'true' : 'false' ); 13 14 $popup 15 .attr( 'aria-hidden', expanded ? 'false' : 'true' ) 16 .stop( true, true )[ expanded ? 'slideDown' : 'slideUp' ]( 'fast' ); 11 if ( document.__darvenEpiInstallmentsModalBound ) { 12 return; 17 13 } 18 14 19 $( document ).on( 'click', toggleSelector, function() { 20 var $toggle = $( this ); 21 var expanded = 'true' === $toggle.attr( 'aria-expanded' ); 15 document.__darvenEpiInstallmentsModalBound = true; 22 16 23 setExpanded( $toggle, ! expanded ); 17 function closest( element, selector ) { 18 let current = element; 19 20 while ( current && current.nodeType === 1 ) { 21 if ( current.matches( selector ) ) { 22 return current; 23 } 24 25 current = current.parentElement; 26 } 27 28 return null; 29 } 30 31 function getModal( trigger ) { 32 const modalId = trigger.getAttribute( 'aria-controls' ); 33 const statement = closest( 34 trigger, 35 '.darven-epi-installments-price-statement' 36 ); 37 38 return Array.prototype.find.call( 39 statement ? statement.querySelectorAll( popupSelector ) : [], 40 ( candidate ) => candidate.id === modalId 41 ); 42 } 43 44 function getFocusableElements( modal ) { 45 const selector = [ 46 'a[href]', 47 'button:not([disabled])', 48 'input:not([disabled])', 49 'select:not([disabled])', 50 'textarea:not([disabled])', 51 '[tabindex]:not([tabindex="-1"])', 52 ].join( ',' ); 53 54 return Array.prototype.filter.call( 55 modal.querySelectorAll( selector ), 56 function ( element ) { 57 return ( 58 ! element.hidden && 59 'true' !== element.getAttribute( 'aria-hidden' ) 60 ); 61 } 62 ); 63 } 64 65 function closeActiveModal( returnFocus ) { 66 const trigger = activeTrigger; 67 68 if ( ! activeModal || ! trigger ) { 69 return; 70 } 71 72 activeModal.hidden = true; 73 activeModal.setAttribute( 'aria-hidden', 'true' ); 74 trigger.setAttribute( 'aria-expanded', 'false' ); 75 trigger.classList.remove( 'selected' ); 76 activeModal = null; 77 activeTrigger = null; 78 79 if ( returnFocus && document.contains( trigger ) ) { 80 trigger.focus(); 81 } 82 } 83 84 function openModal( trigger ) { 85 const modal = getModal( trigger ); 86 87 if ( ! modal ) { 88 return; 89 } 90 91 const closeButton = modal.querySelector( closeSelector ); 92 93 if ( activeModal && activeModal !== modal ) { 94 closeActiveModal( false ); 95 } 96 97 activeModal = modal; 98 activeTrigger = trigger; 99 modal.hidden = false; 100 modal.setAttribute( 'aria-hidden', 'false' ); 101 trigger.setAttribute( 'aria-expanded', 'true' ); 102 trigger.classList.add( 'selected' ); 103 104 if ( closeButton ) { 105 closeButton.focus(); 106 } 107 } 108 109 function toggleModal( trigger ) { 110 if ( 'true' === trigger.getAttribute( 'aria-expanded' ) ) { 111 closeActiveModal( true ); 112 return; 113 } 114 115 openModal( trigger ); 116 } 117 118 function trapFocus( event ) { 119 const focusable = getFocusableElements( activeModal ); 120 121 if ( 0 === focusable.length ) { 122 event.preventDefault(); 123 return; 124 } 125 126 const first = focusable[ 0 ]; 127 const last = focusable[ focusable.length - 1 ]; 128 const activeElement = activeModal.ownerDocument.activeElement; 129 130 if ( 131 event.shiftKey && 132 ( activeElement === first || 133 ! activeModal.contains( activeElement ) ) 134 ) { 135 event.preventDefault(); 136 last.focus(); 137 } else if ( 138 ! event.shiftKey && 139 ( activeElement === last || 140 ! activeModal.contains( activeElement ) ) 141 ) { 142 event.preventDefault(); 143 first.focus(); 144 } 145 } 146 147 document.addEventListener( 'click', function ( event ) { 148 const target = event.target; 149 150 if ( ! target || ! target.matches ) { 151 return; 152 } 153 154 const toggle = closest( target, toggleSelector ); 155 if ( toggle ) { 156 toggleModal( toggle ); 157 return; 158 } 159 160 if ( activeModal && closest( target, closeSelector ) ) { 161 closeActiveModal( true ); 162 return; 163 } 164 165 if ( activeModal && target.matches( backdropSelector ) ) { 166 closeActiveModal( true ); 167 } 24 168 } ); 25 169 26 $( document ).on( 'blur', toggleSelector, function() { 27 setExpanded( $( this ), false ); 28 } ); 170 document.addEventListener( 'keydown', function ( event ) { 171 const target = event.target; 172 const toggle = 173 target && target.matches 174 ? closest( target, toggleSelector ) 175 : null; 29 176 30 $( document ).on( 'keydown', toggleSelector, function( event ) { 177 if ( 178 toggle && 179 ( 'Enter' === event.key || 180 ' ' === event.key || 181 'Spacebar' === event.key ) 182 ) { 183 event.preventDefault(); 184 toggleModal( toggle ); 185 return; 186 } 187 188 if ( ! activeModal ) { 189 return; 190 } 191 31 192 if ( 'Escape' === event.key ) { 32 setExpanded( $( this ), false ); 193 event.preventDefault(); 194 closeActiveModal( true ); 195 } else if ( 'Tab' === event.key ) { 196 trapFocus( event ); 33 197 } 34 198 } ); 35 } ( jQuery ));199 } )(); -
darven-multiplos-precos-informativos/tags/4.0.0/readme.txt
r3627241 r3667117 1 === Plugin Name===1 === Darven Preços Parcelados === 2 2 Contributors: fkdarven 3 Tags: parcelas, parcelamento, preços, installments, price, woocommerce4 Requires at least: 4.75 Tested up to: 7. 06 Stable tag: 3.3.17 Requires PHP: 7.43 Tags: parcelas, parcelamento, preços, preço à vista, preço parcelado 4 Requires at least: 5.0 5 Tested up to: 7.1 6 Stable tag: 4.0.0 7 Requires PHP: 8.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 12 12 13 13 Mostra múltiplos preços em um produto. Preço á vista e com parcelamento (preço parcelado). 14 15 Anteriormente: Darven Múltiplos Preços Informativos. 14 16 15 17 == Description == … … 68 70 == Screenshots == 69 71 70 1. Catálogo de produtos com o preço á vista e com parcelamento ativados 71 2. Configurações do preço com parcelamento 72 3. Configurações do preço á vista 73 4. Produto individual com o preço á vista e com parcelamento ativados 72 1. Configurações do Darven Preços Parcelados no menu do WooCommerce. 73 2. Opções do Darven no editor de produto do WooCommerce. 74 3. Lista acessível de parcelas aberta na página do produto. 74 75 75 76 == Changelog == 77 = 4.0.0 = 78 • Nova identidade pública: Darven Preços Parcelados. Anteriormente: Darven Múltiplos Preços Informativos. 79 • Preparada a infraestrutura de ativos administrativos separados para configurações e opções de produto. 80 76 81 = 3.3.1 = 77 82 • Validado com WordPress 7.0.2 e WooCommerce 10.9.4. … … 137 142 Ajustes para melhorar a compatibilidade com versões anteriores do PHP. 138 143 139 140 -
darven-multiplos-precos-informativos/tags/4.0.0/src/Admin/Assets.php
r3627068 r3667117 7 7 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : null; 8 8 9 if ( 'darven-epi-admin' !== $page ) { 10 return; 11 } 12 13 $plugin_url = plugin_dir_url( DARVEN_EPI_DIR_PATH . 'darven-extra-price-info.php' ); 14 $version = defined( 'DARVEN_EPI_VERSION' ) ? DARVEN_EPI_VERSION : '1.0.0'; 15 16 wp_enqueue_style( 'darven-epi', $plugin_url . 'admin/css/admin_styles.css', array(), $version, 'all' ); 17 18 $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : null; 19 if ( 'colorsandstyles' === $tab ) { 20 wp_enqueue_script( 21 'darven-epi', 22 $plugin_url . 'admin/js/colorsandstyles.js', 23 array( 'jquery', 'wp-color-picker' ), 24 $version, 25 false 26 ); 9 if ( 'darven-epi-admin' === $page ) { 10 $this->enqueueSettingsAssets(); 27 11 28 12 return; 29 13 } 30 14 31 if ( 'positions' !== $tab) {32 wp_enqueue_script( 'darven-epi', $plugin_url . 'admin/js/general.js', array( 'jquery' ), $version, false);15 if ( $this->isProductEditor() ) { 16 $this->enqueueProductOptionsAssets(); 33 17 } 34 18 } 19 20 private function enqueueSettingsAssets(): void { 21 $this->enqueueBundle( 22 'settings', 'darven-precos-parcelados-settings', 'DarvenPrecosParceladosSettings', array( 23 'restUrl' => rest_url( 'darven-precos-parcelados/v1/' ), 24 'nonce' => wp_create_nonce( 'wp_rest' ), 25 'screen' => 'settings', 26 'productId' => 0, 27 ) 28 ); 29 } 30 31 private function enqueueProductOptionsAssets(): void { 32 $this->enqueueBundle( 33 'product-options', 'darven-precos-parcelados-product-options', 'DarvenPrecosParceladosProductOptions', array( 34 'restUrl' => rest_url( 'darven-precos-parcelados/v1/' ), 35 'nonce' => wp_create_nonce( 'wp_rest' ), 36 'screen' => 'product', 37 'productId' => isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0, 38 ) 39 ); 40 wp_enqueue_media(); 41 } 42 43 private function enqueueBundle( string $bundle, string $handle, string $object_name, array $config ): void { 44 $asset = $this->getAssetMetadata( $bundle ); 45 $url = plugin_dir_url( DARVEN_EPI_DIR_PATH . 'darven-extra-price-info.php' ) . 'build/' . $bundle . '/'; 46 $deps = isset( $asset['dependencies'] ) && is_array( $asset['dependencies'] ) ? $asset['dependencies'] : array(); 47 $deps = array_values( array_unique( array_merge( $deps, array( 'wp-api-fetch', 'wp-element', 'wp-i18n' ) ) ) ); 48 $version = isset( $asset['version'] ) && is_string( $asset['version'] ) 49 ? $asset['version'] 50 : ( defined( 'DARVEN_EPI_VERSION' ) ? DARVEN_EPI_VERSION : '1.0.0' ); 51 52 wp_enqueue_style( $handle, $url . 'style-index.css', array(), $version, 'all' ); 53 wp_style_add_data( $handle, 'rtl', 'replace' ); 54 wp_enqueue_script( $handle, $url . 'index.js', $deps, $version, true ); 55 wp_localize_script( $handle, $object_name, $config ); 56 if ( function_exists( 'wp_set_script_translations' ) ) { 57 wp_set_script_translations( $handle, \DARVEN_EPI_LANGUAGE_DOMAIN, \DARVEN_EPI_DIR_PATH . 'languages' ); 58 } 59 } 60 61 private function getAssetMetadata( string $bundle ): array { 62 $asset_file = DARVEN_EPI_DIR_PATH . 'build/' . $bundle . '/index.asset.php'; 63 if ( ! file_exists( $asset_file ) ) { 64 return array(); 65 } 66 67 $asset = require $asset_file; 68 69 return is_array( $asset ) ? $asset : array(); 70 } 71 72 private function isProductEditor(): bool { 73 $screen = get_current_screen(); 74 75 return is_object( $screen ) 76 && isset( $screen->post_type, $screen->base ) 77 && 'product' === $screen->post_type 78 && 'post' === $screen->base; 79 } 35 80 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Admin/ProductOptionsController.php
r3627068 r3667117 16 16 17 17 public function register(): void { 18 add_filter( 19 'woocommerce_product_data_tabs', array( $this, 'addTab' ) 20 ); 18 21 add_action( 19 'woocommerce_product_options_general_product_data', 20 array( $this, 'renderFields' ) 22 'woocommerce_product_data_panels', array( $this, 'renderPanel' ) 21 23 ); 22 24 add_action( … … 26 28 } 27 29 28 public function renderFields(): void { 29 echo '<div class="product_custom_field">'; 30 woocommerce_wp_checkbox( 31 array( 32 'id' => '_darven_epi_is_incash_enabled', 33 'placeholder' => '', 34 'label' => __( 'Disable in cash price for this product', 'woocommerce' ), 35 'type' => 'boolean', 36 ) 30 public function addTab( array $tabs ): array { 31 $tabs['darven-precos-parcelados'] = array( 32 'label' => __( 'Darven', 'darven-multiplos-precos-informativos' ), 33 'target' => 'darven-precos-parcelados-product-options-panel', 34 'class' => array(), 37 35 ); 38 woocommerce_wp_checkbox( 39 array( 40 'id' => '_darven_epi_is_installment_enabled', 41 'placeholder' => '', 42 'label' => __( 'Disable installments price for this product', 'woocommerce' ), 43 'type' => 'boolean', 44 ) 36 37 return $tabs; 38 } 39 40 public function renderPanel(): void { 41 global $post; 42 43 $product_id = isset( $post->ID ) ? absint( $post->ID ) : 0; 44 $product = $product_id > 0 ? wc_get_product( $product_id ) : false; 45 $settings = $product instanceof \WC_Product 46 ? $this->repository->getSettings( $product ) 47 : array( 48 'disable_incash' => false, 49 'disable_installments' => false, 50 ); 51 52 printf( 53 '<div id="darven-precos-parcelados-product-options-panel" class="panel woocommerce_options_panel hidden"><div id="darven-precos-parcelados-product-options-root" data-product-id="%s"></div></div>', esc_attr( (string) $product_id ) 45 54 ); 46 echo '</div>'; 55 echo '<noscript><div class="options_group">'; 56 $this->renderFallbackCheckbox( 57 '_darven_epi_is_incash_enabled', __( 'Disable cash price for this product', 'darven-multiplos-precos-informativos' ), true === $settings['disable_incash'] 58 ); 59 $this->renderFallbackCheckbox( 60 '_darven_epi_is_installment_enabled', __( 'Disable installment price for this product', 'darven-multiplos-precos-informativos' ), true === $settings['disable_installments'] 61 ); 62 echo '</div></noscript>'; 63 } 64 65 private function renderFallbackCheckbox( string $name, string $label, bool $is_checked ): void { 66 printf( 67 '<p class="form-field"><input type="hidden" name="%1$s" value="no"><label><input type="checkbox" name="%1$s" value="yes"%2$s> %3$s</label></p>', esc_attr( $name ), $is_checked ? ' checked' : '', esc_html( $label ) 68 ); 47 69 } 48 70 49 71 public function save( \WC_Product $product ): void { 72 if ( ! array_key_exists( '_darven_epi_is_incash_enabled', $_POST ) 73 && ! array_key_exists( '_darven_epi_is_installment_enabled', $_POST ) ) { 74 return; 75 } 76 50 77 if ( ! current_user_can( 'edit_post', $product->get_id() ) ) { 51 78 return; 52 }53 if ( ! isset( $_POST['woocommerce_meta_nonce'] ) ) {54 return;55 }79 } 80 if ( ! isset( $_POST['woocommerce_meta_nonce'] ) ) { 81 return; 82 } 56 83 $nonce = sanitize_text_field( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ); 57 if ( ! wp_verify_nonce( $nonce, 'woocommerce_save_data' ) ) {58 return;59 }84 if ( ! wp_verify_nonce( $nonce, 'woocommerce_save_data' ) ) { 85 return; 86 } 60 87 61 88 $incash_value = isset( $_POST['_darven_epi_is_incash_enabled'] ) && is_string( $_POST['_darven_epi_is_incash_enabled'] ) … … 71 98 ); 72 99 73 $this->repository->save( $product, $settings );100 $this->repository->save( $product, $settings, false ); 74 101 } 75 102 -
darven-multiplos-precos-informativos/tags/4.0.0/src/Admin/SettingsPage.php
r3627068 r3667117 3 3 namespace Darven\ExtraPriceInfo\Admin; 4 4 5 use Darven\ExtraPriceInfo\Admin\SettingsFields\CompatibilityFields;6 use Darven\ExtraPriceInfo\Admin\SettingsFields\DisplayFields;7 use Darven\ExtraPriceInfo\Admin\SettingsFields\GeneralFields;8 use Darven\ExtraPriceInfo\Admin\SettingsFields\PositionsFields;9 5 10 6 final class SettingsPage { 11 public function register(): void {12 add_action( 'admin_menu', array( $this, 'addMenuPage' ) );13 add_action( 'admin_init', array( $this, 'initializeSettings' ) );14 }15 16 public function addMenuPage(): void {17 add_submenu_page(18 'woocommerce',19 __( 'In Cash and Installments Price', 'darven-epi' ),20 'Preço á Vista e com Parcelamento',21 'manage_options',22 'darven-epi-admin',23 array( $this, 'renderPage' )24 );25 }26 27 7 public function renderPage(): void { 28 $tab = filter_input( INPUT_GET, 'tab' ); 29 30 include DARVEN_EPI_DIR_PATH . 'templates/admin/general-settings.php'; 31 } 32 33 public function initializeSettings(): void { 34 $tab = filter_input( INPUT_GET, 'tab' ); 35 36 if ( 'colorsandstyles' === $tab ) { 37 $this->addInCashSection( __( 'In Cash Settings', 'darven-epi' ) ); 38 $this->addInstallmentsSection( __( 'Installments Settings', 'darven-epi' ) ); 39 ( new DisplayFields() )->register(); 40 41 return; 42 } 43 44 if ( 'positions' === $tab ) { 45 $this->addInCashSection( __( 'Statements Positions Settings', 'darven-epi' ) ); 46 ( new PositionsFields() )->register(); 47 48 return; 49 } 50 51 if ( 'compatibility' === $tab ) { 52 $this->addInCashSection( __( 'Compatibility Settings', 'darven-epi' ) ); 53 ( new CompatibilityFields() )->register(); 54 55 return; 56 } 57 58 $this->addInCashSection( __( 'In Cash Settings', 'darven-epi' ) ); 59 $this->addInstallmentsSection( __( 'Installments Settings', 'darven-epi' ) ); 60 add_settings_section( 61 'darven_epi_advanced_installments_settings_section', 62 __( 'Advanced Installments Settings Section', 'darven-epi' ), 63 array( $this, 'renderAdvancedInstallmentsSection' ), 64 'darven-epi-admin' 65 ); 66 ( new GeneralFields() )->register(); 67 } 68 69 public function renderSection(): void { 70 } 71 72 public function renderAdvancedInstallmentsSection(): void { 73 printf( 74 '<div class="wrap"> %s</div>', 75 esc_attr( 76 __( 77 'Use this section to set up customized interest fees. If your gateway has incremental fees (each month the same value is summed up), please use the incremental interest fee settings in the previous section for a better experience.', 78 'darven-epi' 79 ) 80 ) 81 ); 82 } 83 84 private function addInCashSection( string $title ): void { 85 add_settings_section( 86 'darven_epi_incash_settings_section', 87 $title, 88 array( $this, 'renderSection' ), 89 'darven-epi-admin' 90 ); 91 } 92 93 private function addInstallmentsSection( string $title ): void { 94 add_settings_section( 95 'darven_epi_installments_settings_section', 96 $title, 97 array( $this, 'renderSection' ), 98 'darven-epi-admin' 99 ); 8 echo '<div id="darven-precos-parcelados-settings-root"></div>'; 100 9 } 101 10 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Compatibility/LegacyProductSettingsAdapter.php
r3627068 r3667117 6 6 public function fromLegacyMeta( $incash_value, $installments_value ): array { 7 7 return array( 8 'schema_version' => 1, 8 9 'disable_incash' => 'yes' === $incash_value, 9 10 'disable_installments' => 'yes' === $installments_value, -
darven-multiplos-precos-informativos/tags/4.0.0/src/Compatibility/LegacySettingsAdapter.php
r3627068 r3667117 13 13 public function fromLegacyOptions( array $legacy_options ): array { 14 14 $settings = array( 15 'schema_version' => 1,15 'schema_version' => 2, 16 16 ); 17 17 -
darven-multiplos-precos-informativos/tags/4.0.0/src/Frontend/Assets.php
r3627068 r3667117 4 4 5 5 final class Assets { 6 /** 7 * @var InlineStyles 8 */ 9 private $inline_styles; 10 11 public function __construct( InlineStyles $inline_styles ) { 12 $this->inline_styles = $inline_styles; 13 } 14 6 15 public function enqueue(): void { 7 16 $plugin_url = plugin_dir_url( DARVEN_EPI_DIR_PATH . 'darven-extra-price-info.php' ); … … 9 18 10 19 wp_enqueue_style( 'darven-epi', $plugin_url . 'public/css/styles.css', array(), $version, 'all' ); 11 wp_enqueue_script( 'darven-epi', $plugin_url . 'public/js/frontend.js', array( 'jquery' ), $version, false ); 20 wp_add_inline_style( 'darven-epi', $this->inline_styles->render() ); 21 wp_enqueue_script( 'darven-epi', $plugin_url . 'public/js/frontend.js', array(), $version, false ); 12 22 } 13 23 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Frontend/InlineStyles.php
r3627068 r3667117 18 18 $display = $this->settings_repository->getSection( 'display' ); 19 19 20 return str_replace( '\\n', "\n", '<style>\n\n' 21 . ' .darven-epi-incash-prefix {\n\n' 22 . ' color: ' . $this->getValue( $display, 'darven_epi_color_of_incash_prefix' ) . ';\n' 23 . ' font-size: ' . $this->getValue( $display, 'darven_epi_font_size_of_incash_prefix', '1' ) . 'em;\n' 24 . ' }\n\n' 25 . ' .darven-epi-incash-price {\n\n' 26 . ' color: ' . $this->getValue( $display, 'darven_epi_color_of_incash_price' ) . ' !important;\n' 20 return str_replace( '\\n', "\n", '\n .darven-epi-incash-prefix {\n\n color: ' . $this->getValue( $display, 'darven_epi_color_of_incash_prefix' ) . ';\n font-size: ' . $this->getValue( $display, 'darven_epi_font_size_of_incash_prefix', '1' ) . 'em;\n }\n\n .darven-epi-incash-price {\n\n color: ' . $this->getValue( $display, 'darven_epi_color_of_incash_price' ) . ' !important;\n' 27 21 . ' font-size: ' . $this->getValue( $display, 'darven_epi_font_size_of_incash_price', '1' ) . 'em;\n\n' 28 22 . ' }\n\n' … … 46 40 . ' color: ' . $this->getValue( $display, 'darven_epi_color_of_installments_suffix' ) . ';\n' 47 41 . ' font-size: ' . $this->getValue( $display, 'darven_epi_font_size_of_installments_suffix', '1' ) . 'em;\n' 48 . ' }\n\n\n' 49 . '</style>\n' ); 42 . ' }\n\n\n' ); 50 43 } 51 44 -
darven-multiplos-precos-informativos/tags/4.0.0/src/Repositories/ProductSettingsRepository.php
r3627068 r3667117 16 16 private $adapter; 17 17 18 public function __construct( LegacyProductSettingsAdapter $adapter ) { 19 $this->adapter = $adapter; 18 /** 19 * @var callable 20 */ 21 private $product_reloader; 22 23 public function __construct( LegacyProductSettingsAdapter $adapter, ?callable $product_reloader = null ) { 24 $this->adapter = $adapter; 25 $this->product_reloader = $product_reloader ?? static function ( int $product_id ) { 26 return function_exists( 'wc_get_product' ) ? wc_get_product( $product_id ) : false; 27 }; 20 28 } 21 29 22 30 public function getSettings( \WC_Product $product ): array { 31 $direct_settings = $this->getDirectSettings( $product ); 32 33 if ( null !== $direct_settings ) { 34 return $direct_settings; 35 } 36 37 if ( $product->is_type( 'variation' ) ) { 38 $parent_id = (int) $product->get_parent_id(); 39 $parent = $parent_id > 0 ? wc_get_product( $parent_id ) : false; 40 41 if ( $parent instanceof \WC_Product ) { 42 $parent_settings = $this->getDirectSettings( $parent ); 43 44 if ( null !== $parent_settings ) { 45 return $parent_settings; 46 } 47 } 48 } 49 50 return $this->adapter->fromLegacyMeta( '', '' ); 51 } 52 53 private function getDirectSettings( \WC_Product $product ): ?array { 23 54 $canonical_settings = $product->get_meta( self::META_KEY, true ); 24 55 25 56 if ( $this->isCanonicalSettings( $canonical_settings ) ) { 26 return $canonical_settings; 57 return $this->normalizeSettings( $canonical_settings ); 58 } 59 60 $legacy_incash = $product->get_meta( self::LEGACY_INCASH_META_KEY, true ); 61 $legacy_installments = $product->get_meta( self::LEGACY_INSTALLMENTS_META_KEY, true ); 62 63 if ( '' === $legacy_incash && '' === $legacy_installments ) { 64 return null; 27 65 } 28 66 29 67 return $this->adapter->fromLegacyMeta( 30 $product->get_meta( self::LEGACY_INCASH_META_KEY, true ), 31 $product->get_meta( self::LEGACY_INSTALLMENTS_META_KEY, true ) 68 $legacy_incash, $legacy_installments 32 69 ); 33 70 } 34 71 35 public function save( \WC_Product $product, array $settings ): bool { 72 public function save( \WC_Product $product, array $settings, bool $persist = true ): bool { 73 $current_settings = $this->getSettings( $product ); 36 74 $canonical_settings = array( 37 'disable_incash' => true === ( $settings['disable_incash'] ?? false ), 38 'disable_installments' => true === ( $settings['disable_installments'] ?? false ), 75 'schema_version' => 1, 76 'disable_incash' => array_key_exists( 'disable_incash', $settings ) 77 ? true === $settings['disable_incash'] 78 : $current_settings['disable_incash'], 79 'disable_installments' => array_key_exists( 'disable_installments', $settings ) 80 ? true === $settings['disable_installments'] 81 : $current_settings['disable_installments'], 39 82 ); 40 83 $legacy_meta = $this->adapter->projectToLegacyMeta( $canonical_settings ); … … 43 86 $product->update_meta_data( self::LEGACY_INCASH_META_KEY, $legacy_meta[ self::LEGACY_INCASH_META_KEY ] ); 44 87 $product->update_meta_data( self::LEGACY_INSTALLMENTS_META_KEY, $legacy_meta[ self::LEGACY_INSTALLMENTS_META_KEY ] ); 88 if ( $persist ) { 89 $product->save(); 90 $saved_product = call_user_func( $this->product_reloader, (int) $product->get_id() ); 91 if ( ! $saved_product instanceof \WC_Product ) { 92 return false; 93 } 94 } else { 95 $saved_product = $product; 96 } 45 97 46 return $canonical_settings === $ product->get_meta( self::META_KEY, true )47 && $legacy_meta[ self::LEGACY_INCASH_META_KEY ] === $ product->get_meta( self::LEGACY_INCASH_META_KEY, true )48 && $legacy_meta[ self::LEGACY_INSTALLMENTS_META_KEY ] === $ product->get_meta( self::LEGACY_INSTALLMENTS_META_KEY, true );98 return $canonical_settings === $saved_product->get_meta( self::META_KEY, true ) 99 && $legacy_meta[ self::LEGACY_INCASH_META_KEY ] === $saved_product->get_meta( self::LEGACY_INCASH_META_KEY, true ) 100 && $legacy_meta[ self::LEGACY_INSTALLMENTS_META_KEY ] === $saved_product->get_meta( self::LEGACY_INSTALLMENTS_META_KEY, true ); 49 101 } 50 102 … … 55 107 && is_bool( $settings['disable_installments'] ); 56 108 } 109 110 private function normalizeSettings( array $settings ): array { 111 return array( 112 'schema_version' => 1, 113 'disable_incash' => $settings['disable_incash'], 114 'disable_installments' => $settings['disable_installments'], 115 ); 116 } 57 117 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Repositories/SettingsRepository.php
r3627068 r3667117 30 30 private $adapter; 31 31 32 public function __construct( LegacySettingsAdapter $adapter ) { 33 $this->adapter = $adapter; 32 /** 33 * @var SettingsSanitizer 34 */ 35 private $sanitizer; 36 37 public function __construct( LegacySettingsAdapter $adapter, ?SettingsSanitizer $sanitizer = null ) { 38 $this->adapter = $adapter; 39 $this->sanitizer = $sanitizer ?? new SettingsSanitizer(); 34 40 } 35 41 36 42 public function getSettings(): array { 37 $canonical = get_option( self::OPTION_NAME, array() ); 38 39 if ( $this->isCanonicalDocument( $canonical ) ) { 40 return $canonical; 41 } 42 43 return $this->adapter->fromLegacyOptions( $this->getLegacyOptions() ); 43 return $this->getNormalizedSettings(); 44 } 45 46 /** 47 * Returns a sanitized v2 document without migrating legacy or v1 storage. 48 */ 49 public function getNormalizedSettings(): array { 50 $canonical = get_option( self::OPTION_NAME, null ); 51 $legacy_options = $this->getLegacyOptions(); 52 $has_persisted_darven_settings = null !== $canonical || $this->hasPersistedLegacySettings( $legacy_options ); 53 54 if ( $this->isReadableDocument( $canonical ) ) { 55 return $this->normalizeDocument( $canonical, $has_persisted_darven_settings, $legacy_options ); 56 } 57 58 return $this->normalizeDocument( $this->adapter->fromLegacyOptions( $legacy_options ), $has_persisted_darven_settings, $legacy_options ); 44 59 } 45 60 … … 47 62 $this->assertKnownSection( $section ); 48 63 49 $settings = $this->get Settings();64 $settings = $this->getNormalizedSettings(); 50 65 51 66 return $settings[ $section ]; … … 53 68 54 69 public function getYithDynamicPricingMode(): string { 55 $canonical = get_option( self::OPTION_NAME, null ); 56 $has_persisted_darven_settings = null !== $canonical; 57 $legacy_options = array(); 58 59 foreach ( self::LEGACY_OPTION_NAMES as $option_name ) { 60 $legacy_option = get_option( $option_name, null ); 61 62 if ( null !== $legacy_option ) { 63 $has_persisted_darven_settings = true; 64 } 65 66 $legacy_options[ $option_name ] = null === $legacy_option ? array() : $legacy_option; 67 } 68 69 $settings = $this->isCanonicalDocument( $canonical ) 70 ? $canonical 71 : $this->adapter->fromLegacyOptions( $legacy_options ); 72 73 $compatibility = isset( $settings['compatibility'] ) && is_array( $settings['compatibility'] ) 74 ? $settings['compatibility'] 75 : array(); 76 77 $legacy_compatibility = $legacy_options['darven_epi_option_compatibility']; 78 79 if ( ! isset( $compatibility[ YithDynamicPricingMode::FIELD ] ) 80 && is_array( $legacy_compatibility ) 81 && isset( $legacy_compatibility[ YithDynamicPricingMode::LEGACY_FIELD ] ) ) { 82 $compatibility[ YithDynamicPricingMode::LEGACY_FIELD ] = $legacy_compatibility[ YithDynamicPricingMode::LEGACY_FIELD ]; 83 } 84 85 return YithDynamicPricingMode::resolve( $compatibility, $has_persisted_darven_settings ); 70 $settings = $this->getNormalizedSettings(); 71 72 return $settings['compatibility'][ YithDynamicPricingMode::FIELD ]; 86 73 } 87 74 … … 89 76 $this->assertKnownSection( $section ); 90 77 91 $settings = $this->getSettings(); 92 $settings['schema_version'] = 1; 93 $settings[ $section ] = $values; 78 $settings = $this->getNormalizedSettings(); 79 $settings[ $section ] = $values; 80 81 return $this->saveDocumentInternal( $settings, array( $section ), $deferred_legacy_option, array( $section ) ); 82 } 83 84 /** 85 * Merges submitted sections with the normalized current state, stores v2, 86 * and mirrors every legacy option. 87 */ 88 public function saveDocument( array $document ): bool { 89 $sections = array(); 90 foreach ( self::SECTION_NAMES as $section ) { 91 if ( isset( $document[ $section ] ) && is_array( $document[ $section ] ) ) { 92 $sections[] = $section; 93 } 94 } 95 96 return $this->saveDocumentInternal( $document, $sections, '' ); 97 } 98 99 private function saveDocumentInternal( array $document, array $submitted_sections, string $deferred_legacy_option, array $replaced_sections = array() ): bool { 100 $settings = $this->getNormalizedSettings(); 101 102 foreach ( self::SECTION_NAMES as $section ) { 103 if ( isset( $document[ $section ] ) && is_array( $document[ $section ] ) ) { 104 $settings[ $section ] = in_array( $section, $replaced_sections, true ) 105 ? $document[ $section ] 106 : array_merge( $settings[ $section ], $document[ $section ] ); 107 } 108 } 109 110 $settings = $this->normalizeDocument( $settings, true ); 94 111 95 112 if ( ! $this->persistAndVerify( self::OPTION_NAME, $settings ) ) { … … 98 115 99 116 return $this->persistLegacyOptions( 100 $this->adapter->projectToLegacyOptions( $settings, $this->getLegacyOptions() ), 101 $section, 102 $deferred_legacy_option 117 $this->adapter->projectToLegacyOptions( $settings, $this->getLegacyOptions() ), empty( $submitted_sections ) ? self::SECTION_NAMES : $submitted_sections, $deferred_legacy_option 103 118 ); 104 119 } … … 116 131 } 117 132 118 private function isCanonicalDocument( $settings ): bool { 119 if ( ! is_array( $settings ) || ! isset( $settings['schema_version'] ) || 1 !== $settings['schema_version'] ) { 120 return false; 121 } 133 private function isReadableDocument( $settings ): bool { 134 if ( ! is_array( $settings ) || ! isset( $settings['schema_version'] ) || ! in_array( $settings['schema_version'], array( 1, 2 ), true ) ) { 135 return false; 136 } 137 138 foreach ( self::SECTION_NAMES as $section ) { 139 if ( ! array_key_exists( $section, $settings ) || ! is_array( $settings[ $section ] ) ) { 140 return false; 141 } 142 } 143 144 return true; 145 } 146 147 private function normalizeDocument( array $document, bool $has_persisted_darven_settings, array $legacy_options = array() ): array { 148 $normalized = array( 'schema_version' => 2 ); 122 149 123 150 foreach ( self::SECTION_NAMES as $section ) { 124 if ( ! array_key_exists( $section, $settings ) || ! is_array( $settings[ $section ] ) ) { 125 return false; 126 } 127 } 128 129 return true; 151 $values = isset( $document[ $section ] ) && is_array( $document[ $section ] ) ? $document[ $section ] : array(); 152 if ( 'compatibility' === $section ) { 153 if ( ! isset( $values[ YithDynamicPricingMode::FIELD ] ) 154 && ! isset( $values[ YithDynamicPricingMode::LEGACY_FIELD ] ) 155 && isset( $legacy_options['darven_epi_option_compatibility'] ) 156 && is_array( $legacy_options['darven_epi_option_compatibility'] ) 157 && isset( $legacy_options['darven_epi_option_compatibility'][ YithDynamicPricingMode::LEGACY_FIELD ] ) ) { 158 $values[ YithDynamicPricingMode::LEGACY_FIELD ] = $legacy_options['darven_epi_option_compatibility'][ YithDynamicPricingMode::LEGACY_FIELD ]; 159 } 160 161 $mode = YithDynamicPricingMode::resolve( $values, $has_persisted_darven_settings ); 162 $normalized[ $section ] = array( 163 YithDynamicPricingMode::FIELD => $mode, 164 ); 165 continue; 166 } 167 168 $normalized[ $section ] = $this->sanitizer->sanitizeSection( $section, $values ); 169 } 170 171 return $normalized; 130 172 } 131 173 … … 134 176 135 177 foreach ( self::LEGACY_OPTION_NAMES as $option_name ) { 136 $legacy_options[ $option_name ] = get_option( $option_name, array());178 $legacy_options[ $option_name ] = get_option( $option_name, null ); 137 179 } 138 180 139 181 return $legacy_options; 182 } 183 184 private function hasPersistedLegacySettings( array $legacy_options ): bool { 185 foreach ( $legacy_options as $legacy_option ) { 186 if ( null !== $legacy_option ) { 187 return true; 188 } 189 } 190 191 return false; 140 192 } 141 193 … … 146 198 } 147 199 148 private function persistLegacyOptions( array $legacy_options, string $section, string $deferred_legacy_option ): bool {200 private function persistLegacyOptions( array $legacy_options, array $sections, string $deferred_legacy_option ): bool { 149 201 $failed_options = array(); 150 202 … … 161 213 if ( ! empty( $failed_options ) ) { 162 214 if ( ! $this->persistAndVerify( 163 self::SYNC_STATE_OPTION, 164 array( 165 'pending_sections' => array( $section ), 215 self::SYNC_STATE_OPTION, array( 216 'pending_sections' => $sections, 166 217 'failed_options' => $failed_options, 167 218 ) -
darven-multiplos-precos-informativos/tags/4.0.0/src/Services/InstallmentPriceFormatter.php
r3627068 r3667117 57 57 ); 58 58 59 if ( 'popup' === ( $this->general_settings['darven_epi_mode_of_view'] ?? '' ) ) { 60 $statement = $prefix 61 . '<span class="darven-epi-installment-count">' . $number_of_installments . 'x de</span>' 62 . '<span class="darven-epi-installment-price"> ' . wp_strip_all_tags( wc_price( $price_table[1] ) ) . '</span>' 63 . $suffix; 59 $mode = (string) ( $this->general_settings['darven_epi_mode_of_view'] ?? '' ); 60 $installment_count = sprintf( 61 /* translators: %1$s: number of installments. */ 62 __( '%1$sx of', 'darven-multiplos-precos-informativos' ), $number_of_installments 63 ); 64 65 if ( 'popup' === $mode ) { 66 $statement = $this->getStatement( 67 $prefix, $installment_count, wp_strip_all_tags( wc_price( $price_table[1] ) ), $suffix 68 ); 64 69 65 70 return $this->markup_builder->div( 66 71 'installments-price-statement darven-epi-installments-price-statement', 67 $statement ,72 $statement . $this->getPopupMarkup( $price_table[0] ), 68 73 'installments' 69 74 ); 70 75 } 71 76 72 if ( 'nofee' === ( $this->general_settings['darven_epi_mode_of_view'] ?? '' ) ) { 73 $statement = $prefix 74 . '<span class="darven-epi-installment-count">' . $number_of_installments . 'x de</span>' 75 . '<span class="darven-epi-installment-price"> ' . wp_strip_all_tags( wc_price( $installment_price ) ) . '</span>' 76 . $suffix; 77 $popup_content = '<div class="messagepop pop darven-epi-installments-popup" aria-hidden="true">' 78 . $price_table[0] 79 . '</div>'; 80 $popup_toggle = '<button type="button" class="darven-epi-installments-toggle" aria-expanded="false">' 81 . (string) ( $this->general_settings['darven_epi_popup_text'] ?? '' ) 82 . '</button>'; 77 if ( 'nofee' === $mode ) { 78 $statement = $this->getStatement( 79 $prefix, $installment_count, wp_strip_all_tags( wc_price( $installment_price ) ), $suffix 80 ); 83 81 84 82 return $this->markup_builder->div( 85 83 'installments-price-statement darven-epi-installments-price-statement', 86 $statement . $ popup_content . $popup_toggle,84 $statement . $this->getPopupMarkup( $price_table[0] ), 87 85 'installments' 88 86 ); 89 87 } 90 88 91 $statement = $prefix 92 . '<span class="darven-epi-installment-count">' . $number_of_installments . 'x de</span>' 93 . '<span class="darven-epi-installment-price"> ' . wp_strip_all_tags( wc_price( $price_table[1] ) ) . '</span>' 94 . $suffix; 89 $statement = $this->getStatement( 90 $prefix, $installment_count, wp_strip_all_tags( wc_price( $price_table[1] ) ), $suffix 91 ); 95 92 96 93 return $this->markup_builder->div( … … 101 98 } 102 99 100 private function getStatement( string $prefix, string $count, string $price, string $suffix ): string { 101 return sprintf( 102 '%s<span class="darven-epi-installment-count">%s</span><span class="darven-epi-installment-price"> %s</span>%s', $prefix, $count, $price, $suffix 103 ); 104 } 105 106 private function getPopupMarkup( string $price_table ): string { 107 $instance_id = $this->getPopupInstanceId(); 108 $dialog_id = $instance_id . '-dialog'; 109 $title_id = $instance_id . '-title'; 110 $popup_text = wp_kses( 111 (string) ( $this->general_settings['darven_epi_popup_text'] ?? '' ), 112 array( 113 'br' => array(), 114 'b' => array(), 115 'em' => array(), 116 'i' => array(), 117 'span' => array( 118 'class' => array(), 119 'style' => array(), 120 ), 121 ) 122 ); 123 $popup_label = trim( 124 html_entity_decode( wp_strip_all_tags( $popup_text ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ) 125 ); 126 127 if ( '' === $popup_label ) { 128 $popup_label = __( 'View installment options', 'darven-multiplos-precos-informativos' ); 129 $popup_text = esc_html( $popup_label ); 130 } 131 132 $title = esc_html( __( 'Installment options', 'darven-multiplos-precos-informativos' ) ); 133 $close_label = esc_attr( __( 'Close installment options', 'darven-multiplos-precos-informativos' ) ); 134 135 $popup = '<div id="' . esc_attr( $dialog_id ) 136 . '" class="messagepop pop darven-epi-installments-popup" hidden aria-hidden="true"' 137 . ' role="dialog" aria-modal="true" aria-labelledby="' . esc_attr( $title_id ) . '">' 138 . '<div class="darven-epi-installments-backdrop" aria-hidden="true"></div>' 139 . '<div class="darven-epi-installments-dialog" role="document">' 140 . '<h2 id="' . esc_attr( $title_id ) 141 . '" class="screen-reader-text darven-epi-installments-title">' . $title . '</h2>' 142 . '<button type="button" class="darven-epi-installments-close" aria-label="' . $close_label . '">' 143 . '<span aria-hidden="true">×</span>' 144 . '</button>' 145 . '<div class="darven-epi-installments-table-wrap">' . $price_table . '</div>' 146 . '</div>' 147 . '</div>'; 148 $toggle = '<button type="button" class="darven-epi-installments-toggle" aria-expanded="false" aria-controls="' 149 . esc_attr( $dialog_id ) . '" aria-label="' . esc_attr( $popup_label ) . '">' . $popup_text . '</button>'; 150 151 return $popup . $toggle; 152 } 153 154 private function getPopupInstanceId(): string { 155 $unique_id = function_exists( 'wp_generate_uuid4' ) 156 ? wp_generate_uuid4() 157 : uniqid( '', true ); 158 159 return 'darven-epi-installments-' . $unique_id; 160 } 161 103 162 public function getPriceTable( float $price ): array { 104 163 $install_count = $this->getInstallmentData( $price )['table_count']; … … 108 167 if ( ! empty( $this->general_settings['darven_epi_installments_interest_fee_is_table_enabled'] ) ) { 109 168 $customised_values = array_map( 110 static function ( $value ): float {111 $value = str_replace( ',', '.', trim( $value ) );112 113 return is_numeric( $value ) ? (float) $value : 0.0;114 },169 static function ( $value ): float { 170 $value = str_replace( ',', '.', trim( $value ) ); 171 172 return is_numeric( $value ) ? (float) $value : 0.0; 173 }, 115 174 explode( '|', (string) ( $this->general_settings['darven_epi_installments_interest_fee_table'] ?? '' ) ) 116 175 ); 117 $interest_fee_from = max( 1, (int) ( $this->general_settings['darven_epi_installments_interest_fee_from'] ?? 0 ));176 $interest_fee_from = (int) ( $this->general_settings['darven_epi_installments_interest_fee_from'] ?? 0 ); 118 177 119 178 for ( $installment = 1; $installment <= $install_count; $installment++ ) { 120 179 $interest_rate = 0.0; 121 180 122 if ( $installment >= $interest_fee_from ) {181 if ( 0 !== $interest_fee_from && $installment >= $interest_fee_from ) { 123 182 $interest_index = $installment - $interest_fee_from; 124 183 $interest_rate = $customised_values[ $interest_index ] ?? 0.0; … … 128 187 $installment_price = $total_with_interest / $installment; 129 188 $html_result .= '<tr>'; 130 $html_result .= '<td>' . $installment . 'x de</td><td>' . wc_price( $installment_price ) . '</td>'; 189 $installment_label = sprintf( 190 /* translators: %1$s: number of installments. */ 191 __( '%1$sx of', 'darven-multiplos-precos-informativos' ), $installment 192 ); 193 $html_result .= '<td>' . $installment_label . '</td><td>' . wc_price( $installment_price ) . '</td>'; 131 194 $html_result .= '</tr>'; 132 195 } … … 145 208 if ( $first_install ) { 146 209 $price_for_interest = ( $price_for_interest 147 * (float) ( $this->general_settings['darven_epi_installments_interest_fee_first_install'] ?? 0 ) / 100 )210 * (float) ( $this->general_settings['darven_epi_installments_interest_fee_first_install'] ?? 0 ) / 100 ) 148 211 + $price_for_interest; 149 212 $first_install = false; … … 152 215 $installment_price = $this->getTaxCalculation( $price_for_interest, 'second_period', $installment ); 153 216 $html_result .= '<td>' . $installment . 'x</td><td>' . wc_price( $installment_price ) 154 . ' = ' . wc_price( $installment_price * $installment ) . '</td>';217 . ' = ' . wc_price( $installment_price * $installment ) . '</td>'; 155 218 } else { 156 219 $installment_price = $price_for_interest / $installment; … … 223 286 224 287 if ( 225 $price_count > $interest_fee_from 226 && $display_count > $interest_fee_from 227 && 'nofee' === ( $this->general_settings['darven_epi_mode_of_view'] ?? '' ) 288 0 !== $interest_fee_from 289 && $price_count >= $interest_fee_from 290 && $display_count >= $interest_fee_from 291 && 'nofee' === ( $this->general_settings['darven_epi_mode_of_view'] ?? '' ) 228 292 ) { 229 293 $price_count = $interest_fee_from - 1; … … 232 296 233 297 return array( 234 'table_count' => $table_count,235 'display_count' => $display_count,236 'price_count' => $price_count,298 'table_count' => $table_count, 299 'display_count' => $display_count, 300 'price_count' => $price_count, 237 301 ); 238 302 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Setup/Plugin.php
r3627068 r3667117 5 5 use Darven\ExtraPriceInfo\Admin\Assets as AdminAssets; 6 6 use Darven\ExtraPriceInfo\Admin\ProductOptionsController; 7 use Darven\ExtraPriceInfo\Admin\SettingsPage; 7 use Darven\ExtraPriceInfo\Admin\ReactPage; 8 use Darven\ExtraPriceInfo\Admin\SettingsRestController; 8 9 use Darven\ExtraPriceInfo\Compatibility\LegacyProductSettingsAdapter; 9 10 use Darven\ExtraPriceInfo\Compatibility\LegacySettingsAdapter; 10 11 use Darven\ExtraPriceInfo\Frontend\Assets as FrontendAssets; 12 use Darven\ExtraPriceInfo\Frontend\InlineStyles; 11 13 use Darven\ExtraPriceInfo\Repositories\ProductSettingsRepository; 12 14 use Darven\ExtraPriceInfo\Repositories\SettingsRepository; … … 32 34 $product_settings 33 35 ); 34 $settings_page = new SettingsPage(); 36 $settings_page = new ReactPage( $settings ); 37 $settings_rest = new SettingsRestController( $settings, $product_settings ); 35 38 $product_options = new ProductOptionsController( $product_settings ); 36 39 $admin_assets = new AdminAssets(); 37 $frontend_assets = new FrontendAssets( );40 $frontend_assets = new FrontendAssets( new InlineStyles( $settings ) ); 38 41 $text_domain_loader = new TextDomainLoader(); 39 42 … … 44 47 45 48 $settings_page->register(); 49 add_action( 'rest_api_init', array( $settings_rest, 'register' ) ); 46 50 $product_options->register(); 47 51 } -
darven-multiplos-precos-informativos/tags/4.0.0/src/Setup/TextDomainLoader.php
r3627068 r3667117 6 6 public function load(): void { 7 7 load_plugin_textdomain( 8 'darven-epi', 9 false, 10 dirname( plugin_basename( DARVEN_EPI_DIR_PATH . 'darven-extra-price-info.php' ) ) . '/i18n/languages/' 8 \DARVEN_EPI_LANGUAGE_DOMAIN, false, dirname( plugin_basename( \DARVEN_EPI_DIR_PATH . 'darven-extra-price-info.php' ) ) . '/languages/' 11 9 ); 12 10 } -
darven-multiplos-precos-informativos/tags/4.0.0/vendor/autoload.php
r3627068 r3667117 20 20 require_once __DIR__ . '/composer/autoload_real.php'; 21 21 22 return ComposerAutoloaderInit 20e0eb45e47b4ba6e645250a31f9ffef::getLoader();22 return ComposerAutoloaderInitdb32075ee5d847d9dbbfd29562c8f5c8::getLoader(); -
darven-multiplos-precos-informativos/tags/4.0.0/vendor/composer/autoload_classmap.php
r3627068 r3667117 9 9 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 10 10 'Darven\\ExtraPriceInfo\\Admin\\Assets' => $baseDir . '/src/Admin/Assets.php', 11 'Darven\\ExtraPriceInfo\\Admin\\LegacySettingsSync' => $baseDir . '/src/Admin/LegacySettingsSync.php',12 11 'Darven\\ExtraPriceInfo\\Admin\\ProductOptionsController' => $baseDir . '/src/Admin/ProductOptionsController.php', 13 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\CompatibilityFields' => $baseDir . '/src/Admin/SettingsFields/CompatibilityFields.php', 14 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\DisplayFields' => $baseDir . '/src/Admin/SettingsFields/DisplayFields.php', 15 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\GeneralFields' => $baseDir . '/src/Admin/SettingsFields/GeneralFields.php', 16 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\PositionsFields' => $baseDir . '/src/Admin/SettingsFields/PositionsFields.php', 12 'Darven\\ExtraPriceInfo\\Admin\\ReactPage' => $baseDir . '/src/Admin/ReactPage.php', 17 13 'Darven\\ExtraPriceInfo\\Admin\\SettingsPage' => $baseDir . '/src/Admin/SettingsPage.php', 14 'Darven\\ExtraPriceInfo\\Admin\\SettingsRestController' => $baseDir . '/src/Admin/SettingsRestController.php', 18 15 'Darven\\ExtraPriceInfo\\Compatibility\\LegacyProductSettingsAdapter' => $baseDir . '/src/Compatibility/LegacyProductSettingsAdapter.php', 19 16 'Darven\\ExtraPriceInfo\\Compatibility\\LegacySettingsAdapter' => $baseDir . '/src/Compatibility/LegacySettingsAdapter.php', … … 23 20 'Darven\\ExtraPriceInfo\\Repositories\\ProductSettingsRepository' => $baseDir . '/src/Repositories/ProductSettingsRepository.php', 24 21 'Darven\\ExtraPriceInfo\\Repositories\\SettingsRepository' => $baseDir . '/src/Repositories/SettingsRepository.php', 22 'Darven\\ExtraPriceInfo\\Repositories\\SettingsSanitizer' => $baseDir . '/src/Repositories/SettingsSanitizer.php', 25 23 'Darven\\ExtraPriceInfo\\Services\\CashPriceFormatter' => $baseDir . '/src/Services/CashPriceFormatter.php', 26 24 'Darven\\ExtraPriceInfo\\Services\\FinalPriceFormatter' => $baseDir . '/src/Services/FinalPriceFormatter.php', -
darven-multiplos-precos-informativos/tags/4.0.0/vendor/composer/autoload_real.php
r3627068 r3667117 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 20e0eb45e47b4ba6e645250a31f9ffef5 class ComposerAutoloaderInitdb32075ee5d847d9dbbfd29562c8f5c8 6 6 { 7 7 private static $loader; … … 25 25 require __DIR__ . '/platform_check.php'; 26 26 27 spl_autoload_register(array('ComposerAutoloaderInit 20e0eb45e47b4ba6e645250a31f9ffef', 'loadClassLoader'), true, true);27 spl_autoload_register(array('ComposerAutoloaderInitdb32075ee5d847d9dbbfd29562c8f5c8', 'loadClassLoader'), true, true); 28 28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 29 spl_autoload_unregister(array('ComposerAutoloaderInit 20e0eb45e47b4ba6e645250a31f9ffef', 'loadClassLoader'));29 spl_autoload_unregister(array('ComposerAutoloaderInitdb32075ee5d847d9dbbfd29562c8f5c8', 'loadClassLoader')); 30 30 31 31 require __DIR__ . '/autoload_static.php'; 32 call_user_func(\Composer\Autoload\ComposerStaticInit 20e0eb45e47b4ba6e645250a31f9ffef::getInitializer($loader));32 call_user_func(\Composer\Autoload\ComposerStaticInitdb32075ee5d847d9dbbfd29562c8f5c8::getInitializer($loader)); 33 33 34 34 $loader->register(true); -
darven-multiplos-precos-informativos/tags/4.0.0/vendor/composer/autoload_static.php
r3627068 r3667117 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 20e0eb45e47b4ba6e645250a31f9ffef7 class ComposerStaticInitdb32075ee5d847d9dbbfd29562c8f5c8 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 24 24 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 25 25 'Darven\\ExtraPriceInfo\\Admin\\Assets' => __DIR__ . '/../..' . '/src/Admin/Assets.php', 26 'Darven\\ExtraPriceInfo\\Admin\\LegacySettingsSync' => __DIR__ . '/../..' . '/src/Admin/LegacySettingsSync.php',27 26 'Darven\\ExtraPriceInfo\\Admin\\ProductOptionsController' => __DIR__ . '/../..' . '/src/Admin/ProductOptionsController.php', 28 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\CompatibilityFields' => __DIR__ . '/../..' . '/src/Admin/SettingsFields/CompatibilityFields.php', 29 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\DisplayFields' => __DIR__ . '/../..' . '/src/Admin/SettingsFields/DisplayFields.php', 30 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\GeneralFields' => __DIR__ . '/../..' . '/src/Admin/SettingsFields/GeneralFields.php', 31 'Darven\\ExtraPriceInfo\\Admin\\SettingsFields\\PositionsFields' => __DIR__ . '/../..' . '/src/Admin/SettingsFields/PositionsFields.php', 27 'Darven\\ExtraPriceInfo\\Admin\\ReactPage' => __DIR__ . '/../..' . '/src/Admin/ReactPage.php', 32 28 'Darven\\ExtraPriceInfo\\Admin\\SettingsPage' => __DIR__ . '/../..' . '/src/Admin/SettingsPage.php', 29 'Darven\\ExtraPriceInfo\\Admin\\SettingsRestController' => __DIR__ . '/../..' . '/src/Admin/SettingsRestController.php', 33 30 'Darven\\ExtraPriceInfo\\Compatibility\\LegacyProductSettingsAdapter' => __DIR__ . '/../..' . '/src/Compatibility/LegacyProductSettingsAdapter.php', 34 31 'Darven\\ExtraPriceInfo\\Compatibility\\LegacySettingsAdapter' => __DIR__ . '/../..' . '/src/Compatibility/LegacySettingsAdapter.php', … … 38 35 'Darven\\ExtraPriceInfo\\Repositories\\ProductSettingsRepository' => __DIR__ . '/../..' . '/src/Repositories/ProductSettingsRepository.php', 39 36 'Darven\\ExtraPriceInfo\\Repositories\\SettingsRepository' => __DIR__ . '/../..' . '/src/Repositories/SettingsRepository.php', 37 'Darven\\ExtraPriceInfo\\Repositories\\SettingsSanitizer' => __DIR__ . '/../..' . '/src/Repositories/SettingsSanitizer.php', 40 38 'Darven\\ExtraPriceInfo\\Services\\CashPriceFormatter' => __DIR__ . '/../..' . '/src/Services/CashPriceFormatter.php', 41 39 'Darven\\ExtraPriceInfo\\Services\\FinalPriceFormatter' => __DIR__ . '/../..' . '/src/Services/FinalPriceFormatter.php', … … 51 49 { 52 50 return \Closure::bind(function () use ($loader) { 53 $loader->prefixLengthsPsr4 = ComposerStaticInit 20e0eb45e47b4ba6e645250a31f9ffef::$prefixLengthsPsr4;54 $loader->prefixDirsPsr4 = ComposerStaticInit 20e0eb45e47b4ba6e645250a31f9ffef::$prefixDirsPsr4;55 $loader->classMap = ComposerStaticInit 20e0eb45e47b4ba6e645250a31f9ffef::$classMap;51 $loader->prefixLengthsPsr4 = ComposerStaticInitdb32075ee5d847d9dbbfd29562c8f5c8::$prefixLengthsPsr4; 52 $loader->prefixDirsPsr4 = ComposerStaticInitdb32075ee5d847d9dbbfd29562c8f5c8::$prefixDirsPsr4; 53 $loader->classMap = ComposerStaticInitdb32075ee5d847d9dbbfd29562c8f5c8::$classMap; 56 54 57 55 }, null, ClassLoader::class); -
darven-multiplos-precos-informativos/tags/4.0.0/vendor/composer/platform_check.php
r3627068 r3667117 5 5 $issues = array(); 6 6 7 if (!(PHP_VERSION_ID >= 70400)) {8 $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';7 if (!(PHP_VERSION_ID >= 80000)) { 8 $issues[] = 'Your Composer dependencies require a PHP version ">= 8.0.0". You are running ' . PHP_VERSION . '.'; 9 9 } 10 10
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)