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
:
You can do it by plugin or overwrite of **Magento\Wishlist\CustomerData\Wishlist**
. I will cover pluginize **getSectionData**
for achieving this.
VendorName/ModuleName/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Wishlist\CustomerData\Wishlist">
<plugin name="customer_data_wishlist" type="VendorName\ModuleName\Plugin\Wishlist\CustomerData\Wishlist" sortOrder="1"/>
</type>
</config>
VendorName/ModuleName/Plugin/Wishlist/CustomerData/Wishlist.php
> namespace VendorName\ModuleName\Plugin\Wishlist\CustomerData;
class Wishlist
{
/**
* @var \Magento\Wishlist\Helper\Data
*/
protected $wishlistHelper;
/**
* @var \Magento\Catalog\Helper\ImageFactory
*/
protected $imageHelperFactory;
/**
* @var \Magento\Framework\App\ViewInterface
*/
protected $view;
/**
* @var \Magento\Wishlist\Block\Customer\Sidebar
*/
protected $block;
/**
* Wishlist constructor.
*
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
* @param \Magento\Wishlist\Block\Customer\Sidebar $block
* @param \Magento\Catalog\Helper\ImageFactory $imageHelperFactory
* @param \Magento\Framework\App\ViewInterface $view
*/
public function __construct(
\Magento\Wishlist\Helper\Data $wishlistHelper,
\Magento\Wishlist\Block\Customer\Sidebar $block,
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
\Magento\Framework\App\ViewInterface $view
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
$this->block = $block;
$this->view = $view;
}
public function aroundGetSectionData(
\Magento\Wishlist\CustomerData\Wishlist $subject,
\Closure $proceed
) {
$counter = $this->getCounter();
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : [],
];
}
/**
* @return string
*/
protected function getCounter()
{
return $this->createCounter($this->wishlistHelper->getItemCount());
}
/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return \Magento\Framework\Phrase|null
*/
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
/**
* Get wishlist items
*
* @return array
*/
protected function getItems()
{
$this->view->loadLayout();
$collection = $this->wishlistHelper->getWishlistItemCollection();
$collection->clear()->setInStockFilter(true)->setOrder('added_at');
$items = [];
foreach ($collection as $wishlistItem) {
$items[] = $this->getItemData($wishlistItem);
}
return $items;
}
/**
* Retrieve wishlist item data
*
* @param \Magento\Wishlist\Model\Item $wishlistItem
* @return array
*/
protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
{
$product = $wishlistItem->getProduct();
return [
'image' => $this->getImageData($product),
'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem),
'product_name' => $product->getName(),
'product_price' => $this->block->getProductPriceHtml(
$product,
'wishlist_configured_price',
\Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
['item' => $wishlistItem]
),
'product_is_saleable_and_visible' => $product->isSaleable() && $product->isVisibleInSiteVisibility(),
'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product),
'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem, true),
'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem, true),
];
}
/**
* Retrieve product image data
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Block\Product\Image
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getImageData($product)
{
/** @var \Magento\Catalog\Helper\Image $helper */
$helper = $this->imageHelperFactory->create()
->init($product, 'wishlist_sidebar_block');
$template = $helper->getFrame()
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';
$imagesize = $helper->getResizedImageInfo();
$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
return [
'template' => $template,
'src' => $helper->getUrl(),
'width' => $width,
'height' => $height,
'alt' => $helper->getLabel(),
];
}
}
Clear cache.
NB: Only refresh is not enough for testing working or not. Add/Remove wishlist item then magento fire sidebar section data and load.
Best Answer
The follows should do what you are wanting but you will have to change your loop structure a little bit as when you loop through your products you will only have finish one iteration of the collection items in your original version: