function execute($process, $event) { $ini = eZINI::instance('workflow.ini'); $cost = $ini->variable("SimpleShippingWorkflow", "ShippingCost"); $description = $ini->variable("SimpleShippingWorkflow", "ShippingDescription"); $parameters = $process->attribute('parameter_list'); if (isset($parameters['order_id'])) { $orderID = $parameters['order_id']; $order = eZOrder::fetch($orderID); $orderItems = $order->attribute('order_items'); $addShipping = true; foreach ($orderItems as $orderItem) { if ($orderItem->attribute('type') == 'ezsimpleshipping') { $addShipping = false; break; } } if ($addShipping) { $productCollection = $order->attribute('productcollection'); $orderCurrency = $productCollection->attribute('currency_code'); $cost = eZShopFunctions::convertAdditionalPrice($orderCurrency, $cost); $orderItem = new eZOrderItem(array('order_id' => $orderID, 'description' => $description, 'price' => $cost, 'type' => 'ezsimpleshipping')); $orderItem->store(); } } return eZWorkflowType::STATUS_ACCEPTED; }
function handleShipping($orderID) { do { $order = eZOrder::fetch($orderID); if (!$order) { break; } $productCollectionID = $order->attribute('productcollection_id'); $shippingInfo = eZShippingManager::getShippingInfo($productCollectionID); if (!isset($shippingInfo)) { break; } // check if the order item has been added before. $orderItems = $order->orderItemsByType('ezcustomshipping'); // If orderitems allready exists, remove them first. if ($orderItems) { foreach ($orderItems as $orderItem) { $orderItem->remove(); } $purgeStatus = eZShippingManager::purgeShippingInfo($productCollectionID); } if (isset($shippingInfo['shipping_items']) and is_array($shippingInfo['shipping_items'])) { // Add a new order item for each shipping. foreach ($shippingInfo['shipping_items'] as $orderItemShippingInfo) { $orderItem = new eZOrderItem(array('order_id' => $orderID, 'description' => $orderItemShippingInfo['description'], 'price' => $orderItemShippingInfo['cost'], 'vat_value' => $orderItemShippingInfo['vat_value'], 'is_vat_inc' => $orderItemShippingInfo['is_vat_inc'], 'type' => 'ezcustomshipping')); $orderItem->store(); } } else { // Made for backwards compability, if the array order_items are not supplied. if (!isset($shippingInfo['vat_value'])) { $shippingInfo['vat_value'] = 0; } if (!isset($shippingInfo['is_vat_inc'])) { $shippingInfo['is_vat_inc'] = 1; } $orderItem = new eZOrderItem(array('order_id' => $orderID, 'description' => $shippingInfo['description'], 'price' => $shippingInfo['cost'], 'vat' => $shippingInfo['vat_value'], 'is_vat_inc' => $shippingInfo['is_vat_inc'], 'type' => 'ezcustomshipping')); $orderItem->store(); } } while (false); return array('status' => eZModuleOperationInfo::STATUS_CONTINUE); }