Changeset 3833007
- Timestamp:
- 11/29/2026 12:37:54 PM (112 minutes ago)
- Location:
- grafo-for-woocommerce/trunk
- Files:
-
- 3 edited
-
grafo-for-woocommerce.php (modified) (4 diffs)
-
includes/class-grafo-mock-cart.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grafo-for-woocommerce/trunk/grafo-for-woocommerce.php
r3832987 r3833007 3 3 * Plugin Name: Grafo for WooCommerce 4 4 * Description: Creates WooCommerce orders and updates delivery addresses, with automatic shipping and fee calculation, from Grafo. 5 * Version: 1.1.1 75 * Version: 1.1.18 6 6 * Author: Grafo 7 7 * Author URI: https://www.grafoflow.com/ … … 87 87 add_action( 'woocommerce_loaded', 'grafo_load_mock_cart_class' ); 88 88 89 function grafo_mock_cart( $weight = 0, $subtotal = 0 )90 { 91 return new Grafo_Mock_Cart( $weight, $subtotal );89 function grafo_mock_cart( $weight = 0, $subtotal = 0, $contents = [] ) 90 { 91 return new Grafo_Mock_Cart( $weight, $subtotal, $contents ); 92 92 } 93 93 … … 99 99 $had_cart = !is_null(WC()->cart); 100 100 if (!$had_cart) { 101 WC()->cart = grafo_mock_cart($package['contents_weight'] ?? 0, $package['contents_cost'] ?? 0 );101 WC()->cart = grafo_mock_cart($package['contents_weight'] ?? 0, $package['contents_cost'] ?? 0, $package['contents'] ?? []); 102 102 } 103 103 … … 312 312 $had_cart = !is_null(WC()->cart); 313 313 if (!$had_cart) { 314 WC()->cart = grafo_mock_cart($total_weight, $pkg_cost );314 WC()->cart = grafo_mock_cart($total_weight, $pkg_cost, $pkg_items); 315 315 } 316 316 -
grafo-for-woocommerce/trunk/includes/class-grafo-mock-cart.php
r3832987 r3833007 19 19 class Grafo_Mock_Cart extends WC_Cart { 20 20 21 private $_gw, $_gs ;21 private $_gw, $_gs, $_contents; 22 22 public $_fees_api = []; 23 23 24 public function __construct( $w = 0, $s = 0 ) {24 public function __construct( $w = 0, $s = 0, $contents = [] ) { 25 25 $this->_gw = $w; 26 26 $this->_gs = $s; 27 /* $contents mirrors $package['contents']: already shaped like a real 28 * WC cart-contents array (each entry has 'data' => WC_Product, 29 * 'quantity', 'line_total', etc. — see grafo_create_order()). Some 30 * shipping plugins (WBS's PackageConverter, observed via its 31 * "rates=0, no exception" behavior once the cart/compound-param 32 * fatals were fixed) compute weight/price by walking 33 * get_cart_contents() directly rather than trusting 34 * get_cart_contents_weight()/get_subtotal(); an empty array here 35 * silently zeroes their calculation instead of throwing, which is 36 * why this was hard to spot from the logs alone. */ 37 $this->_contents = $contents; 27 38 // parent::__construct() intentionally skipped — hits DB/session. 28 39 } … … 40 51 * 1.1.17, being the first one actually hit). */ 41 52 public function get_cart_contents_weight( ...$args ) { return $this->_gw; } 42 public function get_cart_contents_count( ...$args ) { return 1; } 53 public function get_cart_contents_count( ...$args ) { 54 $count = 0; 55 foreach ( $this->_contents as $item ) { 56 $count += (int) ( $item['quantity'] ?? 1 ); 57 } 58 return $count ?: 1; 59 } 43 60 public function get_displayed_subtotal( ...$args ) { return $this->_gs; } 44 61 public function get_subtotal( ...$args ) { return $this->_gs; } 45 62 public function get_cart_subtotal( ...$args ) { return $this->_gs; } 46 public function get_cart_contents( ...$args ) { return []; }63 public function get_cart_contents( ...$args ) { return $this->_contents; } 47 64 public function is_empty( ...$args ) { return false; } 48 65 public function needs_shipping( ...$args ) { return true; } -
grafo-for-woocommerce/trunk/readme.txt
r3832987 r3833007 7 7 WC requires at least: 7.0 8 8 WC tested up to: 11.1 9 Stable tag: 1.1.1 79 Stable tag: 1.1.18 10 10 License: GPLv2 or later 11 11 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 67 67 == Changelog == 68 68 69 = 1.1.18 = 70 * Fix: 1.1.17 stopped the fatal and stopped WBS's exceptions, but it still silently returned no rate. Grafo_Mock_Cart::get_cart_contents() was hardcoded to return an empty array, so any shipping method (like WBS) that computes weight/price by walking the cart's actual line items, rather than trusting the pre-computed get_cart_contents_weight()/get_subtotal() totals, saw a cart with zero items and had nothing to match a weight-tier rule against - no error, just quietly zero rates. The mock cart now holds the real line items (the same product/quantity data already resolved for the order) and returns them from get_cart_contents(), with get_cart_contents_count() summing real quantities instead of hardcoding 1. 71 69 72 = 1.1.17 = 70 73 * Fix: the real cause of the fatal error reported on 1.1.15/1.1.16 - nothing to do with when/where the class was declared. Grafo_Mock_Cart::get_cart_subtotal() was declared with no parameters, but WC_Cart::get_cart_subtotal($compound = false) declares one; PHP fatals ("Declaration ... must be compatible with ...") the instant a class with an incompatible override is declared, regardless of timing. Every override in Grafo_Mock_Cart now accepts (...$args) instead of a hand-matched signature, which is unconditionally compatible with any parent signature made of optional parameters - closing off this entire category of mismatch instead of fixing one method at a time as each is discovered. … … 134 137 == Upgrade Notice == 135 138 139 = 1.1.18 = 140 Fixes shipping methods (e.g. WBS) that compute weight/price by walking the cart's line items directly - the mock cart returned an empty item list, so such a method silently found nothing to match and quoted no rate at all. 141 136 142 = 1.1.17 = 137 143 Fixes the actual fatal error from 1.1.15/1.1.16: a mismatched method signature on the mock cart class, not a class-loading timing issue. All its overrides are now signature-safe against any WC_Cart version.
Note:
See TracChangeset
for help on using the changeset viewer.