Skip to content

Commit

Permalink
Merge pull request #172 from melhorenvio/fix/SMS-1935-price-product-c…
Browse files Browse the repository at this point in the history
…ombo

fix: solve problem price on combo products
  • Loading branch information
Vinícius Schlee Tessmann authored May 29, 2023
2 parents 211c243 + 04a134c commit 4c34d6d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Models/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

class Version {

const VERSION = '2.11.34';
const VERSION = '2.11.35';
}
2 changes: 2 additions & 0 deletions Services/CompositeProductBundleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CompositeProductBundleService {

const PRODUCT_COMPOSITE = 'WC_Product_Composite';

const PRODUCT_COMBO_OFFICER = 'WC_Product_Wooco';

const PRODUCT_COMPOSITE_SHIPPING_FEE = 'wooco_shipping_fee';

const PRODUCT_COMPOSITE_PRICING = 'wooco_pricing';
Expand Down
23 changes: 19 additions & 4 deletions Services/OrdersProductsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public function getProductsOrder( $orderId ) {
}

$product = $itemProduct->get_product();
if ( is_bool( $product ) || get_class( $product ) === CompositeProductBundleService::PRODUCT_COMPOSITE ) {
if ($this->isComboProduct($product)) {
$compositeBundleService = new CompositeProductBundleService( $itemProduct );
$productComposite = $compositeBundleService->getProductNormalize();

$productComposite = $compositeBundleService->getProductNormalize();
if ( empty( $productComposite ) ) {
continue;
}
Expand All @@ -81,7 +80,16 @@ public function getProductsOrder( $orderId ) {
$itemProduct->get_quantity()
);

$price = (float) $itemProduct->get_data()['total'] / $itemProduct->get_data()['quantity'];
$quantityInsiderItem = 1;
if (isset($itemProduct->get_data()['quantity'])) {
$quantityInsiderItem = $itemProduct->get_data()['quantity'];
}

$price = (float) $itemProduct->get_data()['total'] / $quantityInsiderItem;
if ($price == 0) {
continue;
}

$products[$productId]->insurance_value = $price;
$products[$productId]->unitary_value = $price;
$quantities = $this->incrementQuantity(
Expand All @@ -108,6 +116,13 @@ public function getProductsOrder( $orderId ) {
return $products;
}

public function isComboProduct($product)
{
return is_bool($product) ||
get_class($product) === CompositeProductBundleService::PRODUCT_COMPOSITE ||
get_class($product) === CompositeProductBundleService::PRODUCT_COMBO_OFFICER;
}

/**
* @param int $productId
* @param array $quantities
Expand Down
2 changes: 1 addition & 1 deletion melhor-envio-beta.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Melhor Envio
Plugin URI: https://melhorenvio.com.br
Description: Plugin para cotação e compra de fretes utilizando a API da Melhor Envio.
Version: 2.11.34
Version: 2.11.35
Author: Melhor Envio
Author URI: melhorenvio.com.br
License: GPL2
Expand Down
7 changes: 5 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Melhor Envio ===
Version: 2.11.34
Version: 2.11.35
Tags: frete, fretes, cotação, cotações, correios, envio, jadlog, latam latam cargo, azul, azul cargo express, melhor envio
Requires at least: 4.7
Tested up to: 6.0
Stable tag: 2.11.34
Stable tag: 2.11.35
Requires PHP: 7.2+
Requires Wordpress 4.0+
Requires WooCommerce 4.0+
Expand Down Expand Up @@ -64,6 +64,9 @@ Observação: Atenção com as medidas de unidades utilizadas, cuidado se você
Pronto! o plugin do Melhor Envio está funcionando.

== Changelog ==
= 2.11.35 =
* Correção para aplicar o valor do produto para produtos combos.

= 2.11.34 =
* Correção para utilizar o valor do produto com cupom de desconto aplicado no campo de valor segurado.

Expand Down

0 comments on commit 4c34d6d

Please sign in to comment.