Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

WooCommerce template throws error #3

Closed
besrabasant opened this issue Aug 11, 2018 · 12 comments
Closed

WooCommerce template throws error #3

besrabasant opened this issue Aug 11, 2018 · 12 comments

Comments

@besrabasant
Copy link

I am not able to make the cart/cart.blade.php work.

it Throws error

( ! ) Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function startSection() on null in 
@MWDelaney
Copy link
Member

Can you show the content of your cart.blade.php here? It’s difficult to troubleshoot code we cannot see.

@besrabasant
Copy link
Author

It's kind of strange... But even if I keep just

@extends('layouts.app')

@section('content')
@endsection

in the template file... It throws an error.

The only thing that works is if I keep the template file empty.

@MWDelaney
Copy link
Member

Does it work if you use the full contents of the default PHP template from WooCommerce?

@besrabasant
Copy link
Author

No. It only works if I keep the template file empty.

@mejta
Copy link
Contributor

mejta commented Aug 13, 2018

@besrabasant

Hey, you should not use @extends and @section in this template. Have a look into the original template from WooCommerce plugin and if the original template doesn't contain get_header or get_footer function call, don't use @extends or @section in your template.

Also, those templates are called without context, so no $__env variable is available, so you have to define this variable in your template with $__env = App\sage('blade'). The code for the cart template should look like this:

@php
$__env = App\sage('blade');
wc_print_notices();
do_action( 'woocommerce_before_cart' );
@endphp

<form class="woocommerce-cart-form" action="{{ wc_get_cart_url() }}" method="post">
  @php
  do_action( 'woocommerce_before_cart_table' );
  @endphp

	<table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
		<thead>
			<tr>
				<th class="product-remove">&nbsp;</th>
				<th class="product-thumbnail">&nbsp;</th>
				<th class="product-name">{{ esc_html_e( 'Product', 'woocommerce' ) }}</th>
				<th class="product-price">{{ esc_html_e( 'Price', 'woocommerce' ) }}</th>
				<th class="product-quantity">{{ esc_html_e( 'Quantity', 'woocommerce' ) }}</th>
				<th class="product-subtotal">{{ esc_html_e( 'Total', 'woocommerce' ) }}</th>
			</tr>
		</thead>
		<tbody>
      @php
      do_action( 'woocommerce_before_cart_contents' );
      @endphp

      @php
      $items = WC()->cart->get_cart();
      @endphp

      @foreach($items as $cart_item)
        @php
				$_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $loop->index );
        $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $loop->index );
        @endphp

        ...

			@endforeach

      @php
      do_action( 'woocommerce_cart_contents' );
      @endphp

      ...

      @php
      do_action( 'woocommerce_after_cart_contents' );
      @endphp
		</tbody>
	</table>
  @php
  do_action( 'woocommerce_after_cart_table' );
  @endphp
</form>

<div class="cart-collaterals">
	@php
  do_action( 'woocommerce_cart_collaterals' );
	@endphp
</div>

@php
do_action( 'woocommerce_after_cart' );
@endphp

@mejta
Copy link
Contributor

mejta commented Aug 13, 2018

Ok, investigation done. If you append following code at the beginning of the .blade.php file, everything will work.

@php
$__env = App\sage('blade');
@endphp

@besrabasant
Copy link
Author

like every .blade.php or just the woocommerce templates.

@besrabasant
Copy link
Author

besrabasant commented Aug 13, 2018

Now it's working... Thanks
@mejta

just removing the item is not working

@mejta
Copy link
Contributor

mejta commented Aug 21, 2018

Bug is solved by #5

@mmirus mmirus closed this as completed Aug 21, 2018
@besrabasant besrabasant changed the title cart template throws error WooCommerce template throws error Aug 21, 2018
@arthurkirkosa
Copy link

arthurkirkosa commented Feb 8, 2019

I'm having the same problem with the latest version of this package and woo 3.5.4.
It's not throwing an error, but it's not loading any styles for that page

Is the @extends method fixed or it's still not recommended?

@mmirus
Copy link
Contributor

mmirus commented Feb 8, 2019

Hey @arthurkirkosa - can you provide more detail on what you're trying to do, e.g., what template you're editing?

AFAIK the correct approach is still what @mejta indicated above:

Have a look into the original template from WooCommerce plugin and if the original template doesn't contain get_header or get_footer function call, don't use @extends or @section in your template.

@arthurkirkosa
Copy link

With @mejta 's approach works.

Was wondering if that's the only way to do it. If so, I'm already doing it :)

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants