format_raw
- burt
- Core Team
- Posts: 4551
- 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
print_r($product) in the Hook.
You will, I think, see NULL $product as the Hook runs before the Product object
So you need to think of another way to access that data.
Maybe throw something from the card and catch it in the hook.
This is the life of a developer, fun no?
It gets duller and duller the more years you do it.
You will, I think, see NULL $product as the Hook runs before the Product object
So you need to think of another way to access that data.
Maybe throw something from the card and catch it in the hook.
This is the life of a developer, fun no?
It gets duller and duller the more years you do it.
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
TY. What you say does make sense, otherwise not so much. LOL!
Yes, even banging head against wall is fun when stopped!
Could be applied to life if counter-measures were not taken but feel sure, even you, still finds some stars in an otherwise dark sky.
Anyway, TY to you both for replies and patience and feck this hook idea! (though nothing tried, nothing learned)
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: format_raw
heatherbell wrote: ↑Wed Feb 28, 2024 10:28 amand made a hookCode: 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(); } }
Code: Select all
$parameters = [
'product' => $product,
];
echo $GLOBALS['hooks']->cat('example', $parameters);Code: Select all
class hook_shop_siteWide_productExample {
function listen_example($parameters) {
return $parameters['product']->format_raw('price') . '<br>'
. $parameters['product']->format_raw();
}
}No. The problem is that the $product in the product_card is not global, so to access it via hook, you have to pass it into the hook publisher so that the listener can hear it. The order of processing is irrelevant here.
-
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
Sincere thanks for both the answer and, more important to me, the explainer.
This really has opened the gate for me
Delete the now superfluous ; from the code in the hook file and works as expected.
Code: Select all
class hook_shop_siteWide_productExample {
function listen_example($parameters) {
return $parameters['product']->format_raw('price') . '<br>'
. $parameters['product']->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
Playing with this today and found difficulty getting the products_date_added data.
Used $product->get('date_added') and $product->get('products_date_added') in product_card to output that data on cards, both produced some unexpected results in some areas of the site that do not correlate to the DB data. Guessing something to do with manufacturers in one of the core DB queries?
Can't find what to use instead of $product->get('date_added') to output that data.
Used $product->get('date_added') and $product->get('products_date_added') in product_card to output that data on cards, both produced some unexpected results in some areas of the site that do not correlate to the DB data. Guessing something to do with manufacturers in one of the core DB queries?
Can't find what to use instead of $product->get('date_added') to output that data.
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: format_raw
I'm not following. What change did you make exactly and what unexpected results did you get? I follow that $product->get('date_added') was added somewhere. Where? Did you make any other changes?
-
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
<?= $product->get('date_added'); ?> added to product_card component on 1.0.8.21heatherbell wrote: ↑Thu Feb 29, 2024 4:12 pm Used $product->get('date_added') in product_card to output that data on cards
The data in products table is this: Note that Lime (see bottom row) products_date_added is 2024-02-26 15:51:03
Output on index is 2024-02-26 15:51:03 - expected
Output on index nested is 2024-02-26 15:51:03 - expected
Output on index products is 2024-02-18 15:51:03 - unexpected, That data does not occur in products table.
Output on specials, products_new and advanced_search_result is 2024-02-18 15:51:03 - unexpected, That data does not occur in products table.
What to use instead of $product->get('date_added') to output products_date_added on all cards?
You do not have the required permissions to view the files attached to this post.
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: format_raw
Sure it does. That's the date for Orange. This suggests to me that when you call $product->get('date_added'), $product refers to Orange. I.e. ->get('date_added') is correct. $product is incorrect. So the thing that you should be troubleshooting is why $product is incorrect.
Previously you had been attempting to use global $product. That's exactly the kind of thing that would cause $product to be set to the wrong value. Look for places where you set $product after using global.
-
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
Now changed that data in DB so that data is definitely not there with exactly the same result Searching the DB shows that data occurring in manufacturers so maybe that's correlated.
This is on a clean install, the only addition to product_card component is <?= $product->get('date_added'); ?>
Still stumped by the unexpected outputs and do not know what to use instead of <?= $product->get('date_added'); ?> that would output products_date_added on all cards.
You do not have the required permissions to view the files attached to this post.