Example #1
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_localpickup')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_localpickup'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $store = ConfigQuery::create();
                 $country = CountryQuery::create()->findPk($store->read("store_country"));
                 $country = CountryI18nQuery::create()->filterById($country->getId())->findOneByLocale($order->getLang()->getLocale())->getTitle();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('store_name', $store->read("store_name"));
                 $this->parser->assign('store_address1', $store->read("store_address1"));
                 $this->parser->assign('store_address2', $store->read("store_address2"));
                 $this->parser->assign('store_address3', $store->read("store_address3"));
                 $this->parser->assign('store_zipcode', $store->read("store_zipcode"));
                 $this->parser->assign('store_city', $store->read("store_city"));
                 $this->parser->assign('store_country', $country);
                 $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->getMailer()->send($instance);
             }
         }
     }
 }
Example #2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see CountryI18n::setDeleted()
  * @see CountryI18n::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(CountryI18nTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCountryI18nQuery::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;
     }
 }
Example #3
0
 /**
  * Performs an INSERT on the database, given a CountryI18n or Criteria object.
  *
  * @param mixed               $criteria Criteria or CountryI18n 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(CountryI18nTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from CountryI18n object
     }
     // Set the correct dbName
     $query = CountryI18nQuery::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;
 }
Example #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);
     }
 }
Example #5
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    ChildCountry The current object (for fluent API support)
  */
 public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!$this->isNew()) {
         ChildCountryI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->delete($con);
     }
     if (isset($this->currentTranslations[$locale])) {
         unset($this->currentTranslations[$locale]);
     }
     foreach ($this->collCountryI18ns as $key => $translation) {
         if ($translation->getLocale() == $locale) {
             unset($this->collCountryI18ns[$key]);
             break;
         }
     }
     return $this;
 }
Example #6
0
 /**
  * @param $id_country_thelia_1
  * @return Country
  * @throws ImportException
  */
 public function getT2Country($id_country_thelia_1)
 {
     if ($id_country_thelia_1 == 0) {
         //Avoid to throw an exception for unknown country
         //set it to France
         $id_country_thelia_1 = self::COUNTRY_FALLBACK;
     }
     if (!isset($this->country_cache[$id_country_thelia_1])) {
         $id = $id_country_thelia_1;
         $country = null;
         try {
             $obj = $this->t1db->query_obj("select isoalpha3 from pays where id=?", array($id_country_thelia_1));
         } catch (\Exception $ex) {
             $obj = false;
         }
         if ($obj == false) {
             $obj = $this->t1db->query_obj("select pays, titre from paysdesc where pays=? and lang=1", array($id_country_thelia_1));
             if ($obj == false) {
                 throw new ImportException(Translator::getInstance()->trans("Failed to find a Thelia 1 country for id '%id'", array("%id" => $id_country_thelia_1), ImportT1::DOMAIN));
             }
             $id = $obj->pays;
             if (null === ($countryI18n = CountryI18nQuery::create()->filterByLocale('fr_FR')->findOneByTitle("{$obj->titre}%"))) {
                 throw new ImportException(Translator::getInstance()->trans("Failed to find a Thelia 1 country for '%title'", array("%title" => $obj->titre), ImportT1::DOMAIN));
             }
             $country = CountryQuery::create()->findPk($countryI18n->getId());
         } else {
             // Get the T2 country
             $country = CountryQuery::create()->findOneByIsoalpha3($obj->isoalpha3);
         }
         if ($country == null) {
             throw new ImportException(Translator::getInstance()->trans("Failed to find a Thelia 2 country for Thelia 1 country '%id'", array("%id" => $id), ImportT1::DOMAIN));
         }
         $this->country_cache[$id_country_thelia_1] = $country;
     }
     return $this->country_cache[$id_country_thelia_1];
 }