Changeset 2578312
- Timestamp:
- 08/04/2021 06:38:40 PM (4 years ago)
- Location:
- appmax-woocommerce
- Files:
-
- 2 added
- 7 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
assets/icon-128x128.png (modified) (previous)
-
assets/icon-256x256.png (modified) (previous)
-
trunk/appmax-woocommerce.php (modified) (3 diffs)
-
trunk/includes/class-awc-api.php (modified) (7 diffs)
-
trunk/includes/class-awc-interest.php (added)
-
trunk/includes/class-awc-tax.php (added)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
appmax-woocommerce/trunk/appmax-woocommerce.php
r2552677 r2578312 3 3 * Plugin Name: AppMax WooCommerce 4 4 * Description: Gateway de pagamento AppMax para WooCommerce. 5 * Version: 2.0.4 05 * Version: 2.0.41 6 6 * License: GPLv2 or later 7 7 * Author: AppMax Plataforma de Vendas Ltda … … 24 24 class AppMax_WC 25 25 { 26 const VERSION = '2.0.4 0';26 const VERSION = '2.0.41'; 27 27 28 28 /** … … 179 179 include_once AWC_ABSPATH . '/includes/class-awc-gateway-credit-card.php'; 180 180 include_once AWC_ABSPATH . '/includes/class-awc-helper.php'; 181 include_once AWC_ABSPATH . '/includes/class-awc-interest.php'; 181 182 include_once AWC_ABSPATH . '/includes/class-awc-post-payment.php'; 182 183 include_once AWC_ABSPATH . '/includes/class-awc-process-payment.php'; 183 184 include_once AWC_ABSPATH . '/includes/class-awc-search-gateway.php'; 185 include_once AWC_ABSPATH . '/includes/class-awc-tax.php'; 186 include_once AWC_ABSPATH . '/includes/class-awc-tracking-code.php'; 184 187 include_once AWC_ABSPATH . '/includes/class-awc-validation.php'; 185 188 include_once AWC_ABSPATH . '/includes/class-awc-webhook.php'; 186 189 include_once AWC_ABSPATH . '/includes/class-awc-webhook-post.php'; 187 include_once AWC_ABSPATH . '/includes/class-awc-tracking-code.php';188 190 } 189 191 -
appmax-woocommerce/trunk/includes/class-awc-api.php
r2552677 r2578312 115 115 * @param $interest_total 116 116 * @return array|WP_Error 117 * @throws Exception 117 118 */ 118 119 public function awc_post_order( $customer_id, $interest_total ) … … 207 208 return array( 208 209 'Content-Type' => 'application/json; charset=utf-8', 209 'access-token' => $this->gateway->awc_api_key 210 'access-token' => $this->gateway->awc_api_key, 210 211 ); 211 212 } … … 249 250 $array_products = []; 250 251 251 foreach ($items as $ item => $values) {252 foreach ($items as $values) { 252 253 array_push( $array_products, $this->awc_get_current_product( $values ) ); 253 254 } 254 255 255 $array_products = $this->awc_distribute_interest( $array_products, $interest );256 $array_products = (new AWC_Interest())->awc_distribute_interest( $array_products, $interest ); 256 257 257 258 $tax_total = (float) AWC_Helper::awc_get_fee_total(); … … 261 262 } 262 263 263 return $this->awc_distribute_tax( $array_products, $interest ); 264 } 265 266 private function awc_distribute_interest( $products, $interest ) 267 { 268 $distribute_interest = (float) round(($interest / count($products)), 3); 269 270 return array_map(function($item) use ($distribute_interest) { 271 $price = $item['price'] + ($distribute_interest / $item['qty']); 272 $item['price'] = round($price, 3); 273 return $item; 274 }, $products); 275 } 276 277 private function awc_distribute_tax( $products, $interest ) 278 { 279 $tax_total = (float) AWC_Helper::awc_get_fee_total(); 280 281 $distribute_tax = round(($tax_total / count($products)), 3); 282 283 $new_products = array_map(function($item) use ($distribute_tax) { 284 $price = $item['price'] + ($distribute_tax / $item['qty']); 285 $item['price'] = round($price, 3); 286 return $item; 287 }, $products); 288 289 $total_sum_products = $this->awc_get_total_sum_products( $new_products ); 290 291 $discount = (float) number_format( AWC_Helper::awc_get_discount_total(), 2, '.', ',' ); 292 293 $total_cart = (float) AWC_Helper::awc_get_total_cart(); 294 295 $difference = (float) round((($total_sum_products - $discount - $interest) - $total_cart), 2); 296 297 if ($difference == 0.00) { 298 return $new_products; 299 } 300 301 uasort($new_products, function($a, $b) { 302 if ($a['price'] == $b['price']) { 303 return 0; 304 } 305 return ($a['price'] < $b['price']) ? 1 : -1; 306 }); 307 308 $new_products = array_values($new_products); 309 310 foreach ($new_products as $key => $product) { 311 if ($product['qty'] == 1) { 312 $new_products[$key]['price'] -= $difference; 313 break; 314 } 315 if ($product['qty'] > 1) { 316 $new_products[$key]['price'] -= $difference / $product['qty']; 317 break; 318 } 319 } 320 321 return $new_products; 322 } 323 324 private function awc_get_total_sum_products( $products ) 325 { 326 return array_reduce($products, function($total, $item) { 327 $total += (float) ($item['price'] * $item['qty']); 328 return $total; 329 }); 264 return (new AWC_Tax())->awc_distribute_tax( $array_products, $interest ); 265 } 266 267 /** 268 * @param $values 269 * @return array 270 * @throws Exception 271 */ 272 private function awc_get_current_product( $values ) 273 { 274 $product = wc_get_product( $values['product_id'] ); 275 276 if ( ! $product->get_sku() ) { 277 throw new \Exception( "Produto do carrinho {$product->get_title()} não possui SKU registrado." ); 278 } 279 280 if ( empty( $values['variation_id'] ) && count( $values['variation'] ) == 0 ) { 281 return $this->awc_get_information_product( $product, $values ); 282 } 283 284 return $this->awc_get_information_product_variation( $product->get_sku(), $values ); 285 } 286 287 /** 288 * @param WC_Product $product 289 * @param $values 290 * @return array 291 */ 292 private function awc_get_information_product( WC_Product $product, $values ) 293 { 294 $price = (float) $product->get_price(); 295 296 if ( ! empty( $values['rn_entry'] ) ) { 297 $totals = $values['rn_entry']->Totals; 298 299 $price = (float) $product->get_price() + $totals->OptionsTotal; 300 } 301 302 return [ 303 "sku" => $product->get_sku(), 304 "price" => $price, 305 "name" => $product->get_title(), 306 "qty" => $values['quantity'], 307 "description" => $product->get_description(), 308 "image" => get_the_post_thumbnail_url( $values['product_id'] ), 309 ]; 330 310 } 331 311 … … 339 319 $variation = wc_get_product( $values['variation_id'] ); 340 320 321 $price = (float) $variation->get_price(); 322 323 if ( ! empty( $values['rn_entry'] ) ) { 324 $totals = $values['rn_entry']->Totals; 325 326 $price = (float) $variation->get_price() + $totals->OptionsTotal; 327 } 328 341 329 return [ 342 330 "sku" => "{$skuParentProduct}__{$variation->get_sku()}", 343 "price" => (float) $variation->get_price(),331 "price" => $price, 344 332 "name" => $variation->get_name(), 345 333 "qty" => $values['quantity'], … … 350 338 351 339 /** 352 * @param WC_Product $product353 * @param $values354 * @return array355 */356 private function awc_get_information_product( WC_Product $product, $values )357 {358 return [359 "sku" => $product->get_sku(),360 "price" => (float) $product->get_price(),361 "name" => $product->get_title(),362 "qty" => $values['quantity'],363 "description" => $product->get_description(),364 "image" => get_the_post_thumbnail_url( $values['product_id'] ),365 ];366 }367 368 /**369 * @param $values370 * @return array371 * @throws Exception372 */373 private function awc_get_current_product( $values )374 {375 $product = wc_get_product( $values['product_id'] );376 377 if ( ! $product->get_sku() ) {378 throw new \Exception( "Produto do carrinho {$product->get_title()} não possui SKU registrado." );379 }380 381 if ( empty( $values['variation_id'] ) && count( $values['variation'] ) == 0 ) {382 return $this->awc_get_information_product( $product, $values );383 }384 385 return $this->awc_get_information_product_variation( $product->get_sku(), $values );386 387 }388 389 /**390 340 * @param $order_id 391 341 * @param $tracking_code … … 398 348 return $this->awc_post( $this->awc_get_full_url( AWC_Suffix_Api::AWS_SUFFIX_TRACKING_CODE ), $data ); 399 349 } 400 401 350 402 351 /** -
appmax-woocommerce/trunk/readme.txt
r2552677 r2578312 4 4 Requires at least: 4.0 5 5 Tested up to: 5.1 6 Stable tag: 2.0.4 06 Stable tag: 2.0.41 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 117 117 == Changelog == 118 118 119 = 2.0.41 = 120 121 * Permitido envio de valores personalizados ao produto através da extensão do Woocommerce Extra Product Options Builder for WooCommerce. 122 119 123 = 2.0.40 = 120 124
Note: See TracChangeset
for help on using the changeset viewer.