Hello when a user place a order,i want to update a custom field of all customer.Though i have created custom field in customer section.
For this i am using following code.but by this code i am unable to find customer ids.
Please tell me how can i find customer ids in loop.
$productId='1';
$order= Mage::getModel('sales/order_item')->getCollection()
->addAttributeToFilter('store_id', Mage::app()->getStore()->getId())
->addAttributeToFilter('product_id',$productId);
foreach ($order_collection as $itemId => $item)
{
$customerid=$item->getCustomerId();
}
Mage::getModel('sales/order_item') won't have customer Id's see the database table: sales_flat_order_item You'll want to use Mage::getModel('sales/order') to retrieve such from sales_flat_order
Related
I built the plugin (with builder) where I have products and categories. Product and categories are "conected" by relation table. I have list of products and another list of categories. On page where I list my all categories everthing works fine. The problem is with the single category view. Now products in a single category are listed by add order. But I want to have my own order of products or some sort of reordering. Builder delivers sorting in record list (categories page) but not in record details (single category page).
Thanks for answers.
In your model, you have already added relationship like category <-> products
Here you can add an order option to set the order.
// inside category model
public $hasMany = [
'products' => [
\Acme\Shop\Models\Product::class,
'order' => 'title desc', // <- here although its hardcoded
]
];
Or if you prefer dynamic order then inside your page code section you can add the onStart function and fetch the product manually.
function onStart() {
$id = 1; // just for example you can get category based on slug
$sortedProducts = Category::find($id)
->products()->orderBy('title')->get();
// dynamic as per your need ^
$this['products'] = $sortedProducts;
}
// now in the code section you can use `products` and they will be sorted
if any doubt please comment
I have a custom module and I am loading a collection like following
$collection = Mage::getModel('module/product')->getCollection()
->addFieldToFilter('sku',$sku);
There is field named as prod_id in the database. Can I get this as entity_id while loading the collection?
If yes. Please help how to do this.
First of all all
addAttributeToFilter() is used to filter EAV collections.
addFieldToFilter() is used to filter Non-EAV collections.
EAV-models are for example product, customer, sales, etc so you can use use addAttributeToFilter() for those entities.
addFieldToFilter() is mapped to `addAttributeToFilter()` for `EAV` entities. So you can just use `addFieldToFiler().`
You can have a look in app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php where the Mapping is done:
public function addFieldToFilter($attribute, $condition = null) {
return $this->addAttributeToFilter($attribute, $condition);
}
If you are using custom module then you can directly use addFieldToFilter() with your column name
Like
$collection = Mage::getModel('module/model')->getCollection()
->addFieldToFilter('column_name',$data);
Let me know if you have any query
I'm currently developing a custom module for Magento and theres one thing I´m not able to get working.
I have a front-end display of employees and an backend so I can add employees.
I save the employees in a regular mysql table(so not EAV). Just to add employees to the database is no problem but now I want to add a different table so that the employees can be part of more than one category. I want to display the magento categories, and that I get working, but next I want to save that value along with the id of my employee in my own table in the database. Thats the problem i'm having.
I've tried using the magento admin grid and have a tab for adding and editing. I´ve tried to add a new tab and adding checkboxes there to check and save but can get it to work
Maybe I'm completely of, if that so youre free to suggest a different approach.
add this to save action
if (isset($data['categories'])) {
$data['categories'] = explode(',', $data['categories']);
if (is_array($data['categories'])) {
$data['categories'] = array_unique($data['categories']);
}
}
and this to collection
$this->getSelect()->join(
array('category_table' => $this->getTable('qbanner/qbanner_category')), 'main_table.qbanner_id = category_table.qbanner_id', array()
)
->where('category_table.category_id = ?', $categoryId);
return $this;
hope this will help you
I am using magento 1.7.0.2. I am having issue regarding store id. When I add new customer from the frontend by sign up, it adds the store id in the "Customer Entity" table. However, when I try to manually add a customer using the backend inserts "0" rather than the 'store id' in the "Customer Entity" table.
How can I get the store id of the customer when adding a customer by admin?
How to set option in backend to insert store id manually in "Customer Entity" table via backend?
Is it required to set new field 'select store'?
It is simple.
go to /app/code/core/Mage/Adminhtml/controllers/CustomerController.php
and just before //send welcome email part
// Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
// 'customer' => $customer,
// 'request' => $this->getRequest()
// ));
And put following code there.
$storeId = $customer->getSendemailStoreId();
Mage::app()->setCurrentStore($storeId);
$customer->save();
That's it now you can choose store from backend and will also be inserted in to customer_entity table.
solution find from phprocks
I was able to get order details and customer details inside template/checkout/success.html file, but not sure how to get details for the exact products that were ordered? I need their names for some third party stat appliances. I bet it's simple - just another weird chained call to some "where-did-this-come-from?" method...
Help?
do (as you have order model)
$order_items = $order->getAllItems();
foreach($order_items as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
//and you can do what ever you want with the product
}
You can retrieve the order details like:
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout /session')->getLastOrderId());
Then you can pull in all the various data with this:
$subtotal = $order->getSubtotal();
$order->getId();
$order->getIncrementId();
$order->getGrandTotal();