public function shipmentSaveBefore(Varien_Event_Observer $observer) { /* @var $shipment Mage_Sales_Model_Order_Shipment */ $shipment = $observer->getShipment(); if ($shipment->getOrder()->getDcOrderId() && !$shipment->getDcOrderId()) { $result = Dutycalculator_Charge_Model_Importdutytaxes::shipmentCalculation($shipment); if ($result) { $shipment->setDcOrderId($result['dc_order_id']); } } $shipment->setDeliveryDutyType($shipment->getOrder()->getDeliveryDutyType()); $shipment->setFailedCalculation($shipment->getOrder()->getFailedCalculation()); return $this; }
/** * Sends create order shipment request to Rakuten Checkout * Observes "sales_order_shipment_save_before" event * * @param Varien_Event_Observer $observer * @return void */ public function sendShipment($observer) { try { /** @var $shipment Mage_Sales_Model_Order_Shipment */ $shipment = $observer->getShipment(); if ($shipment->getOrder()->getRakutenOrder()) { /** @var $rockout Rakuten_Checkout_Model_Checkout */ $rockout = Mage::getModel('rakuten/checkout'); // Send shipment to Rakuten $rockout->sendShipment($shipment); } } catch (Exception $e) { Mage::throwException(Mage::helper('rakuten')->__('Cannot send shipment to Rakuten Checkout.') . '<br />' . Mage::helper('rakuten')->__('Error #%s: %s', $e->getCode(), $e->getMessage())); } }
/** * @param Varien_Event_Observer $observer * * @return $this|void */ public function manipulateShipmentForBillsafe(Varien_Event_Observer $observer) { if (Mage::getConfig()->getModuleConfig('Netresearch_Billsafe')->is('active', 'true')) { $shipment = $observer->getShipment(); $code = $shipment->getOrder()->getPayment()->getMethodInstance()->getCode(); if ($code != Netresearch_Billsafe_Model_Payment::CODE) { return; } $magentoShopgateOrder = Mage::getModel("shopgate/shopgate_order")->load($shipment->getOrder()->getId(), "order_id"); if ($magentoShopgateOrder->getId() == null) { return; } /** * manipulate order number */ $shipment->getOrder()->setIncrementId($magentoShopgateOrder->getShopgateOrderNumber()); /** @var Mage_Sales_Model_Order $order */ $order = $shipment->getOrder(); $order->setIsShopgateOrder(true); return $this; } return $this; }
/** * Saves the chosen consignment options and creates a MyParcel shipment for the current shipment. * * @param Varien_Event_Observer $observer * * @return $this * @throws Exception * @event sales_order_shipment_save_after * @observer tig_myparcel_shipment_save_after */ public function saveConsignmentOption(Varien_Event_Observer $observer) { $helper = Mage::helper('tig_myparcel'); /** * check if extension is enabled */ if (!$helper->isEnabled()) { return $this; } /** * @var Mage_Sales_Model_Order_Shipment $shipment */ $shipment = $observer->getShipment(); /** * check if order is placed with Myparcel */ $shippingMethod = $shipment->getOrder()->getShippingMethod(); if (!$helper->shippingMethodIsMyParcel($shippingMethod)) { return $this; } /** * check if the current shipment already has a myparcel shipment */ if ($helper->hasMyParcelShipment($shipment->getId())) { return $this; } /** * check if a new consignment must me made */ $registryOptions = Mage::registry('tig_myparcel_consignment_options'); if (empty($registryOptions) || !isset($registryOptions['create_consignment'])) { return $this; } /** * check if consignment option matches the Magento shipment */ if (false !== $helper->getPgAddress($shipment->getOrder()) && (!isset($registryOptions['shipment_type']) || $registryOptions['shipment_type'] != TIG_MyParcel2014_Model_Shipment::TYPE_NORMAL)) { return $this; } /** * @var TIG_MyParcel2014_Model_Shipment $myParcelShipment */ $myParcelShipment = Mage::getModel('tig_myparcel/shipment')->load($shipment->getId()); $consignmentOptions = $registryOptions; if (Mage::registry('tig_myparcel_consignment_options')) { $consignmentOptions = array_merge($consignmentOptions, Mage::registry('tig_myparcel_consignment_options')); Mage::unregister('tig_myparcel_consignment_options'); } Mage::register('tig_myparcel_consignment_options', $consignmentOptions); $myParcelShipment->setShipmentId($shipment->getId())->setConsignmentOptions()->createConsignment()->save(); $barcode = $myParcelShipment->getBarcode(); if ($barcode) { $carrierCode = TIG_MyParcel2014_Model_Shipment::MYPARCEL_CARRIER_CODE; $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/name', $shipment->getStoreId()); //if the other carrier-method is used, get the title if ($helper->getPgAddress($myParcelShipment)) { $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/pakjegemak_title', $shipment->getStoreId()); } $data = array('carrier_code' => $carrierCode, 'title' => $carrierTitle, 'number' => $barcode); /** * @var Mage_Sales_Model_Order_Shipment_Track $track */ $track = Mage::getModel('sales/order_shipment_track')->addData($data); $shipment->addTrack($track); $trackCollection = $shipment->getTracksCollection(); foreach ($trackCollection as $track) { $track->save(); } } return $this; }
/** * @param Varien_Event_Observer $observer */ public function captureInvoiceOnShipment(Varien_Event_Observer $observer) { /* @noinspection PhpUndefinedMethodInspection */ /* @var Mage_Sales_Model_Order_Shipment $shipment */ $shipment = $observer->getShipment(); /** @var Mage_Sales_Model_Order $order */ $order = $shipment->getOrder(); $adyenHelper = Mage::helper('adyen'); $storeId = $order->getStoreId(); $captureOnShipment = $adyenHelper->getConfigData('capture_on_shipment', 'adyen_abstract', $storeId); $createPendingInvoice = $adyenHelper->getConfigData('create_pending_invoice', 'adyen_abstract', $storeId); // validate if payment method is adyen and if capture_on_shipment is enabled if ($this->isPaymentMethodAdyen($order) && $captureOnShipment) { if ($createPendingInvoice) { $transaction = Mage::getModel('core/resource_transaction'); $transaction->addObject($order); foreach ($order->getInvoiceCollection() as $invoice) { /* @var Ho_Invoice_Model_Sales_Order_Invoice $invoice */ if (!$invoice->canCapture()) { continue; } $invoice->capture(); $invoice->setCreatedAt(now()); $transaction->addObject($invoice); } $order->setIsInProcess(true); $transaction->save(); } else { // create an invoice and do a capture to adyen if ($order->canInvoice()) { try { $invoice = $order->prepareInvoice(); $invoice->getOrder()->setIsInProcess(true); // set transaction id so you can do a online refund from credit memo $invoice->setTransactionId(1); $invoice->register()->capture(); $invoice->save(); } catch (Exception $e) { Mage::logException($e); } $invoiceAutoMail = (bool) $adyenHelper->getConfigData('send_invoice_update_mail', 'adyen_abstract', $storeId); if ($invoiceAutoMail) { $invoice->sendEmail(); } } } } return $this; }
/** * Add shipping method to invoice notes. * * @param Varien_Event_Observer $observer observer object * * @return FireGento_Pdf_Model_Observer */ public function addShippingMethod(Varien_Event_Observer $observer) { $invoice = $observer->getInvoice(); $shipment = $observer->getShipment(); if (empty($invoice) && empty($shipment) || !empty($invoice) && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') != FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_NOTE || !empty($shipment) && Mage::getStoreConfig('sales_pdf/shipment/shipping_method_position') != FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_NOTE) { return $this; } $result = $observer->getResult(); $notes = $result->getNotes(); $notes[] = Mage::helper('firegento_pdf')->__('Shipping method: %s', $observer->getOrder()->getShippingDescription()); $result->setNotes($notes); return $this; }
/** * Event * - sales_order_shipment_save_before * * @param Varien_Event_Observer $observer * @return $this */ public function handleShipmentSaveBefore(Varien_Event_Observer $observer) { /* @var $shipment Mage_Sales_Model_Order_Shipment */ $shipment = $observer->getShipment(); $carrier = $shipment->getOrder()->getShippingCarrier(); if ($carrier instanceof Swisspost_YellowCube_Model_Shipping_Carrier_Rate && $shipment->getOrder()->getIsInProcess()) { Mage::getModel('shipping/shipping')->requestToShipment($shipment); } return $this; }
public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer) { Mage::getModel('aramexshipping/shipping')->prepareShipment($observer->getShipment(), 'neutral'); }
/** * Check if insurance is choosen but not possible. * * @param Varien_Event_Observer $observer * * @return boolean */ protected function _checkInsuranceOfMassActionShipment($observer) { $amount = 0; foreach ($observer->getShipment()->getItemsCollection() as $item) { $amount += (double) $item->getPrice() * (double) $item->getQty(); } return (double) $amount <= (double) Dhl_Intraship_Model_Shipment::INSURANCE_A; }