format_raw

Open to all! Ask other shopowners for help.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

format_raw

Post by heatherbell »

https://github.com/CE-PhoenixCart/Phoen ... er.php#L41
$data['data-product-price'] = $product->format_raw();
which outputs the price with tax as applicable.
Want to add, e.g.
$data['data-product-fullPrice] = $product->get('products_price');
but with tax as applicable similar to above but have hit the wall - any pointers please?


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4553
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: s01e10 - Sale Sticker

Post by burt »

heatherbell wrote: Tue Feb 27, 2024 3:07 pm $data['data-product-price'] = $product->format_raw();
which outputs the price with tax as applicable.
$data['data-product-fullPrice] = $product->get('products_price');
but with tax as applicable similar to above but have hit the wall - any pointers please?
Could you rephrase the question as I don't quite understand what you are looking for.

It seems like you're looking for $product->format_raw(); as that would be the answer to what I have quoted second.

Maybe you want it without tax ?
I am not here to build for you.
I am here to build with you. Let's help each other.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: s01e10 - Sale Sticker

Post by heatherbell »

burt wrote: Tue Feb 27, 2024 6:33 pmI don't quite understand what you are looking for.
LOL - story of my life!
TY anyway, now gone a different route but after some hours browsing core, now beginning to understand format_raw()
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: format_raw

Post by heatherbell »

Still experimenting.
Adding this code in product_card

Code: Select all

echo $product->format_raw('price') . '<br>';
echo $product->format_raw();
outputs this which is great
Screenshot 2024-02-28 101623.png
taking it a stage further, (naively) thought to hook in that content so replaced that code with

Code: Select all

echo $GLOBALS['hooks']->cat('example');
and made a hook

Code: Select all

class hook_shop_siteWide_productExample {
    function listen_example() {
    	echo $product->format_raw('price') . '<br>';
    	echo $product->format_raw();
    } 
}
but that fails with
Undefined variable $product
and
Call to a member function format_raw() on null
so tried, in the hook, with

Code: Select all

    echo $GLOBALS['product']->format_raw('price') . '<br>';
    echo $GLOBALS['product']->format_raw();
but that fails with
Undefined array key "product"
and
Call to a member function format_raw() on null
Just doing it wrong or trying to do impossible?
You do not have the required permissions to view the files attached to this post.
User avatar
burt
Core Team
Posts: 4553
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: format_raw

Post by burt »

Hook runs before product object?
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: format_raw

Post by heatherbell »

burt wrote: Wed Feb 28, 2024 11:26 am Hook runs before product object?
Naively thought that if the code runs OK in that position in the file, then a hook in that same position calling the same code should run. Still stumped as to what's wrong.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: format_raw

Post by heatherbell »

So changing the code in hook to

Code: Select all

    global $product;
    echo $product->format_raw('price') . '<br>';
    echo $product->format_raw();
gives just the one error now
Uncaught Error: Call to a member function format_raw() on null
so still stumped :(
User avatar
burt
Core Team
Posts: 4553
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: format_raw

Post by burt »

I think you'll find that there is still no available product object.

In other words: $product = NULL

print_r($product) and you will ascertain.
I am not here to build for you.
I am here to build with you. Let's help each other.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: format_raw

Post by heatherbell »

burt wrote: Wed Feb 28, 2024 12:09 pm print_r($product)
Inserting that into the file at exactly the same position as the hook call (commented out) outputs all the product data so guessing $product is doing as expected so still stumped.
As per previous post, the code works at that position in the file but the hook containing the same code called at the same position does not - that's what is not understood.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: format_raw

Post by Kofod95 »

heatherbell wrote: Wed Feb 28, 2024 12:23 pm Inserting that into the file at exactly the same position as the hook call
Yes, your problem is, that hooks are processed before the product-object. Meaning, that even if the position in the file has the data, the hooks are processed before that and just injected at the place of the hook-call - makes sense?

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply