getFeature()->hasPro()) { return; } if(!array_key_exists($event, AmzFulfillment_Event::$events)) { AmzFulfillment_Core::debug('Event with invalid event id: ' . $event); return; } $eventName = AmzFulfillment_Event::$events[$event]['name']; $eventGroup = AmzFulfillment_Event::$events[$event]['group']; $message = sprintf('Order %d status update: %s', $orderId, $eventName); AmzFulfillment_Core::instance()->getLog()->add($message); if($eventGroup != 'WooCommerce') { AmzFulfillment_Core::instance()->getWooCommerce()->addNote($orderId, $message); } foreach($this->getActions($event) as $action) { $this->doAction($action, $orderId); } } /** * getActions * * @param string $event * @return string[] */ private function getActions($event) { $rules = new AmzFulfillment_Rules(); $rules->load(); return $rules->getActions($event); } /** * doAction * * @param string $action * @param int $orderId */ private function doAction($action, $orderId) { if(!array_key_exists($action, AmzFulfillment_Action::$actions)) { AmzFulfillment_Core::debug('Rule with invalid action id: ' . $action); return; } $actionName = AmzFulfillment_Action::$actions[$action]['name']; try { switch($action) { case AmzFulfillment_Action::WOOCOMMERCE_ORDER_PENDING: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::PENDING_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_PROCESSING: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::PROCESSING_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_ONHOLD: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::ONHOLD_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_COMPLETED: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::COMPLETED_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_CANCELLED: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::CANCELLED_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_REFUNDED: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::REFOUNDED_STATUS); break; case AmzFulfillment_Action::WOOCOMMERCE_ORDER_FAILED: AmzFulfillment_Core::instance()->getWooCommerce()->setStatus($orderId, AmzFulfillment_WooCommerce::FAILED_STATUS); break; case AmzFulfillment_Action::AMAZON_FULFILLMENT_CREATE: AmzFulfillment_Core::instance()->doAmazonFulfillment($orderId); break; case AmzFulfillment_Action::AMAZON_FULFILLMENT_CANCEL: AmzFulfillment_Core::instance()->cancelAmazonFulfillment($orderId); break; case AmzFulfillment_Action::MAIL_NOTIFY: AmzFulfillment_Core::instance()->sendNotification('Order has changed', sprintf('Order %d has changed %s', $orderId, $actionName)); break; } AmzFulfillment_Core::instance()->getLog()->add(sprintf("Triggered configured action %s for order %d", $actionName, $orderId)); } catch(Exception $e) { $message = sprintf("Error while executing configured action %s for order %d. Error: %s", $actionName, $orderId, $e->getMessage()); AmzFulfillment_Core::instance()->getLog()->add($message); AmzFulfillment_Core::debug($message); } } }