<commit_before><?php
/**
 * This file is part of the official Aplazame module for PrestaShop.
 *
 * @author    Aplazame <<EMAIL>>
 * @copyright 2015-2018 Aplazame
 * @license   see file: LICENSE
 */

/**
 * Order.
 */
class Aplazame_Aplazame_BusinessModel_Order
{
    public static function createFromCart(Cart $cart)
    {
        $currency = new Currency($cart->id_currency);

        $total_shipping = $cart->getTotalShippingCost();
        $total_shipping_tax_exc = $cart->getTotalShippingCost(null, false);
        $shipping_tax = $total_shipping - $total_shipping_tax_exc;

        $base_total_tax_inc = $cart->getOrderTotal(true);
        $base_total_tax_exc = $cart->getOrderTotal(false);
        $order_tax = $base_total_tax_inc - $base_total_tax_exc - $shipping_tax;

        $aOrder = new self();
        $aOrder->id = $cart->id;
        $aOrder->currency = $currency->iso_code;
        $aOrder->total_amount = Aplazame_Sdk_Serializer_Decimal::fromFloat($base_total_tax_inc);
        $aOrder->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(100 * $order_tax / $base_total_tax_exc);
        $aOrder->articles = array_map(function (array $productData) use ($cart) {
            return Aplazame_Aplazame_BusinessModel_Article::createFromProductData($cart, $productData);
        }, $cart->getProducts());
        $aOrder->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));

        return $aOrder;
    }
}<commit_msg>Fix discount if tax included.<commit_after><?php
/**
 * This file is part of the official Aplazame module for PrestaShop.
 *
 * @author    Aplazame <<EMAIL>>
 * @copyright 2015-2018 Aplazame
 * @license   see file: LICENSE
 */

/**
 * Order.
 */
class Aplazame_Aplazame_BusinessModel_Order
{
    public static function createFromCart(Cart $cart)
    {
        $currency = new Currency($cart->id_currency);

        $total_shipping = $cart->getTotalShippingCost();
        $total_shipping_tax_exc = $cart->getTotalShippingCost(null, false);
        $shipping_tax = $total_shipping - $total_shipping_tax_exc;

        $base_total_tax_inc = $cart->getOrderTotal(true);
        $base_total_tax_exc = $cart->getOrderTotal(false);
        $order_tax = $base_total_tax_inc - $base_total_tax_exc - $shipping_tax;

        $aOrder = new self();
        $aOrder->id = $cart->id;
        $aOrder->currency = $currency->iso_code;
        $aOrder->total_amount = Aplazame_Sdk_Serializer_Decimal::fromFloat($base_total_tax_inc);
        $aOrder->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(100 * $order_tax / $base_total_tax_exc);
        $aOrder->articles = array_map(function (array $productData) use ($cart) {
            return Aplazame_Aplazame_BusinessModel_Article::createFromProductData($cart, $productData);
        }, $cart->getProducts());
        $aOrder->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));

        return $aOrder;
    }
}
{'fraction_non_alphanumeric': 0.12487445597589555, 'fraction_numerical': 0.007365249414127887, 'mean_word_length': 3.8193548387096774, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665514', 'n_tokens_mistral': 1017, 'n_tokens_neox': 979, 'n_words': 158}