Прерывистый «не может создать пустую отгрузку».Когда объемная обработка поставки

magento.stackexchange https://magento.stackexchange.com//questions/60776

  •  12-12-2019
  •  | 
  •  

Вопрос

У нас есть прерывистый, не может создать пустую доставку.когда объемные переработки грузов.Использовал API раньше.

Этот контроллер срабатывает с объемом выбранных заказов в обзоре заказа.Он отправляет все элементы на заказ и отправляет электронную почту.

Каким-то образом мы не можем создать пустую доставку..... $ itemqty> 0 просто проверил

Мы что-нибудь забываем?

public function _shipmailinvoice($email=true) {

    $orderIds = $this->getRequest()->getPost('order_ids', array());

    $cnt_Orders     = count($orderIds);
    $cnt_Shipments  = 0;
    $cnt_Invoices   = 0;

    if (!empty($orderIds)) {
      foreach ($orderIds as $orderId) {
        $order = Mage::getModel('sales/order')->load($orderId);
        //$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);

        $itemQty = (int)$order->getItemsCollection()->count();
        $shipment = $order->prepareShipment($itemQty);
        //$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
        if ($shipment && ($order->hasShipments() < 1)) {
            $shipment->register();
            $order->setIsInProcess(true);
            $order->addStatusHistoryComment('Shipment created by SNH_SHipMailInvoice.', false);
            try {
                $transactionSave = Mage::getModel('core/resource_transaction')
                ->addObject($shipment)
                ->addObject($shipment->getOrder())
                ->save();
                if ($email) { $shipment->sendEmail($email, '')->setEmailSent(true)->save(); }
                $cnt_Shipments++;
            } catch (Mage_Core_Exception $e) {
                // var_dump($e);
                $this->_getSession()->addError($e, 'Cannot create shipment');
            }
        } else {
            if ($email) { $shipment->sendEmail($email, '')->setEmailSent(true)->save(); }
            $cnt_Shipments++;
        }`
.

Это было полезно?

Решение

Это работало для нас

$orderIds = $this->getRequest()->getPost('order_ids', array());

    $cnt_Orders     = count($orderIds);
    $cnt_Shipments  = 0;
    $cnt_Invoices   = 0;

    if (!empty($orderIds)) {
        foreach ($orderIds as $orderId) {
            if (!$ship) continue;
            $order = Mage::getModel('sales/order')->load($orderId);
            //$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
            //$itemQty = (int)$order->getItemsCollection()->count();
            //$shipment = $order->prepareShipment($itemQty);
            //$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
            $shipment = $order->prepareShipment();
            if ($shipment && $order->canShip()) {
                $shipment->register();
                if ($email) $shipment->setEmailSent($email);
                $shipment->getOrder()->setIsInProcess(true);
                try {
                    $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($shipment)
                    ->addObject($shipment->getOrder())
                    ->save();
                    if ($email) $shipment->sendEmail($email, '');
                    $cnt_Shipments++;
                } catch (Mage_Core_Exception $e) {
                    $this->_getSession()->addError($e, 'Cannot create shipment');
                }
                unset($shipment);
            } else {
                if ($email) { $shipment->sendEmail($email, '')->setEmailSent(true)->save(); }
                $cnt_Shipments++;
            }

            if ($cnt_Shipments > 0 && $cnt_Shipments < $cnt_Orders) {
             $this->_getSession()->addNotice(Mage::helper('sales')->__('Sent %s shipments and notications of %s requested. Not all shipments were sent.', $cnt_Shipments, $cnt_Orders));
            }

    }
.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top