Please use this code
$productCollection = Mage::getResourceModel('catalog/product_collection')
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', 3);
$productCollection->getSelect()->group('product_id')->distinct(true);
echo '<pre>'; print_r($productCollection->getData());
Definitely this work for you.
user1618341,According magento an order can place
from one store
,Magento is save order store id at sales_flat_order,sales_flat_grid order
.
At your collection you need get store_id.Also need rectify collection query,Please use * instead of some field
<?php
try {
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter(
'status',
array(
'nin' => array('complete', 'canceled', 'processing', 'holded', 'fraud'),
'in' => 'pending',
))
->addAttributeToSelect('store_id')
->addAttributeToSelect('status');
}
catch (Mage_Core_Exception $e) {
}
I have put the condition to skip create shipment for one store view[if($eachorder->getData('store_id')!=='YOUSKIPSTOREID'):]
see code:
try {
foreach ($orders as $eachorder) {
$order = Mage::getModel("sales/order")->load($eachorder->getId());
if (!$order->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
/* put code for skip for one store */
if($eachorder->getData('store_id')!=='YOUSKIPSTOREID'):
$shipment = $order->prepareShipment();
if ($shipment) {
$shipment->register();
$order->setIsInProcess(true);
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
} else {
throw new Exception("Cant get shipment");
}
endif;
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
}
}catch (Mage_Core_Exception $e) {
}
If you getting the issues for create invoice and shipment,Please see my Blog:
Create invoice:
Create Shipment
:
Best Answer
When you want to get products from category using $productCollection->addCategoryFilter() or using $category->getProductCollection() query use product to category connection INDEX table. When you run re index that product category connection INDEX table is populated only with Enabled porducts, and you can not get disabled products on that way.
For Disable Product