X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Showing some calculation at checkout (https://forum.x-cart.com/showthread.php?t=76518)

Daisy 09-09-2018 02:11 PM

Showing some calculation at checkout
 
2 Attachment(s)
Hi there,
can somebody help me, I'm pretty stuck here :-(


I tried to calculate processing time depending on items in cart and orders in status 'P' so I created a mod that extends cart class like this:


Code:

namespace XLite\Module\Dsy\ProcessingTime\View;

/**
 * Cart widget
 *
 */


abstract class Cart extends \XLite\View\Cart implements \XLite\Base\IDecorator
{

    /**
    * Returns Processing Time
    *
    * @return string
    */
    public function getProcessingTime()
    {
        $items = $this->getCart()->countQuantity();

        $time = ceil($items/5);

        $orders = \XLite\Core\Database::getRepo('XLite\Model\Order')
            ->createQueryBuilder('o')
            ->andWhere('o.shippingStatus  = :id')
            ->setParameter('id', '2')
            ->getResult();

        $openorders = count($orders);

        if ( $openorders > 0 )
        {
        $openorders = floor($openorders / 3);
        }
        $time = $time + $openorders;
       
        return $time;
    }
   
}



This works fine on cart page, where I added a twig like this:


theme_tweaker\customer\shopping_cart\parts\process ingtime.twig


Code:

{##
 # Shopping cart items block
 #
 # @ListChild (list="cart.children", weight="30")
 # @ListChild (list="checkout.cart", weight="30")
 #}
<div class="subtotal" style="text-align: right; padding-top: 45px;">
  <strong>{{ t('Expected delivery time in working days') }}: {{ this.getProcessingTime() }}</strong>
</div>



It shows up beneath subtotal, you can see in screenshot 1.


Then I wanted to add the same to FastLaneCheckout right beneath shipping methods so that customers can combine delivery time with processing time.


theme_tweaker\customer\modules\XC\FastLaneCheckout \sections\shipping\processingtime.twig


Code:

{##
 # Fastlane checkout processing time
 #
 # @ListChild (list="checkout_fastlane.sections.shipping.right", weight="20")
 #}

<div class="subtotal" style="text-align: right; padding-top: 45px;">
  <strong>{{ t('Expected delivery time in working days') }}: {{ this.cart.getProcessingTime() }}</strong>
</div>



I had to add .cart before getProcessingTime(), otherwise I got this error



Quote:

XLite [error] Trying to call undefined class method; class - "XLite\Controller\Customer\Checkout", function - "getProcessingTime"


But with this.cart.getProcessingTime() the error disappears and the page is shown correctly but the value of this.cart.getProcessingTime() is missing. (screenshot 2).


The function is there, but it won't return anything. I added var_dump at the beginning so I found out it won't even get called.


I'v been trying for hours and days. I tried different things: various listviews on that page, extending other classes like controller\customer\checkout and so on, but nothing. What am I missing?



I just learned about x-cart 5 file structure and twig templates, adding modules and redefining classes. I didn't read the whole developer manuals so I think it's just something real stupid that I did wrong. Do you have any suggestions?



Best regards,
Daisy

Daisy 09-12-2018 01:00 PM

Re: Showing some calculation at checkout
 
done... found the correct viewer class to use and solved error in redefinition :roll:


All times are GMT -8. The time now is 09:13 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.