Changeset 3317070
- Timestamp:
- 06/24/2025 02:38:48 PM (10 months ago)
- Location:
- bosta-woocommerce
- Files:
-
- 25 added
- 2 edited
-
tags/4.0.3 (added)
-
tags/4.0.3/Css (added)
-
tags/4.0.3/Css/main.css (added)
-
tags/4.0.3/assets (added)
-
tags/4.0.3/assets/images (added)
-
tags/4.0.3/assets/images/bosta.svg (added)
-
tags/4.0.3/assets/images/refresh.png (added)
-
tags/4.0.3/assets/images/refreshIcon.png (added)
-
tags/4.0.3/bosta-woocommerce.php (added)
-
tags/4.0.3/components (added)
-
tags/4.0.3/components/pickups (added)
-
tags/4.0.3/components/pickups/pickups.css (added)
-
tags/4.0.3/components/pickups/pickups.php (added)
-
tags/4.0.3/components/settings (added)
-
tags/4.0.3/components/settings/flexship (added)
-
tags/4.0.3/components/settings/flexship/flexship.css (added)
-
tags/4.0.3/components/settings/flexship/flexship.html (added)
-
tags/4.0.3/components/settings/flexship/flexship.js (added)
-
tags/4.0.3/readme.txt (added)
-
tags/4.0.3/uninstall.php (added)
-
trunk/bosta-woocommerce.php (modified) (12 diffs)
-
trunk/components/settings (added)
-
trunk/components/settings/flexship (added)
-
trunk/components/settings/flexship/flexship.css (added)
-
trunk/components/settings/flexship/flexship.html (added)
-
trunk/components/settings/flexship/flexship.js (added)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bosta-woocommerce/trunk/bosta-woocommerce.php
r3262320 r3317070 6 6 * Author: Bosta 7 7 * Author URI: https://www.bosta.co/ 8 * Version: 4.0. 18 * Version: 4.0.3 9 9 * Requires at least: 5.0 10 10 * php version 7.0 … … 33 33 $main_css_file = plugin_dir_path(__FILE__) . 'Css/main.css'; 34 34 $pickups_css_file = plugin_dir_path(__FILE__) . 'components/pickups/pickups.css'; 35 $flexship_css_file = plugin_dir_path(__FILE__) . 'components/settings/flexship/flexship.css'; 35 36 36 37 $main_css_version = filemtime($main_css_file); 37 38 $pickups_css_version = filemtime($pickups_css_file); 38 39 $flexship_css_version = filemtime($flexship_css_file); 39 40 40 41 wp_enqueue_style( … … 50 51 $pickups_css_version 51 52 ); 53 wp_enqueue_style( 54 'flexshipCSS', 55 plugins_url('components/settings/flexship/flexship.css', __FILE__), 56 array(), 57 $flexship_css_version 58 ); 52 59 } 53 60 54 61 const BOSTA_ENV_URL_V0 = 'https://app.bosta.co/api/v0'; 55 62 const BOSTA_ENV_URL_V2 = 'https://app.bosta.co/api/v2'; 56 const PLUGIN_VERSION = '4.0. 1';63 const PLUGIN_VERSION = '4.0.3'; 57 64 const bosta_cache_duration = 86400; 58 65 const bosta_country_id_duration = 604800; 59 66 const BOSTA_EGYPT_COUNTRY_ID = "60e4482c7cb7d4bc4849c4d5"; 60 67 const FLEX_SHIPPING_DEFAULT_VALUE = 75; 61 68 //region Bosta Utils Functions 62 69 … … 587 594 function bosta_render_error_notice($error_message) 588 595 { 589 echo '<div class="notice notice-error is-dismissible" >';596 echo '<div class="notice notice-error is-dismissible" style="padding: 10px;">'; 590 597 echo $error_message; 591 598 echo '</div>'; … … 811 818 812 819 if (!$response['success']) { 813 bosta_render_error_notice($response['error']); 820 $error_message = $response['error']? $response['error'] : $response['message']; 821 bosta_set_transient('bosta_errors', $error_message); 814 822 return; 815 823 } … … 998 1006 $product = $item->get_product(); 999 1007 $itemsCount += $item->get_quantity(); 1000 $descArray[] = bosta_format_order_description($productDescription, $ index, $product->get_sku(), $product->get_name(), $item->get_quantity());1008 $descArray[] = bosta_format_order_description($productDescription, $product->get_sku(), $product->get_name(), $item->get_quantity()); 1001 1009 $index++; 1002 1010 } … … 1009 1017 } 1010 1018 1011 function bosta_format_order_description($productDescription, $index, $sku, $name, $quantity) 1012 { 1013 $desc = "Product_$index: "; 1014 if ($productDescription === 'yes') $desc .= $name; 1015 if (!empty($sku)) $desc .= " [$sku]"; 1016 $desc .= " (" . $quantity . ")"; 1017 1019 function bosta_format_order_description($productDescription, $sku, $name, $quantity) 1020 { 1021 $desc = ""; 1022 if (is_array($productDescription)) { 1023 if (in_array('name', $productDescription)) { 1024 $desc .= $name; 1025 } 1026 if (in_array('sku', $productDescription) && !empty($sku)) { 1027 $desc .= " [$sku]"; 1028 } 1029 $desc .= " (" . $quantity . ")"; 1030 1031 } 1018 1032 return $desc; 1019 1033 } … … 1421 1435 $this->init_form_fields(); 1422 1436 $this->init_settings(); 1437 $this->auto_update_flex_ship_on_settings_page(); 1423 1438 add_action('woocommerce_update_options_shipping_' . $this->id, array( 1424 1439 $this, 1425 1440 'process_admin_options', 1426 1441 )); 1442 add_action('admin_footer', array($this, 'handle_flex_shipping_toggle')); 1443 } 1444 1445 private function is_bosta_shipping_settings_screen() { 1446 if (!is_admin()) { 1447 return false; 1448 } 1449 if (!isset($_GET['page'], $_GET['tab'], $_GET['section'])) { 1450 return false; 1451 } 1452 return $_GET['page'] === 'wc-settings' && $_GET['tab'] === 'shipping' && $_GET['section'] === 'bosta'; 1453 } 1454 1455 1456 function handle_flex_shipping_toggle() 1457 { 1458 if (!$this->is_bosta_shipping_settings_screen()) { 1459 return; 1460 } 1461 $settings_html_file = plugin_dir_path(__FILE__) . 'components/settings/flexship/flexship.html'; 1462 if (file_exists($settings_html_file)) { 1463 include $settings_html_file; 1464 } 1465 } 1466 1467 function auto_update_flex_ship_on_settings_page() 1468 { 1469 if ($this->is_bosta_shipping_settings_screen()) { 1470 $apiKey = $this->get_option('APIKey'); 1471 if (!empty($apiKey)) { 1472 $this->update_plugin_flex_ship_settings($apiKey); 1473 } 1474 } 1427 1475 } 1428 1476 … … 1435 1483 ), 1436 1484 'ProductDescription' => array( 1437 'label' => ' Display Woocomerce product descriptionin AWB',1485 'label' => 'Select product info to display in AWB', 1438 1486 'title' => __('Product description', 'bosta'), 1439 'type' => 'checkbox', 1440 'default' => 'yes', 1487 'type' => 'multiselect', 1488 'class' => 'wc-enhanced-select', 1489 'options' => array( 1490 'name' => __('Product Name', 'bosta'), 1491 'sku' => __('Product SKU', 'bosta'), 1492 ), 1493 'default' => array('name'), 1494 'description' => __('Select one or more product fields to display in the AWB.', 'bosta'), 1441 1495 ), 1442 1496 'AllowToOpenPackage' => array( … … 1445 1499 'type' => 'checkbox', 1446 1500 'default' => 'no', 1501 ), 1502 'EnableFlexShipping' => array( 1503 'label' => 'Enable FlexShip', 1504 'title' => __('Enable FlexShip', 'bosta'), 1505 'type' => 'checkbox', 1506 'default' => 'no', 1507 'description' => 'Charge your customer a service fee in case of package refusal to reduce your refund costs', 1508 ), 1509 'FlexShippingValue' => array( 1510 'type' => 'hidden', 1511 'default' => FLEX_SHIPPING_DEFAULT_VALUE, 1447 1512 ), 1448 1513 'OrderRef' => array( … … 1481 1546 public function process_admin_options() 1482 1547 { 1548 $oldAPIKey = $this->get_option('APIKey'); 1549 $oldFlexship = $this->get_option('EnableFlexShipping'); 1550 $oldFlexshipValue = $this->get_option('FlexShippingValue'); 1551 $oldProductDescription = $this->get_option('ProductDescription'); 1552 1553 $productDescription = isset($_POST['woocommerce_bosta_ProductDescription']) ? $_POST['woocommerce_bosta_ProductDescription'] : array(); 1554 if (empty($productDescription) || (is_array($productDescription) && count($productDescription) === 0)) { 1555 WC_Admin_Settings::add_error(__('Please select at least one product info field for AWB.', 'bosta')); 1556 $this->settings['ProductDescription'] = $oldProductDescription; 1557 return false; 1558 } 1559 1483 1560 $settings_saved = parent::process_admin_options(); 1484 1561 $this->bosta_check_reset_zoning_cache_toggle(); 1485 1562 1486 $apikey = $this->get_option('APIKey'); 1487 if (empty($apikey)) { 1563 $newAPIKey = $this->get_option('APIKey'); 1564 $newFlexship = $this->get_option('EnableFlexShipping'); 1565 $newFlexshipValue = $this->get_option('FlexShippingValue'); 1566 1567 if (empty($newAPIKey)) { 1488 1568 WC_Admin_Settings::add_error(__('Error: API Key is required.', 'bosta')); 1489 $settings_saved = false; 1490 } elseif (!bosta_validate_api_key($apikey)) { 1569 return false; 1570 } 1571 if (!bosta_validate_api_key($newAPIKey)) { 1491 1572 WC_Admin_Settings::add_error(__('Error: API Key is invalid.', 'bosta')); 1492 $settings_saved =false;1573 return false; 1493 1574 } 1494 1495 return $settings_saved; 1575 1576 if (!$settings_saved) { 1577 return false; 1578 } 1579 1580 if ($newAPIKey !== $oldAPIKey) { 1581 if ($newFlexship === 'yes') { 1582 $this->update_bosta_flex_ship_settings($newAPIKey, $newFlexship, $newFlexshipValue); 1583 } else { 1584 $this->update_plugin_flex_ship_settings($newAPIKey); 1585 } 1586 return true; 1587 } 1588 1589 if ($newFlexship !== $oldFlexship || $newFlexshipValue !== $oldFlexshipValue) { 1590 $this->update_bosta_flex_ship_settings($newAPIKey, $newFlexship, $newFlexshipValue); 1591 } 1592 1593 return true; 1594 } 1595 1596 private function update_plugin_flex_ship_settings($apikey) 1597 { 1598 $url = BOSTA_ENV_URL_V0 . '/businesses/' . esc_html($apikey) . '/info'; 1599 $response = bosta_send_api_request('GET', $url); 1600 1601 if ($response['success'] && isset($response['body']['flexShip'])) { 1602 $flexShip = $response['body']['flexShip']; 1603 $isSubscribed = !empty($flexShip['isSubscribed']); 1604 $isAppliedToAllOrders = !empty($flexShip['isAppliedToAllOrders']); 1605 if ($isSubscribed && $isAppliedToAllOrders) { 1606 $this->update_option('EnableFlexShipping', 'yes'); 1607 $this->update_option('FlexShippingValue', $flexShip['amountToBeCollected'] ?? FLEX_SHIPPING_DEFAULT_VALUE); 1608 $this->update_option('AllowToOpenPackage', 'yes'); 1609 } else { 1610 $this->update_option('EnableFlexShipping', 'no'); 1611 $this->update_option('FlexShippingValue', FLEX_SHIPPING_DEFAULT_VALUE); 1612 } 1613 } else { 1614 $this->update_option('EnableFlexShipping', 'no'); 1615 $this->update_option('FlexShippingValue', FLEX_SHIPPING_DEFAULT_VALUE); 1616 } 1617 } 1618 1619 private function update_bosta_flex_ship_settings($apikey, $flexship, $flexship_value) 1620 { 1621 $url = BOSTA_ENV_URL_V2 . '/businesses/flex-ship'; 1622 $body = [ 1623 'isSubscribed' => ($flexship === 'yes'), 1624 'amountToBeCollected' => intval($flexship_value), 1625 'isAppliedToAllOrders' => true 1626 ]; 1627 $response = bosta_send_api_request('PUT', $url, $apikey, $body); 1628 1629 if (!$response['success']) { 1630 $error_message = 'Failed to update FlexShip settings: ' . $response['error']; 1631 WC_Admin_Settings::add_error(__($error_message, 'bosta')); 1632 } else { 1633 $success_message = $flexship === 'yes' 1634 ? 'FlexShip service has been activated successfully.' 1635 : 'FlexShip service has been deactivated successfully.'; 1636 WC_Admin_Settings::add_message(__($success_message, 'bosta')); 1637 } 1496 1638 } 1497 1639 } … … 1535 1677 } 1536 1678 1679 add_action('admin_enqueue_scripts', function($hook) { 1680 if ($hook === 'woocommerce_page_wc-settings' && isset($_GET['section']) && $_GET['section'] === 'bosta') { 1681 wp_enqueue_script( 1682 'bosta-settings-js', 1683 plugins_url('components/settings/flexship/flexship.js', __FILE__), 1684 array('jquery'), 1685 filemtime(plugin_dir_path(__FILE__) . 'components/settings/flexship/flexship.js'), 1686 true 1687 ); 1688 } 1689 }); 1537 1690 //endregion 1538 1691 -
bosta-woocommerce/trunk/readme.txt
r3262320 r3317070 7 7 Requires PHP: 7.0 8 8 Tested up to: 6.6.1 9 Stable tag: 4.0. 19 Stable tag: 4.0.3 10 10 WC requires at least: 2.6 11 11 WC tested up to: 9.3.3 … … 206 206 = 4.0.1 = 207 207 * Send order items value 208 209 = 4.0.2 = 210 * Show notice error for blocked to order businesses 211 212 = 4.0.3 = 213 * Add FlexShip option to settings page
Note: See TracChangeset
for help on using the changeset viewer.