How to use expression values in where condition?
How to do that in magento model way
Select sum(qty + product_id - any_other_columns) as total from table2 where total>10;
model eav query
add a comment |
How to do that in magento model way
Select sum(qty + product_id - any_other_columns) as total from table2 where total>10;
model eav query
add a comment |
How to do that in magento model way
Select sum(qty + product_id - any_other_columns) as total from table2 where total>10;
model eav query
How to do that in magento model way
Select sum(qty + product_id - any_other_columns) as total from table2 where total>10;
model eav query
model eav query
edited 35 mins ago
Teja Bhagavan Kollepara
2,94841847
2,94841847
asked May 13 '16 at 9:41
Vipan Kumar ParjapatiVipan Kumar Parjapati
32
32
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Its a strange query you want to run, but this is how you do it:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
$collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
$collection->getSelect()->having('total > 10');
add a comment |
Here is the example how to use Direct mysql in Magento
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = 44;
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
$newSku = 'new-sku';
$query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
. (int)$productId;
/**
* Execute the query
*/
$writeConnection->query($query);
For More see here.
Another way
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
For more detail see here.
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f115275%2fhow-to-use-expression-values-in-where-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Its a strange query you want to run, but this is how you do it:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
$collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
$collection->getSelect()->having('total > 10');
add a comment |
Its a strange query you want to run, but this is how you do it:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
$collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
$collection->getSelect()->having('total > 10');
add a comment |
Its a strange query you want to run, but this is how you do it:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
$collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
$collection->getSelect()->having('total > 10');
Its a strange query you want to run, but this is how you do it:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
$collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
$collection->getSelect()->having('total > 10');
answered May 14 '16 at 6:34
Shawn AbramsonShawn Abramson
2,4671815
2,4671815
add a comment |
add a comment |
Here is the example how to use Direct mysql in Magento
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = 44;
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
$newSku = 'new-sku';
$query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
. (int)$productId;
/**
* Execute the query
*/
$writeConnection->query($query);
For More see here.
Another way
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
For more detail see here.
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
add a comment |
Here is the example how to use Direct mysql in Magento
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = 44;
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
$newSku = 'new-sku';
$query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
. (int)$productId;
/**
* Execute the query
*/
$writeConnection->query($query);
For More see here.
Another way
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
For more detail see here.
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
add a comment |
Here is the example how to use Direct mysql in Magento
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = 44;
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
$newSku = 'new-sku';
$query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
. (int)$productId;
/**
* Execute the query
*/
$writeConnection->query($query);
For More see here.
Another way
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
For more detail see here.
Here is the example how to use Direct mysql in Magento
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = 44;
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
$newSku = 'new-sku';
$query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
. (int)$productId;
/**
* Execute the query
*/
$writeConnection->query($query);
For More see here.
Another way
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
For more detail see here.
answered May 13 '16 at 10:12
ArunendraArunendra
6,13831642
6,13831642
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
add a comment |
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
you didn't read my question i think
– Vipan Kumar Parjapati
May 13 '16 at 10:29
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
I have read your question and these are just examples now what do you want ?
– Arunendra
May 13 '16 at 10:34
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f115275%2fhow-to-use-expression-values-in-where-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown