public function delete_zetaprints_order($observer) { $order = $observer->getEvent()->getDataObject(); //Continue only on complete or canceled status of the order if (!($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE || $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED)) { return; } $url = Mage::getStoreConfig('webtoprint/settings/url'); $key = Mage::getStoreConfig('webtoprint/settings/key'); //For every item in the order foreach ($order->getAllItems() as $item) { $options = $item->getProductOptions(); //check if it's web-to-print product then continue if (!isset($options['info_buyRequest']['zetaprints-order-id'])) { continue; } $order_guid = $options['info_buyRequest']['zetaprints-order-id']; //receive current ZetaPrints order status (need it on next step) $order_details = zetaprints_get_order_details($url, $key, $order_guid); if (!$order_details) { continue; } $old_status = $order_details['status']; //change ZetaPrints order status to 'deleted' from current one zetaprints_change_order_status($url, $key, $order_guid, $old_status, 'deleted'); } }
public function completeZetaPrintsOrder($id) { $url = Mage::getStoreConfig('webtoprint/settings/url'); $key = Mage::getStoreConfig('webtoprint/settings/key'); //New GUID for completed order $newId = zetaprints_generate_guid(); $details = zetaprints_complete_order($url, $key, $id, $newId); if (!$details) { //_zetaprints_debug('Order wasn\'t completed ' // . "(old ID: {$id}, new ID: {$newId})"); //Check if saved order exists on ZetaPrints... if (zetaprints_get_order_details($url, $key, $id)) { //_zetaprints_debug('Order with old ID exists ' // . "(old ID: {$id}, new ID: {$newId})"); //... then try again to complete the order $details = zetaprints_complete_order($url, $key, $id, $newId); //If it fails... if (!$details) { //_zetaprints_debug('Order wasn\'t completed second time ' // . "(old ID: {$id}, new ID: {$newId})"); $message = $this->__('Use the link to ZP order to troubleshoot.'); //... then return error. return array('error' => true, 'message' => $message); } } else { if (!($details = zetaprints_get_order_details($url, $key, $newId))) { //_zetaprints_debug('Orders with old and new ID don\'t exist ' // . "(old ID: {$id}, new ID: {$newId})"); $message = $this->__('Failed order. Contact admin@zetaprints.com ASAP to resolve.'); //... then return error. return array('error' => true, 'message' => $message); } } } $data = array('error' => false, 'files' => array()); $types = array('pdf', 'gif', 'png', 'jpeg', 'cdr'); foreach ($types as $type) { if (strlen($details[$type])) { $data['files'][$type] = $url . '/' . $details[$type]; } } $data['id'] = $details['guid']; return $data; }