Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Cnc/Payments/Preference/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Payments/Preference/Helper/InitialFee.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Cnc
 * Radosław Stępień <[email protected]> <[email protected]>
 */
namespace Cnc\Payments\Preference\Helper;

use StripeIntegration\Payments\Helper\InitialFee as BaseInitialFee;

class InitialFee extends BaseInitialFee
{
    protected $paymentsHelper;
    protected $subscriptionsHelperFactory;

    public function __construct(
        \StripeIntegration\Payments\Helper\Generic $paymentsHelper,
        \StripeIntegration\Payments\Helper\SubscriptionsFactory $subscriptionsHelperFactory
    ) {
        $this->paymentsHelper = $paymentsHelper;
        $this->subscriptionsHelperFactory = $subscriptionsHelperFactory;
    }

    /**
     * @override due to correctly display historical orders imported from oscommerce
     *
     * @param $items
     * @param $rate
     * @param bool $skipConfigurables
     * @return float|int
     */
    public function getInitialFeeForItems($items, $rate, $skipConfigurables = true)
    {
        $total = 0;

        foreach ($items as $item) {
            // We skip the children of configurable products which are duplicates
            if ($skipConfigurables && $item->getParentItem()) {
                continue;
            }

            $qty = $this->getItemQty($item);

            // We include the configurable products children
            if ($item->getQtyOptions()) {
                foreach ($item->getQtyOptions() as $id => $option) {
                    $total += $this->getInitialFeeForProductId($id, $rate, $qty);
                }
            } elseif ($item->getProductId()) {
                // KDC modification here: retrieve product by sku for oscom historical orders
                $total += $this->getInitialFeeForProductId($item->getProductId(), $rate, $qty);
            } elseif ($item->getSku()) { //Fallback
                $total += $this->getInitialFeeForProductSku($item->getSku(), $rate, $qty);
            }
            // KDC modification end
        }

        return $total;
    }

    /**
     * @param $productSku
     * @param $rate
     * @param $qty
     * @return float|int
     */
    public function getInitialFeeForProductSku($productSku, $rate, $qty)
    {
        try {
            $product = $this->paymentsHelper->loadProductBySku($productSku);
        } catch (\Exception $exception) {
            return 0;
        }

        if (!is_numeric($product->getStripeSubInitialFee())) {
            return 0;
        }

        return round($product->getStripeSubInitialFee() * $rate, 2) * $qty;
    }

    /**
     * @param $item
     * @return mixed
     */
    protected function getItemQty($item)
    {
        $qty = $item->getQtyOrdered(); // Viewing orders in admin

        if (empty($qty)) {
            $qty = $item->getQty(); // Checkout
        }

        return $qty;
    }
}

Spamworldpro Mini