Changeset 3264847
- Timestamp:
- 04/01/2025 05:44:37 AM (12 months ago)
- Location:
- cdekdelivery/trunk
- Files:
-
- 1 added
- 7 edited
-
README.md (modified) (1 diff)
-
lang/cdekdelivery.pot (modified) (1 diff)
-
src/Actions/OrderCreateAction.php (modified) (3 diffs)
-
src/Model/Tax.php (added)
-
src/ShippingMethod.php (modified) (2 diffs)
-
src/UI/Admin.php (modified) (1 diff)
-
vendor/composer/autoload_classmap.php (modified) (1 diff)
-
vendor/composer/autoload_static.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cdekdelivery/trunk/README.md
r3262145 r3264847 76 76 * WP-159 Fix error for paid on delivery with zero price 77 77 * WP-156 Restore plugin settings on delivery zone page 78 * WP-158 Fix missing delivery invoice information on order page 78 * WP-158 Fixed missing delivery invoice information on order page 79 * WP-173 Fixed save plugin settings with WP cache plugins 80 * WP-160 Product tax settings now set in delivery invoice 81 * WP-183 Fixed errors or warnings on admin pages 79 82 80 83 = 4.0 = -
cdekdelivery/trunk/lang/cdekdelivery.pot
r3262118 r3264847 10 10 "X-Generator: GlotPress/4.0.1\n" 11 11 "Language: ru\n" 12 "Project-Id-Version: CDEKDelivery 4.1. 6"12 "Project-Id-Version: CDEKDelivery 4.1.7" 13 13 14 14 #. translators: 1: attempt number -
cdekdelivery/trunk/src/Actions/OrderCreateAction.php
r3262118 r3264847 29 29 use Cdek\Model\ShippingItem; 30 30 use Cdek\Model\Tariff; 31 use Cdek\Model\Tax; 31 32 use Cdek\Model\ValidationResult; 32 33 use Cdek\Note; … … 289 290 function_exists('wcml_get_woocommerce_currency_option') ? $this->order->currency : null; 290 291 291 return array_map(function (array $p) use ( &$shouldConvert, &$orderItems, &$shouldPay) {292 return array_map(function (array $p) use ($shouldConvert, $orderItems, $shouldPay) { 292 293 $weight = 0; 293 294 294 $items = array_values(array_filter(array_map(function ($item) use ( 295 &$shouldConvert, 296 &$shouldPay, 297 &$orderItems, 298 &$weight 299 ) { 300 if ($item instanceof WC_Order_Item_Product) { 301 $qty = (int)$item->get_quantity(); 302 } else { 303 $qty = (int)$item['qty']; 304 $item = $orderItems[$item['id']] ?? null; 305 } 306 307 if ($item === null) { 308 return null; 309 } 310 311 assert($item instanceof WC_Order_Item_Product); 312 $product = $item->get_product(); 313 314 $w = WeightConverter::getWeightInGrams($product->get_weight()); 315 $weight += $qty * $w; 316 $cost = $shouldConvert === null ? (float)$item->get_total() : $this->convertCurrencyToRub( 317 (float)$item->get_total(), 318 $shouldConvert, 319 ); 320 321 $cost /= $qty; 322 323 if ($shouldPay !== null) { 324 if ($shouldPay !== 0) { 325 $paymentValue = (int)(($shouldPay / 100) * $cost); 326 } else { 327 $paymentValue = $cost; 328 } 329 } else { 330 $paymentValue = 0; 331 } 332 333 return [ 334 'ware_key' => $product->get_sku() ?: $product->get_id(), 335 'payment' => ['value' => $paymentValue], 336 'name' => $item->get_name(), 337 'cost' => $cost, 338 'amount' => $qty, 339 'weight' => $w, 340 'weight_gross' => $w + 1, 341 ]; 342 }, $p['items'] ?: $orderItems))); 295 $items = array_values( 296 array_filter( 297 array_map( 298 static function($item) use ($shouldConvert, $shouldPay, $orderItems, &$weight){ 299 if ($item instanceof WC_Order_Item_Product) { 300 $qty = (int)$item->get_quantity(); 301 } else { 302 $qty = (int)$item['qty']; 303 $item = $orderItems[$item['id']] ?? null; 304 } 305 306 if ($item === null) { 307 return null; 308 } 309 310 assert($item instanceof WC_Order_Item_Product); 311 312 return $this->buildItemData($item, $qty, $shouldConvert, $shouldPay, $weight); 313 }, 314 $p['items'] ?: $orderItems 315 ) 316 ) 317 ); 343 318 344 319 $package = [ … … 359 334 } 360 335 336 private function buildItemData( 337 WC_Order_Item_Product $item, 338 int $qty, 339 ?string $shouldConvert, 340 ?int $shouldPay, 341 int &$weight 342 ): array 343 { 344 $product = $item->get_product(); 345 346 $w = WeightConverter::getWeightInGrams($product->get_weight()); 347 $weight += $qty * $w; 348 $cost = $shouldConvert === null ? (float)wc_get_price_including_tax($product) : 349 $this->convertCurrencyToRub( 350 (float)wc_get_price_including_tax($product), 351 $shouldConvert, 352 ); 353 354 $payment = ['value' => 0]; 355 356 if ($shouldPay !== null) { 357 if ($shouldPay !== 0) { 358 $payment['value'] = (int)(($shouldPay / 100) * $cost); 359 360 if($product->is_taxable()){ 361 $taxCost = $shouldConvert === null ? (float)$item->get_total_tax() : 362 $this->convertCurrencyToRub( 363 (float)$item->get_total_tax(), 364 $shouldConvert, 365 ); 366 367 if($taxCost > 0){ 368 $payment['vat_sum'] = (int)(($shouldPay / 100) * $taxCost); 369 $payment['vat_rate'] = Tax::getTax($product->get_tax_class()); 370 }else{ 371 $payment['vat_sum'] = 0; 372 $payment['vat_rate'] = 0; 373 } 374 } 375 } else { 376 $payment['value'] = $cost; 377 } 378 } 379 380 return [ 381 'ware_key' => $product->get_sku() ?: $product->get_id(), 382 'payment' => $payment, 383 'name' => $item->get_name(), 384 'cost' => $cost, 385 'amount' => $qty, 386 'weight' => $w, 387 'weight_gross' => $w + 1, 388 ]; 389 } 390 361 391 private function convertCurrencyToRub(float $cost, string $currency): float 362 392 { -
cdekdelivery/trunk/src/ShippingMethod.php
r3213294 r3264847 120 120 } 121 121 122 final public function init_instance_settings(): void { 123 parent::init_instance_settings(); 124 125 if (doing_action("woocommerce_update_options_shipping_$this->id")){ 126 $this->instance_settings['token'] = null; 127 } 128 } 129 130 final public function init_settings(): void { 131 parent::init_settings(); 132 133 if (doing_action("woocommerce_update_options_shipping_$this->id")){ 134 $this->settings['token'] = null; 135 } 136 } 137 122 138 /** @noinspection MissingReturnTypeInspection */ 123 139 public function __get(string $key) … … 216 232 } 217 233 } 218 219 final public function process_admin_options(): bool220 {221 FlushTokenCacheAction::new()();222 223 return parent::process_admin_options();224 }225 234 } 226 235 } -
cdekdelivery/trunk/src/UI/Admin.php
r3262118 r3264847 65 65 66 66 if ($current_section !== Config::DELIVERY_NAME) { 67 if (empty($_REQUEST['instance_id'])) { 68 return; 69 } 70 67 71 $shippingMethodCurrent = WC_Shipping_Zones::get_shipping_method(absint(wp_unslash($_REQUEST['instance_id']))); 68 72 -
cdekdelivery/trunk/vendor/composer/autoload_classmap.php
r3234614 r3264847 71 71 'Cdek\\Model\\Tariff' => $baseDir . '/src/Model/Tariff.php', 72 72 'Cdek\\Model\\TaskResult' => $baseDir . '/src/Model/TaskResult.php', 73 'Cdek\\Model\\Tax' => $baseDir . '/src/Model/Tax.php', 73 74 'Cdek\\Model\\ValidationResult' => $baseDir . '/src/Model/ValidationResult.php', 74 75 'Cdek\\Note' => $baseDir . '/src/Note.php', -
cdekdelivery/trunk/vendor/composer/autoload_static.php
r3234614 r3264847 152 152 'Cdek\\Model\\Tariff' => __DIR__ . '/../..' . '/src/Model/Tariff.php', 153 153 'Cdek\\Model\\TaskResult' => __DIR__ . '/../..' . '/src/Model/TaskResult.php', 154 'Cdek\\Model\\Tax' => __DIR__ . '/../..' . '/src/Model/Tax.php', 154 155 'Cdek\\Model\\ValidationResult' => __DIR__ . '/../..' . '/src/Model/ValidationResult.php', 155 156 'Cdek\\Note' => __DIR__ . '/../..' . '/src/Note.php',
Note: See TracChangeset
for help on using the changeset viewer.