public function updateStatus(OrderEvent $event) { $order = $event->getOrder(); $socolissimo = new SoColissimo(); if ($order->isSent() && $order->getDeliveryModuleId() == $socolissimo->getModuleModel()->getId()) { $contact_email = ConfigQuery::read('store_email'); if ($contact_email) { $message = MessageQuery::create()->filterByName('mail_socolissimo')->findOne(); if (false === $message) { throw new \Exception("Failed to load message 'order_confirmation'."); } $order = $event->getOrder(); $customer = $order->getCustomer(); $this->parser->assign('customer_id', $customer->getId()); $this->parser->assign('order_ref', $order->getRef()); $this->parser->assign('order_date', $order->getCreatedAt()); $this->parser->assign('update_date', $order->getUpdatedAt()); $this->parser->assign('package', $order->getDeliveryRef()); $message->setLocale($order->getLang()->getLocale()); $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name')); // Build subject and body $message->buildMessage($this->parser, $instance); $this->mailer->send($instance); } } }
/** * * in this function you add all the fields you need for your Form. * Form this you have to call add method on $this->formBuilder attribute : * * $this->formBuilder->add("name", "text") * ->add("email", "email", array( * "attr" => array( * "class" => "field" * ), * "label" => "email", * "constraints" => array( * new \Symfony\Component\Validator\Constraints\NotBlank() * ) * ) * ) * ->add('age', 'integer'); * * @return null */ protected function buildForm() { $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING, OrderStatus::CODE_SENT), Criteria::IN)->find()->toArray("code"); $query = OrderQuery::create()->filterByDeliveryModuleId(SoColissimo::getModCode())->filterByStatusId(array($status['paid']['Id'], $status['processing']['Id']), Criteria::IN)->find(); $this->formBuilder->add('new_status_id', 'choice', array('label' => Translator::getInstance()->trans('server'), 'choices' => array("nochange" => Translator::getInstance()->trans("Do not change"), "processing" => Translator::getInstance()->trans("Set orders status as processing"), "sent" => Translator::getInstance()->trans("Set orders status as sent")), 'required' => 'true', 'expanded' => true, 'multiple' => false, 'data' => 'nochange')); /** @var \Thelia\Model\Order $order */ foreach ($query as $order) { $this->formBuilder->add("order_" . $order->getId(), "checkbox", array('label' => $order->getRef(), 'label_attr' => array('for' => 'export_' . $order->getId()))); } }
public function buildArray() { $area = $this->getArea(); $prices = SoColissimo::getPrices(); if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) { return array(); } $areaPrices = $prices[$area]["slices"]; ksort($areaPrices); return $areaPrices; }
public function onInvoiceAfterDeliveryModule(HookRenderEvent $event) { // No So Colissimo information if the delivery module is not SoColissimo if (SoColissimo::getModuleId() == $event->getArgument('module_id')) { return; } $order = OrderQuery::create()->findOneById($event->getArgument('order')); if (!is_null($order)) { $event->add($this->render('delivery_mode_infos.html', ['delivery_address_id' => $order->getDeliveryOrderAddressId()])); } }
public function socolissimoDeliveryPrice($params, $smarty) { $deliveryMode = $params["delivery-mode"]; $country = CountryQuery::create()->findOneById($params["country"]); $cartWeight = $this->request->getSession()->getSessionCart($this->dispatcher)->getWeight(); $cartAmount = $this->request->getSession()->getSessionCart($this->dispatcher)->getTaxedAmount($country); try { $price = SoColissimo::getPostageAmount($country->getAreaId(), $cartWeight, $cartAmount, $deliveryMode); } catch (DeliveryException $ex) { $smarty->assign('isValidMode', false); } $smarty->assign('deliveryModePrice', $price); }
public function importAction() { $i = 0; $con = Propel::getWriteConnection(OrderTableMap::DATABASE_NAME); $con->beginTransaction(); $form = $this->createForm('socolissimo.import'); try { $vForm = $this->validateForm($form); // Get file $importedFile = $vForm->getData()['import_file']; // Check extension if (strtolower($importedFile->getClientOriginalExtension()) != 'csv') { throw new FormValidationException(Translator::getInstance()->trans('Bad file format. CSV expected.', [], SoColissimo::DOMAIN)); } $csvData = file_get_contents($importedFile); $lines = explode(PHP_EOL, $csvData); // For each line, parse columns foreach ($lines as $line) { $parsedLine = str_getcsv($line, ";"); // Check if there are 2 columns : delivery ref & order ref if (count($parsedLine) == SoColissimo::IMPORT_NB_COLS) { // Get delivery and order ref $deliveryRef = $parsedLine[SoColissimo::IMPORT_DELIVERY_REF_COL]; $orderRef = $parsedLine[SoColissimo::IMPORT_ORDER_REF_COL]; // Save delivery ref if there is one if (!empty($deliveryRef)) { $this->importDeliveryRef($deliveryRef, $orderRef, $i); } } } $con->commit(); // Get number of affected rows to display $this->getSession()->getFlashBag()->add('import-result', Translator::getInstance()->trans('Operation successful. %i orders affected.', ['%i' => $i], SoColissimo::DOMAIN)); // Redirect return $this->generateRedirect(URL::getInstance()->absoluteUrl($form->getSuccessUrl(), ['current_tab' => 'import'])); } catch (FormValidationException $e) { $con->rollback(); $this->setupFormErrorContext(null, $e->getMessage(), $form); return $this->render('module-configure', ['module_code' => SoColissimo::getModuleCode(), 'current_tab' => 'import']); } }
/** * this method returns a Propel ModelCriteria * * @return \Propel\Runtime\ActiveQuery\ModelCriteria */ public function buildModelCriteria() { $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING), Criteria::IN)->find()->toArray("code"); $query = OrderQuery::create()->filterByDeliveryModuleId(SoColissimo::getModCode())->filterByStatusId(array($status[OrderStatus::CODE_PAID]['Id'], $status[OrderStatus::CODE_PROCESSING]['Id']), Criteria::IN); return $query; }
public function export() { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE))) { return $response; } $csv = new CSV(self::CSV_SEPARATOR); try { $form = new ExportOrder($this->getRequest()); $vform = $this->validateForm($form); // Check status_id $status_id = $vform->get("new_status_id")->getData(); if (!preg_match("#^nochange|processing|sent\$#", $status_id)) { throw new Exception("Bad value for new_status_id field"); } $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING, OrderStatus::CODE_SENT), Criteria::IN)->find()->toArray("code"); $query = OrderQuery::create()->filterByDeliveryModuleId(SoColissimo::getModCode())->filterByStatusId(array($status[OrderStatus::CODE_PAID]['Id'], $status[OrderStatus::CODE_PROCESSING]['Id']), Criteria::IN)->find(); // check form && exec csv /** @var \Thelia\Model\Order $order */ foreach ($query as $order) { $value = $vform->get('order_' . $order->getId())->getData(); // If checkbox is checked if ($value) { /** * Retrieve user with the order */ $customer = $order->getCustomer(); /** * Retrieve address with the order */ $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId()); if ($address === null) { throw new Exception("Could not find the order's invoice address"); } /** * Retrieve country with the address */ $country = CountryQuery::create()->findPk($address->getCountryId()); if ($country === null) { throw new Exception("Could not find the order's country"); } /** * Retrieve Title */ $title = CustomerTitleI18nQuery::create()->filterById($customer->getTitleId())->findOneByLocale($this->getSession()->getAdminEditionLang()->getLocale()); /** * Get user's phone & cellphone * First get invoice address phone, * If empty, try to get default address' phone. * If still empty, set default value */ $phone = $address->getPhone(); if (empty($phone)) { $phone = $customer->getDefaultAddress()->getPhone(); if (empty($phone)) { $phone = self::DEFAULT_PHONE; } } /** * Cellp */ $cellphone = $customer->getDefaultAddress()->getCellphone(); if (empty($cellphone)) { $cellphone = self::DEFAULT_CELLPHONE; } /** * Compute package weight */ $weight = 0; /** @var \Thelia\Model\OrderProduct $product */ foreach ($order->getOrderProducts() as $product) { $weight += (double) $product->getWeight(); } /** * Get relay ID */ $relay_id = OrderAddressSocolissimoQuery::create()->findPk($order->getDeliveryOrderAddressId()); if ($relay_id === null) { throw new Exception("Invalid order " . $order->getRef() . ", no relay id found"); } /** * Get store's name */ $store_name = ConfigQuery::read("store_name"); /** * Write CSV line */ $csv->addLine(CSVLine::create(array($address->getFirstname(), $address->getLastname(), $address->getCompany(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $country->getIsoalpha2(), $phone, $cellphone, $order->getRef(), $title->getShort(), $relay_id->getCode() == 0 ? '' : $relay_id->getCode(), $customer->getEmail(), $weight, $store_name, $relay_id->getType()))); /** * Then update order's status if necessary */ if ($status_id == "processing") { $event = new OrderEvent($order); $event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']); $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); } elseif ($status_id == "sent") { $event = new OrderEvent($order); $event->setStatus($status[OrderStatus::CODE_SENT]['Id']); $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); } } } } catch (\Exception $e) { return Response::create($e->getMessage(), 500); } return Response::create(utf8_decode($csv->parse()), 200, array("Content-Encoding" => "ISO-8889-1", "Content-Type" => "application/csv-tab-delimited-table", "Content-disposition" => "filename=export.csv")); }
protected function check_module($id) { return $id == SoColissimo::getModCode(); }
/** * this method returns an array * * @return array */ public function buildArray() { return array(SoColissimo::getModCode()); }