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
:
The table you are looking for is a simple table.
When your host restored your database, it sounds like it did not have the core_store
table inside of it. Also, it might be that there is a table prefix that might or might not be at play here.
Try these first:
- Check your database to ensure there is a
core_store
(or variant) table available.
- Check to make sure your
local.xml
config file is pointing to the right database.
- Ask your host to restore from another restore point.
- Check to ensure your
local.xml
didn't have a table prefix recently added or removed.
If that does not work, you can always do raw SQL inside your database.
PLEASE NOTE: TEST THIS ON A NON PRODUCTION ENVIRONMENT BEFORE PRODUCTION!
Core Store Table:
CREATE TABLE `core_store` (
`store_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Store Id',
`code` varchar(32) DEFAULT NULL COMMENT 'Code',
`website_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Website Id',
`group_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Group Id',
`name` varchar(255) NOT NULL COMMENT 'Store Name',
`sort_order` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Sort Order',
`is_active` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Activity',
PRIMARY KEY (`store_id`),
UNIQUE KEY `UNQ_core_store_CODE` (`code`),
KEY `IDX_core_store_WEBSITE_ID` (`website_id`),
KEY `IDX_core_store_IS_ACTIVE_SORT_ORDER` (`is_active`,`sort_order`),
KEY `IDX_core_store_GROUP_ID` (`group_id`),
CONSTRAINT `FK_core_store_GROUP_ID_core_store_GROUP_GROUP_ID` FOREIGN KEY (`group_id`) REFERENCES `core_store_group` (`group_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_core_store_WEBSITE_ID_WBCORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `wbcore_website` (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Stores';
Insert default entries:
INSERT INTO `core_store` VALUES (0,'admin',0,0,'Admin',0,1),(1,'default',1,1,'Default Store View',0,1);
Best Answer
You can check the size of your collection:
Explaination here: Difference between getSize() and count() on collection
Edit: tested for 750 products
$collection->getData()
$collection->getSize()
$collection->count()
orsizeof($collection)