Esempio n. 1
0
 /**
  * Remove the translation for a given locale
  *
  * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
  * @param     ConnectionInterface $con an optional connection object
  *
  * @return    ChildCustomerTitle The current object (for fluent API support)
  */
 public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!$this->isNew()) {
         ChildCustomerTitleI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->delete($con);
     }
     if (isset($this->currentTranslations[$locale])) {
         unset($this->currentTranslations[$locale]);
     }
     foreach ($this->collCustomerTitleI18ns as $key => $translation) {
         if ($translation->getLocale() == $locale) {
             unset($this->collCustomerTitleI18ns[$key]);
             break;
         }
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see CustomerTitleI18n::setDeleted()
  * @see CustomerTitleI18n::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(CustomerTitleI18nTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCustomerTitleI18nQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * @param FormEvent $event
  *
  * This methods loads current title data into the update form.
  * It uses an event to load only needed ids.
  */
 public function hydrateUpdateForm(FormEvent $event)
 {
     $data = $event->getData();
     $title = CustomerTitleQuery::create()->findPk($data["title_id"]);
     if (null === $title) {
         $this->entityNotFound($data["title_id"]);
     }
     $data["default"] |= (bool) $title->getByDefault();
     $titleI18ns = CustomerTitleI18nQuery::create()->filterById($data["title_id"])->find()->toKeyIndex('Locale');
     $i18n =& $data["i18n"];
     foreach ($data["i18n"] as $key => $value) {
         $i18n[$value["locale"]] = $value;
         unset($i18n[$key]);
     }
     /** @var \Thelia\Model\CustomerTitleI18n $titleI18n */
     foreach ($titleI18ns as $titleI18n) {
         $row = array();
         $row["locale"] = $locale = $titleI18n->getLocale();
         $row["short"] = $titleI18n->getShort();
         $row["long"] = $titleI18n->getLong();
         if (!isset($i18n[$locale])) {
             $i18n[$locale] = array();
         }
         $i18n[$locale] = array_merge($row, $i18n[$locale]);
     }
     $event->setData($data);
 }
Esempio n. 4
0
 public function testQuery()
 {
     new Translator(new Container());
     $handler = new CustomerExport(new Container());
     $lang = Lang::getDefaultLanguage();
     $data = $handler->buildData($lang);
     $keys = ["ref", "title", "last_name", "first_name", "email", "label", "discount", "is_registered_to_newsletter", "sign_up_date", "total_orders", "last_order_amount", "last_order_date", "address_first_name", "address_last_name", "company", "address1", "address2", "address3", "zipcode", "city", "country", "phone", "cellphone", "is_default_address", "address_title"];
     sort($keys);
     $rawData = $data->getData();
     $max = CustomerQuery::create()->count();
     /**
      * 30 customers that has more than 1 addresses or enough
      */
     if (30 < $max) {
         $max = 30;
     }
     for ($i = 0; $i < $max;) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         sort($rowKeys);
         $this->assertEquals($rowKeys, $keys);
         $customer = CustomerQuery::create()->findOneByRef($row["ref"]);
         $this->assertNotNull($customer);
         $this->assertEquals($customer->getFirstname(), $row["first_name"]);
         $this->assertEquals($customer->getLastname(), $row["last_name"]);
         $this->assertEquals($customer->getEmail(), $row["email"]);
         $this->assertEquals($customer->getCreatedAt()->format($lang->getDatetimeFormat()), $row["sign_up_date"]);
         $this->assertEquals($customer->getDiscount(), $row["discount"]);
         $title = CustomerTitleQuery::create()->findPk($customer->getTitleId());
         $this->assertEquals($title->getShort(), $row["title"]);
         $total = 0;
         foreach ($customer->getOrders() as $order) {
             $amount = $order->getTotalAmount($tax);
             if (0 < ($rate = $order->getCurrencyRate())) {
                 $amount = round($amount / $rate, 2);
             }
             $total += $amount;
         }
         $defaultCurrencyCode = Currency::getDefaultCurrency()->getCode();
         $this->assertEquals($total . " " . $defaultCurrencyCode, $row["total_orders"]);
         $lastOrder = OrderQuery::create()->filterByCustomer($customer)->orderByCreatedAt(Criteria::DESC)->orderById(Criteria::DESC)->findOne();
         if (null !== $lastOrder) {
             $expectedPrice = $lastOrder->getTotalAmount($tax_) . " " . $lastOrder->getCurrency()->getCode();
             $expectedDate = $lastOrder->getCreatedAt()->format($lang->getDatetimeFormat());
         } else {
             $expectedPrice = "";
             $expectedDate = "";
         }
         $this->assertEquals($expectedPrice, $row["last_order_amount"]);
         $this->assertEquals($expectedDate, $row["last_order_date"]);
         $newsletter = NewsletterQuery::create()->findOneByEmail($customer->getEmail());
         $this->assertEquals($newsletter === null ? 0 : 1, $row["is_registered_to_newsletter"]);
         do {
             $address = AddressQuery::create()->filterByCustomer($customer)->filterByAddress1($rawData[$i]["address1"])->filterByAddress2($rawData[$i]["address2"])->filterByAddress3($rawData[$i]["address3"])->filterByFirstname($rawData[$i]["address_first_name"])->filterByLastname($rawData[$i]["address_last_name"])->filterByCountryId(CountryI18nQuery::create()->filterByLocale($lang->getLocale())->findOneByTitle($rawData[$i]["country"])->getId())->filterByCompany($rawData[$i]["company"])->_if(empty($rawData[$i]["company"]))->_or()->filterByCompany(null, Criteria::ISNULL)->_endif()->filterByZipcode($rawData[$i]["zipcode"])->filterByCity($rawData[$i]["city"])->filterByIsDefault($rawData[$i]["is_default_address"])->filterByCellphone($rawData[$i]["cellphone"])->_if(empty($rawData[$i]["cellphone"]))->_or()->filterByCellphone(null, Criteria::ISNULL)->_endif()->filterByPhone($rawData[$i]["phone"])->_if(empty($rawData[$i]["phone"]))->_or()->filterByPhone(null, Criteria::ISNULL)->_endif()->filterByLabel($rawData[$i]["label"])->_if(empty($rawData[$i]["label"]))->_or()->filterByLabel(null, Criteria::ISNULL)->_endif()->filterByTitleId(CustomerTitleI18nQuery::create()->filterByLocale($lang->getLocale())->findOneByShort($rawData[$i]["address_title"])->getId())->findOne();
             $this->assertNotNull($address);
             $rowKeys = array_keys($rawData[$i]);
             sort($rowKeys);
             $this->assertEquals($rowKeys, $keys);
         } while (isset($rawData[++$i]["ref"]) && $rawData[$i - 1]["ref"] === $rawData[$i]["ref"] && ++$max);
     }
 }
 /**
  * Performs an INSERT on the database, given a CustomerTitleI18n or Criteria object.
  *
  * @param mixed               $criteria Criteria or CustomerTitleI18n object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(CustomerTitleI18nTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from CustomerTitleI18n object
     }
     // Set the correct dbName
     $query = CustomerTitleI18nQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
Esempio n. 6
0
 public function export()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('FreeShipping'), 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(FreeShipping::getModuleId())->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 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(), $customer->getEmail(), $weight, $store_name)));
                 /**
                  * 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"));
 }
Esempio n. 7
0
 /**
  * @param $id_title_thelia_1
  * @return CustomerTitle
  * @throws ImportException
  */
 public function getT2CustomerTitle($id_title_thelia_1)
 {
     $title = null;
     if (!isset($this->title_cache[$id_title_thelia_1])) {
         try {
             $obj = $this->t1db->query_obj("select * from raisondesc where raison=? limit 1", array($id_title_thelia_1));
             if ($obj == false) {
                 throw new ImportException(Translator::getInstance()->trans("Failed to find a Thelia 1 customer title for id '%id'", array("%id" => $id_title_thelia_1), ImportT1::DOMAIN));
             }
             // Find the T1 object lang
             $lang = $this->getT2Lang($obj->lang);
             // Get the T2 title for this lang
             $title = CustomerTitleI18nQuery::create()->filterByLocale($lang->getLocale())->findOneByShort($obj->court);
             if ($title === null) {
                 throw new ImportException(Translator::getInstance()->trans("Failed to find a Thelia 2 customer title for Thelia 1 short title '%title'", array("%title" => $obj->court), ImportT1::DOMAIN));
             }
         } catch (\Exception $ex) {
             if ($id_title_thelia_1 == 1 || $id_title_thelia_1 > 3) {
                 $title = CustomerTitleI18nQuery::create()->filterByLocale('fr_FR')->findOneByShort('Mme');
             } else {
                 if ($id_title_thelia_1 == 2) {
                     $title = CustomerTitleI18nQuery::create()->filterByLocale('fr_FR')->findOneByShort('Mlle');
                 } else {
                     if ($id_title_thelia_1 == 3) {
                         $title = CustomerTitleI18nQuery::create()->filterByLocale('fr_FR')->findOneByShort('M.');
                     }
                 }
             }
         }
         if ($title === null) {
             //Set a default title to avoid breaking the import script
             $title = CustomerTitleI18nQuery::create()->filterByLocale('fr_FR')->findOneByShort('M.');
         }
         $this->title_cache[$id_title_thelia_1] = $title;
     }
     return $this->title_cache[$id_title_thelia_1];
 }