View Single Post
  #1  
Old 09-09-2018, 02:11 PM
 
Daisy Daisy is offline
 

Advanced Member
  
Join Date: Aug 2010
Posts: 40
 

Question Showing some calculation at checkout

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
Attached Thumbnails
Click image for larger version

Name:	screenshot 1.png
Views:	438
Size:	11.0 KB
ID:	5226  Click image for larger version

Name:	screenshot 2.png
Views:	438
Size:	11.8 KB
ID:	5227  
__________________
X-Cart Business 5.4.1.35
Reply With Quote