Posted by R.Muilwijk on April 24, 2008 at 1:22pm
| Project: | e-Commerce |
| Version: | 5.x-4.0-alpha11 |
| Component: | product |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (won't fix) |
Issue Summary
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])) {
Comments
#1
In v4 there is actually no product node type. Any type of node can be turned into a product.
#2
Hmmz 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:
variable_get('ec_product_convert_'. $form['#node']->type, variable_get('ec_product_convert', 0))So atleast change this:
function product_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {switch ($op) {
case 'load':
if ($product = product_load($node)) {
foreach ($product as $key => $value) {
$node->$key = $value;
}
}
break;
to
function product_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {switch ($op) {
case 'load':
if (variable_get('ec_product_convert_'. $node->type, variable_get('ec_product_convert', 0))) {
if ($product = product_load($node)) {
foreach ($product as $key => $value) {
$node->$key = $value;
}
}
}
break;
#3
Patch was provided in previous post status set to patch (code needs review)
#4
I 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.
#5
Argh... 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.
#6
This 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.
#7
At 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?
#8