In the product_nodeapi the following is done:
$product = product_load($node);
However it ain't checked whether the node is a product type there. So ALL nodes loaded now do this query.
$product = db_fetch_object(db_query('SELECT * FROM {ec_product} WHERE vid = %d', $node->vid));
A solution like this would be appreciated:
$types = product_get_ptypes();
if ($node->type != 'product' && isset($types[$node->type])) {
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | product_nodeapi_load.patch | 698 bytes | R.Muilwijk |
Comments
Comment #1
gordon commentedIn v4 there is actually no product node type. Any type of node can be turned into a product.
Comment #2
R.Muilwijk commentedHmmz it can be nice for some things but sucks for alot of other things.
For example I made my own node type newsitem and blog. Those types will NEVER be a product because that would just be strange. So on my main page I show like 3 newsitems and 5 blog posts. They all do a node_load. And I get 8!!!! queries from e-commerce for free totally unneseccary.
Or a forum... list of 15 -40 nodes on a page... will never be a product and poof 15-40 queries!!!! on that page because of E-commerce.
However I've seen in the code line 575 of product.module you can turn it off for some node types:
So atleast change this:
to
Comment #3
R.Muilwijk commentedPatch was provided in previous post status set to patch (code needs review)
Comment #4
gordon commentedI have looked at this further and it is because if you turn off allowing to make a certain node type into a product then it will orphan any products that still exist.
Comment #5
R.Muilwijk commentedArgh... so you think it has more benefit to not be able to loose any products when you turn being a product off for a node type then a query for each node_load?
Just add a validate function to the node_form to check or any nodes of that node type are a product at that moment and throw a form_set_error. Or set the option of not being a product to disabled when there are products of that node type.
Changing the settings of a node type happens ONLY when making a site or adding new features. Node_loads happen all the time.
Comment #6
gordon commentedThis is ok, if you want to submit a patch to do this, then I will look at it.
I would not bother on a validate, but more just change the form so the option to turn off being a product is disabled until there is no products of that type.
Comment #7
R.Muilwijk commentedAt the moment there is a choice whether something is always a product or it can be product.
Would you rather have me add a new setting for disabling it as a product or adding a type as disabled?
Comment #8
R.Muilwijk commented