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
format_raw
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?
$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?
- burt
- Core Team
- Posts: 4552
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: s01e10 - Sale Sticker
heatherbell wrote: ↑Tue Feb 27, 2024 3:07 pm $data['data-product-price'] = $product->format_raw();
which outputs the price with tax as applicable.
Could you rephrase the question as I don't quite understand what you are looking for.$data['data-product-fullPrice] = $product->get('products_price');
but with tax as applicable similar to above but have hit the wall - any pointers please?
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.
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
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
Still experimenting.
Adding this code in product_card
outputs this which is great
taking it a stage further, (naively) thought to hook in that content so replaced that code with
and made a hook
but that fails with
Undefined variable $product
and
Call to a member function format_raw() on null
so tried, in the hook, with
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?
Adding this code in product_card
Code: Select all
echo $product->format_raw('price') . '<br>';
echo $product->format_raw();Code: Select all
echo $GLOBALS['hooks']->cat('example');Code: Select all
class hook_shop_siteWide_productExample {
function listen_example() {
echo $product->format_raw('price') . '<br>';
echo $product->format_raw();
}
}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();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.
- burt
- Core Team
- Posts: 4552
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
-
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
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
So changing the code in hook to
gives just the one error now
Uncaught Error: Call to a member function format_raw() on null
so still stumped
Code: Select all
global $product;
echo $product->format_raw('price') . '<br>';
echo $product->format_raw();Uncaught Error: Call to a member function format_raw() on null
so still stumped
- burt
- Core Team
- Posts: 4552
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: format_raw
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.
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.
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
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.
- 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
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?heatherbell wrote: ↑Wed Feb 28, 2024 12:23 pm Inserting that into the file at exactly the same position as the hook call
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide