Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

total_including_tax - Call to a member function raw() on int #1035

Closed
de-raaf-media opened this issue Mar 25, 2024 · 14 comments
Closed

total_including_tax - Call to a member function raw() on int #1035

de-raaf-media opened this issue Mar 25, 2024 · 14 comments

Comments

@de-raaf-media
Copy link

Description

In version 5 an object is passed. For some reason in version 6 an integer is passed.

Version 5 - entries table

This seems to be the correct way. An object is passed.

{
	"items": [
		{
			"id": "0b048878-f46f-434d-8341-27c8fb822d1d",
			"tax": {
				"rate": 21,
				"amount": 174,
				"price_includes_tax": true
			},
			"total": 826,
			"product": "00c83cb1-6089-4785-9479-b5032c6f1bc3",
			"variant": {
				"product": "00c83cb1-6089-4785-9479-b5032c6f1bc3",
				"variant": "default"
			},
			"metadata": [],
			"quantity": 1
		}
	],
	
}

Result:

Statamic\Fields\Value {#3460 ▼ // vendor/doublethreedigital/simple-commerce/src/Tags/TotalIncludingTax.php:13
  #raw: 826
  #handle: "total"
  #fieldtype: DoubleThreeDigital\SimpleCommerce\Fieldtypes\MoneyFieldtype {#3476 ▶}
  #augmentable: Statamic\Eloquent\Entries\Entry {[#2110 ▶](https://webshop2.tuindingen.test/cart#sf-dump-617803364-ref22110)}
  #shallow: false
}

Version 6 - Orders table

This seems incorrect. An integer is passed as total.

{
	"id": "70b0279c-3bee-4b62-827f-39cd1f72fe90",
	"tax": {
		"rate": 21,
		"amount": 174,
		"price_includes_tax": true
	},
	"total": 826,
	"product": "4d0c8f81-4ea4-4b03-b864-d1e6317440da",
	"variant": {
		"product": "4d0c8f81-4ea4-4b03-b864-d1e6317440da",
		"variant": "default"
	},
	"metadata": [],
	"quantity": 1
}

Result:

826 // vendor/doublethreedigital/simple-commerce/src/Tags/TotalIncludingTax.php:13

Output without {{ total_including_tax }}

If I leave out total_including_tax from antlers I get the following results.

for version 5

sc:cart:total - €15.00 - Returns the overall/grand total of the cart
sc:cart:grand_total - €15.00 - Does the same thing as sc:cart:total
sc:cart:items_total - €8.26 - Returns the total of all line items.
sc:cart:shipping_total - €5.00 - Returns the shipping total of the cart.
sc:cart:shipping_total_with_tax - €5.00 - Return the shipping total, inclusive of any tax.
sc:cart:tax_total - €1.74 - Returns the tax total of the cart.
sc:cart:tax_total_split - - Returns the tax total of the cart, split by tax rate.
sc:cart:coupon_total - €0.00 - Returns the total amount saved from coupons.
sc:cart:items_total_with_tax - €10.00 - Returns the total of all line items, inclusive of any tax.

for version 6

sc:cart:total - 1000 - Returns the overall/grand total of the cart
sc:cart:grand_total - 1000 - Does the same thing as sc:cart:total
sc:cart:items_total - 826 - Returns the total of all line items.
sc:cart:shipping_total - 0 - Returns the shipping total of the cart.
sc:cart:shipping_total_with_tax - €0.00 - Return the shipping total, inclusive of any tax.
sc:cart:tax_total - 174 - Returns the tax total of the cart.
sc:cart:tax_total_split - - Returns the tax total of the cart, split by tax rate.
sc:cart:coupon_total - 0 - Returns the total amount saved from coupons.
sc:cart:items_total_with_tax - €10.00 - Returns the total of all line items, inclusive of any tax.

Steps to reproduce

I created a separate branch to upgrade to version 6. There I switched orders from eloquent to database orders.

Environment

Environment
Application Name: Statamic
Laravel Version: 10.48.4
PHP Version: 8.2.16
Composer Version: 2.7.1
Environment: local
Debug Mode: ENABLED
URL: domain6.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Simple Commerce
Currencies: EUR
Gateways: Mollie
Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\UserCustomerRepository
Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EloquentOrderRepository
Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository
Shipping Methods: Free Shipping
Tax Engine: DuncanMcClean\SimpleCommerce\Tax\BasicTaxEngine

Statamic
Addons: 3
Antlers: runtime
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.54.0 PRO

Statamic Addons
doublethreedigital/simple-commerce: 6.0.10
statamic-rad-pack/runway: 6.6.1
statamic/eloquent-driver: 3.3.2

Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: file
Collections: file
Entries: eloquent
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Taxonomies: file
Terms: file

@duncanmcclean
Copy link
Owner

There I switched orders from eloquent to database orders.

I think this may be part of the reason you're running into this issue, since none of the totals you're showing for v6 are being augmented like they should be.

What does your resources/blueprints/vendor/runway/order.yaml file look like?

@de-raaf-media
Copy link
Author

This looks a bit empty. Did I miss a step?

tabs:
  main:
    fields: {  }

@duncanmcclean
Copy link
Owner

Can you try copying the contents of this file into there and let me know if it helps?

https://github.com/duncanmcclean/simple-commerce/blob/6.x/src/Console/Commands/stubs/runway_order_blueprint.yaml

It should be copying it over as part of the "move to database" process but something must have went weird.

@de-raaf-media
Copy link
Author

"Unsupported operand types: int + string"

seems to be hanging on map in this function:

public function rawTaxTotalSplit(): Collection

    {

        return collect($this->items())

            ->groupBy(function ($item) {

                return $item['tax']['rate'];

            })

            ->map(function ($group, $groupRate) {

                return [

                    'rate' => $groupRate,

                    'amount' => $group->sum(function ($item) {

                        return $item['tax']['amount'];

                    }),

                ];

            })

            ->values();

    }

@duncanmcclean
Copy link
Owner

Hmm, looks like something that should be a number isn't a number. Can you share the contents of the items column for your current order?

@de-raaf-media
Copy link
Author

de-raaf-media commented Mar 25, 2024

Sure, here you go:

[
	{
		"id": "18fb0585-3e23-45f1-abd9-a0b6848f17ba",
		"tax": {
			"rate": 21,
			"amount": 260,
			"price_includes_tax": true
		},
		"total": 1240,
		"product": "00c83cb1-6089-4785-9479-b5032c6f1bc3",
		"variant": {
			"product": "00c83cb1-6089-4785-9479-b5032c6f1bc3",
			"variant": "default"
		},
		"metadata": [],
		"quantity": 1
	}
]

@duncanmcclean
Copy link
Owner

That looks okay to me 🤔

"Unsupported operand types: int + string"

Are you able to provide the full stack trace for this error?

@de-raaf-media
Copy link
Author

de-raaf-media commented Mar 25, 2024

I just added a dd in RawTaxTotalSplit:

dd($item['tax']['amount']);

result: €2.60

If I convert the amount to int it works:

return intval($item['tax']['amount']);

The cart now shows correctly.

sc:cart:total - €25.00 - Returns the overall/grand total of the cart
sc:cart:grand_total - €25.00 - Does the same thing as sc:cart:total
sc:cart:items_total - €20.66 - Returns the total of all line items.
sc:cart:shipping_total - €0.00 - Returns the shipping total of the cart.
sc:cart:shipping_total_with_tax - €0.00 - Return the shipping total, inclusive of any tax.
sc:cart:tax_total - €4.34 - Returns the tax total of the cart.
sc:cart:tax_total_split - - Returns the tax total of the cart, split by tax rate.
sc:cart:coupon_total - €0.00 - Returns the total amount saved from coupons.
sc:cart:items_total_with_tax - €25.00 - Returns the total of all line items, inclusive of any tax.

@de-raaf-media
Copy link
Author

return intval($item['tax']['amount']) seems to do the trick. Do you need more info from me?

@duncanmcclean
Copy link
Owner

$item['tax']['amount'] should already be an integer (it is in the data you provided).

I just need to find some time to dig into it a bit more, I don't need anything from you. :)

@de-raaf-media
Copy link
Author

de-raaf-media commented Apr 2, 2024

Maybe this helps?

'amount' => $group->sum(function ($item) {
    dd($item['tax']);

Result:

array:3 [▼ // vendor/doublethreedigital/simple-commerce/src/Tags/CartTags.php:174
  "rate" => 21
  "amount" => "€1.74"
  "price_includes_tax" => true
]

@duncanmcclean
Copy link
Owner

duncanmcclean commented Apr 2, 2024

From a very brief look, I think it's happening because $this->items() returns the augmented line items:

return collect($this->items())

It should probably be using the "raw" line item data from the order instead. I'll try and take a look at this issue this week. For now, you could maybe use a composer patch if you need it fixed for now.

@de-raaf-media
Copy link
Author

Cool. Didn't know about "composer patch".

@duncanmcclean
Copy link
Owner

Just tagged a release (v6.0.11) which should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants