To get the max entity_id in customer_address_entity table in magento - magento

I am new in magento , if anyone know how to get the max entity_id in customer_address_entity table please reply soon

By using mysql
select entity_id from customer_address_entity order by entity_id desc
By using Magento Collection
echo "<pre>";
$collection = Mage::getModel('customer/customer')->getCollection()->getLastItem();
print_r($collection->getData());

Related

Magento disable products with no images via Phpmyadmin

i would like to disable products with no images in Magento 1.8. I have tried this code:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT entity_id
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);
but i have this alert:
Column 'entity_id' in field list is ambiguous
How can i resolve?
Thanks!
In your inner query on line 4 you're listing the column entity_id. This column name entity_id is not unique in your sql field list, because the column entity_id is in the catalog_product_entity table and in the catalog_product_entity_media_gallery as well. MySQL simply doesn't know, which one of these two columns should be shown. So you have to prepend the table in your select area:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT `your_table_name`.`entity_id`
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);

Magento: Query Database for products with no assigned categories

I'm really new to Magento and I'm looking to find a way to get a list of all the products in the catalog which are not assigned to any categories. Can anyone offer any help as to how this can be achieved?
Many thanks.
Select entity_id from catalog_product_entity where entity_id not in (select distinct product_id from catalog_category_product);
This will give you all product entity id not belonging to any category.
You can get product collection by using following code :
$product = Mage::getModel('catalog/product');
$productCollection = $product->getCollection()
->addAttributeToSelect('*');
foreach ( $productCollection as $_product ) {
echo $_product->getName().'<br/>';
}
But for your requirement you can get idea from following links,may be its help you.
How do I get product category information using collections in Magento

How we can write multiple select keyword in a single mysql query using Magento?

here is my query and this give proper ouput.
But How can I set it according to magento rules?
SELECT main_table.*,
(select company from sales_flat_order_address sfoa where sfoa.entity_id=sfo.billing_address_id) as bill_to_company,
(select company from sales_flat_order_address sfoa where sfoa.entity_id=sfo.shipping_address_id) as ship_to_company
FROM sales_flat_order_grid as main_table inner join sales_flat_order as sfo
on main_table.entity_id = sfo.entity_id
please help me....
Thanks & Reagards
Praful
You can use magento default connection Model
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$result=$write->query("your query as like mysql query no different");
$row = $readresult->fetch(); // this will fetch all your data

Magento filter order collection by product sku

I'm using magento 1.7 and I need to get all orders from certain increment_id containing at least one item matching a sku.
Here's what I have:
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status',
array(
'nin' => array(
'new',
'pending',
'pending_payment',
'holded',
'canceled')
))
->addFieldToFilter('increment_id', array('gteq' => $last_order));
If I add a line with:
$orderCollection->addFieldToFilter('sku', $findSku);
I will get a PHP fatal error since 'sku' is not a field. I've tried addAttributeToFilter() and it won't work either.
I know I need to build a join with another table, but I don't know how joins are made in Magento and I don't know which table I should join to.
Any help will be greatly appreciated.
SKUs are placed in order item table not in orders.
Your final query must look like this one:
SELECT o.increment_id
FROM sales_flat_order_item oi
INNER JOIN sales_flat_order o ON o.entity_id = oi.order_id
WHERE product_id=XXX
ORDER BY o.increment_id DESC;
This query can be done using nearly such syntax:
$orderItem = Mage::getModel('sales/order_item')->getCollection();
$orderItem
->getSelect()
->joinInner(array('order' => Mage::getSingleton('core/resource')->getTableName('sales/order')), 'order.entity_id = main_table.order_id' )
->where('product_id=?', $productId)
->order('main_table.order_id DESC');

Magento Get Product SELECTED ATTRIBUTE only?

Hi i'm working on an external application thats shows all the ordered items on a magento store.
The query that display the ordered product attribute is this :
select group_concat(distinct(b.value) separator '<br/>') from catalog_product_entity_varchar a , eav_attribute_option_value b , eav_attribute c
where a.value = b.option_id
and c.attribute_id = a.attribute_id
and c.is_user_defined = 1
and a.entity_id = PRODUCT_ID
This is for the attributes with type VARCHAR , i use the same query to get attributes of int and text. I just change the table name from catalog_product_entity_varchar to catalog_product_entity_int and catalog_product_entity_text.
The problem that i have is that i GET all the product attributes , manufacturer , supplier... and due to the fact that we got many stores i dont want to retrieve all the additional attributes with an additional sql where clause!
Any solution to get only selected attributes?
The below will grab the collection in PHP. You just need to change the Attribute that you select on. By adding the ->addOrderedQty, it allows the ability to get the ordered qty. Now I understand that you are using an external application. The reason that I post this is that you can load the Mage.php into your application and use this directly or you can just run this once and watch for the query in your database and then use that query to accomplish what you are looking to.
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->addAttributeToFilter('visibility', $visibility)
->setOrder('ordered_qty', 'desc');

Resources