I know how to get order details of customer in magento with the following code
$salesModel=Mage::getModel("sales/order");
$salesCollection = $salesModel->getCollection()
->setOrder('increment_id','DESC');
But i need to display the customer details who have purchased only one time. I don't know how to resolve it. If anybody know, please save me guys!
If you go with the query, bellow query will help you,
SELECT * FROM sales_flat_order GROUP BY customer_id HAVING COUNT(customer_id) = 1
or This can be used,
$collection = Mage::getModel('customer/customer')->getCollection();
foreach ($collection as $user){
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToSelect('increment_id')
->addFieldToFilter('customer_id',$user->getId());
if($orders->getSize() == 1){
echo $user->getId();
}
}
Related
I need to retrieve the customer ID by email, I have tried like this:
$collection = mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('customer_id')
->addAttributeToFilter('email', 'costumeremail#gmail.com')
->addAttributeToSort('customer_id', 'ASC');
echo (string)$collection->getSelect();
but it always return error 500;
What's wrong?
Is there any way to retrieve customer info by email?
Please, use standard features magento:
$customerEmail = 'someemail#sample.com';
$customer = Mage::getModel('customer/customer')->loadByEmail($customerEmail);
$customerId = $customer->getId();
Can anyone help with the model/collection to search through all credit memos within magento as opposed to orders?
I can use Mage::getModel('sales/order') for orders but not seeing for credit memos
Kind regards
I put this together quickly. For example, let's say you wanted to grab the comments, you can do something like this.
Get CreditMemo Comment Based on Order
$incrementId = 100000002;
$collection = Mage::getResourceModel('sales/order_creditmemo_collection')
->addAttributeToFilter('increment_id', $incrementId);
foreach($collection as $item) {
$creditMessage = Mage::getResourceModel('sales/order_creditmemo_comment_collection')
->addAttributeToFilter('entity_id', $item->getEntityId());
foreach($creditMessage as $message) {
echo $message->getComment();
}
}
You can filter the collection with the increment_id or even the order_id :)
Get All Comments
$collection = Mage::getResourceModel('sales/order_creditmemo_comment_collection');
Below is a list of tables for creditmemo
sales_flat_creditmemo
sales_flat_creditmemo_comment
sales_flat_creditmemo_grid
sales_flat_creditmemo_item
Hope this helps!
right way to get Credit Memo comment collection
$collection = Mage::getResourceModel('sales/order_creditmemo_collection')
->addFieldToFilter('order_id', $order->getId()); /* here we have no load memo by order id not increment id.Increment id is the creditmemo increment id not order increment id. */
foreach($collection as $item) {
$creditMessage = Mage::getResourceModel('sales/order_creditmemo_comment_collection')
->addAttributeToFilter('parent_id', $item->getId()); /* here we need to use parent_id not entity_id.*/
}
var_dump($creditMessage->getData());
exit();
I have added a simple code to track each purchase on the site. All products have different types of rules based on categories to subtract a predefined percent of amount of product price.
But when there are configurable products in the cart then it is displaying me both products, original product price and the price of the selected option for the product details in the order detail.
If I have a lipstick in my cart and the color I selected is "RED" then lipstick price will change. But it is displaying me the original lipstick price as well as the red lipstick price in the order details.
I have added the code on order success page.
$orders = Mage::getModel('sales/order')->getCollection()
->setOrder('created_at','DESC')
->setPageSize(1)
->setCurPage(1);
$orderId = $orders->getFirstItem()->getEntityId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllItems();
foreach ($items as $itemId => $item)
{
$pid = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($pid);
$_finalPrice = $product->getFinalPrice();
echo $price = Mage::helper('core')->currency($_finalPrice,true,false);
// Some Code
}
I have also tried
$tempmain = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$temp = $tempmain->getAllItems();
$total = $tempmain->getGrandTotal();
foreach ($temp as $itemId => $item)
{
$pid = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($pid);
$_finalPrice = $product->getFinalPrice();
echo $price = Mage::helper('core')->currency($_finalPrice,true,false);
// Some Code
}
With the same results.
How to get only "RED" lipstick price in Order details?
Thanks in advance.
This is the details for all the availabel lipstick and their values:
when I select "Tango" as the color for lipstick on front end:
I am getting the Price of both products on success page:
Here is the Order Details Screen shot:
In frontoffice, when a customer add a configurable produt in his cart and order it, you'll see (in Database) 2 lines (2 quote_items and 2 order_item).
It's normal because magento needs to store the configurable product and the linked simple produt corresponding to the user selection (and linked to the master configurable product).
When displaying order details, Magento handles that difference by checking if a product has a parent id. You can do the same to ignore some order_item :
foreach($items as $item){
if ($item->getParentProductId() {
continue; // ignoring simple product associated to master order item (configurable)
}
// your code
}
I'm NOT 100% sure what your tying to do, but if you are on the order success page then this is the way to retrive the current order info (get the the last order for the db may not always be the current order on the success page if two user make a purchase millisecond apart)
Try adding this to Success.phtml
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
foreach($items as $item){
if ($item->getParentItem()) {
continue;
}
echo Mage::helper('core')->currency($item->getPrice(),true,false);
}
Layered navigation filters are created in
app/design/frontend/base/theme/template/catalog/layer/filter.phtml
How can I retrieve the value of the highest product price in the current product collection from within this file?
I've tried what I thought was the obvious choice $this->getMaxPriceInt() from Mage_Catalog_Model_Layer_Filter_Price but that does not seem to work within filter.phtml.
Assuming $collection is a collection of 'catalog/product', this should do the trick:
$product = $collection->setOrder('price', 'DESC')->getFirstItem();
Get highest and lowest price in category listing you can use below code.
$min_price = Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMinPrice();
$max_price = Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMaxPrice();
But it is not working for search and advance search layer navigation.so you can use below code for all pages layer navigation.$min_price = $this->getLayer()->getProductCollection()->getMinPrice();
$max_price = $this->getLayer()->getProductCollection()->getMaxPrice();
You can use below code on app/design/frontend/THEME/default/template/catalog/layer/view.phtml file.
Could you please try this ( let me know the result )
$model = Mage::getModel('catalog/product');
$collection = $model->getCollection()
->addStoreFilter()
->addAttributeToSelect('price')
->addAttributeToSort('price', 'asc');
if(!emtpy($collection)):
foreach($collection as $products) {
echo $products->getPrice();
echo $products->getName();
}
endif;
I have to load all available products from the particular attribute-set value additionally it needs to filter only the products which are not under particular category/categories. How can i load product collection here. Please help me
<?php
$storeId = Mage::app()->getStore()->getId();
$catalog = $this->getLayout()->createBlock('catalog/product_list')->setStoreId($storeId);
$collection = $catalog->getProductCollection()->addAttributeToSelect('*');
$collection->getSelect()->where(category_id != { cat_id } )->limit($this->products_count);
$_productCollection = $collection;
?>
This isn't teste yet and I'm not sure if category_id is the correct value that is used in the database. But it should give you a good start.