Jump to content

Edit History

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversionRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost/1.1;  // Impuesto 10%

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());
        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        if (!$cart->isVirtualCart()) {
            $shippingCost = $cart->getTotalShippingCost(null, $this->includeTaxes());
        } else {
            $shippingCost = 0;
        }
        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        $this->importCostFees = new AmountImmutable(                  // Se agrega esta línea
            $cart->getTotalImportCost(true),                          // Se agrega esta línea
            $cart->getTotalImportCost(false)                          // Se agrega esta línea
        );                                                            // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversionRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());
        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        if (!$cart->isVirtualCart()) {
            $shippingCost = $cart->getTotalShippingCost(null, $this->includeTaxes());
        } else {
            $shippingCost = 0;
        }
        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        $this->importCostFees = new AmountImmutable(                  // Se agrega esta línea
            $cart->getTotalImportCost(true),                          // Se agrega esta línea
            $cart->getTotalImportCost(false)                          // Se agrega esta línea
        );                                                            // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversionRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());
        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        if (!$cart->isVirtualCart()) {
            $shippingCost = $cart->getTotalShippingCost(null, $this->includeTaxes());
        } else {
            $shippingCost = 0;
        }
        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());
        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        if (!$cart->isVirtualCart()) {
            $shippingCost = $cart->getTotalShippingCost(null, $this->includeTaxes());
        } else {
            $shippingCost = 0;
        }
        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        if (!$cart->isVirtualCart()) {
            $shippingCost = $cart->getTotalShippingCost(null, $this->includeTaxes());
        } else {
            $shippingCost = 0;
        }
        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion al debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\(nombre_del_tema)\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion al debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() <= 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\theme_benito1\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion al debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() < 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\theme_benito1\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                      // Se agrega esta línea
                $cart->getTotalImportCost(false)                      // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion al debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() < 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\theme_benito1\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(true),                // Se agrega esta línea
                $cart->getTotalImportCost(false)                // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

gjferrando

gjferrando


Aquí voy resumiendo los cambios que hice
Deben tener en cuenta que muchos de los cambios hechos más arriba los fui descartando

-----------------------------------------------------------------------------------------------------------------

\classes\Cart.php (esto no está terminado pero sirve)

Se agrega esta funcion al debajo de:
public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null)
{

}

public function getTotalImportCost($use_tax = true)
    {
        if ($this->getTotalWeight() > 0 && $this->getTotalWeight() < 0.2)
        {
            $totalweight = 0.2; // Peso mínimo
        }
        else
        {
            $totalweight = $this->getTotalWeight();
        }

        $importCost = $totalweight * (21.5 * Context::getContext()->currency->getConversationRate());  // USD 21.5 costo en dólares americanos (moneda principal)

        $_total_importcost['with_tax'] = $importCost;
        $_total_importcost['without_tax'] = $importCost;

        return ($use_tax) ? $_total_importcost['with_tax'] : $_total_importcost['without_tax'];
    }

 

\themes\theme_benito1\modules\ps_shoppingcart\modal.tpl

<p><strong>{l s='Total products:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.products.value}</p>
<p><strong>{l s='Total import:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.import_cost.value}</p> {** Se agrega esta línea *}
<p><strong>{l s='Total shipping:' d='Shop.Theme.Checkout'}</strong>&nbsp;{$cart.subtotals.shipping.value} {hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}</p>

 

\src\Adapter\Presenter\Cart\CartPresenter.php
Se agrega:

        $importCost = $cart->getTotalImportCost($this->includeTaxes());

        if ($importCost > 0)
        {
            $subtotals['import_cost'] = [
                'type' => 'import_cost',
                'label' => $this->translator->trans('Import Cost', [], 'Shop.Theme.Checkout'),
                'amount' => $importCost,
                'value' => $this->priceFormatter->format($importCost),
            ];
        }

Antes de:

        $subtotals['shipping'] = [
            'type' => 'shipping',
            'label' => $this->translator->trans('Shipping', [], 'Shop.Theme.Checkout'),
            'amount' => $shippingCost,
            'value' => $this->getShippingDisplayValue($cart, $shippingCost),
        ];

 

\src\Core\Cart\Calculator.php
Se reemplaza:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

Por:

public function getTotal($ignoreProcessedFlag = false)
    {
        if (!$this->isProcessed && !$ignoreProcessedFlag) {
            throw new \Exception('Cart must be processed before getting its total');
        }

        $amount = $this->getRowTotalWithoutDiscount();
        $amount = $amount->sub($this->rounded($this->getDiscountTotal(), $this->computePrecision));
        $importCostFees = $this->fees->getInitialImportCostFees();                                     // Se agrega
        if (null !== $importCostFees) {                                                                // Se agrega
            $amount = $amount->add($this->rounded($importCostFees, $this->computePrecision));          // Se agrega
        }                                                                                              // Se agrega
        $shippingFees = $this->fees->getInitialShippingFees();
        if (null !== $shippingFees) {
            $amount = $amount->add($this->rounded($shippingFees, $this->computePrecision));
        }
        $wrappingFees = $this->fees->getFinalWrappingFees();
        if (null !== $wrappingFees) {
            $amount = $amount->add($this->rounded($wrappingFees, $this->computePrecision));
        }

        return $amount;
    }

 

\src\Core\Cart\Fees.php
Se agrega:

class Fees
{
    /**
     * @var AmountImmutable
     */
    protected $importCostFees;

    /**
     * @var AmountImmutable
     */
    protected $finalImportCostFees;

 

    public function __construct(?int $orderId = null)
    {
        $this->importCostFees = new AmountImmutable(); // Se agrega esta línea
        $this->shippingFees = new AmountImmutable();
        $this->orderId = $orderId;
    }

 

    /**
     * @param Cart $cart
     * @param CartRowCollection $cartRowCollection
     * @param int $computePrecision
     * @param int $id_carrier
     */
    public function processCalculation(
        Cart $cart,
        CartRowCollection $cartRowCollection,
        $computePrecision,
        $id_carrier = null
    ) {
        if ($id_carrier === null) {                                   // Se agrega esta línea
            $this->importCostFees = new AmountImmutable(              // Se agrega esta línea
                $cart->getTotalImportCost(null, true),                // Se agrega esta línea
                $cart->getTotalImportCost(null, false)                // Se agrega esta línea
            );                                                        // Se agrega esta línea
        }                                                             // Se agrega esta línea
        $this->finalImportCostFees = clone $this->importCostFees;     // Se agrega esta línea

        if ($id_carrier === null) {
            $this->shippingFees = new AmountImmutable(
                $cart->getTotalShippingCost(null, true),
                $cart->getTotalShippingCost(null, false)
            );
        } else {

 

×
×
  • Create New...