本文整理汇总了PHP中Thelia\Model\Lang::getLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Lang::getLocale方法的具体用法?PHP Lang::getLocale怎么用?PHP Lang::getLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thelia\Model\Lang
的用法示例。
在下文中一共展示了Lang::getLocale方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testQuery
public function testQuery()
{
$data = $this->handler->buildData($this->lang)->getData();
$max = count($data);
if ($max > 50) {
$max = 50;
}
for ($i = 0; $i < $max;) {
$content = ContentQuery::create()->findPk($data[$i]["id"]);
$this->assertNotNull($content);
$content->setLocale($this->lang->getLocale());
$this->assertEquals($content->getTitle(), $data[$i]["title"]);
$this->assertEquals($content->getDescription(), $data[$i]["description"]);
$this->assertEquals($content->getChapo(), $data[$i]["chapo"]);
$this->assertEquals($content->getPostscriptum(), $data[$i]["conclusion"]);
$this->assertEquals($content->getMetaTitle(), $data[$i]["seo_title"]);
$this->assertEquals($content->getMetaDescription(), $data[$i]["seo_description"]);
$this->assertEquals($content->getMetaKeywords(), $data[$i]["seo_keywords"]);
do {
if (null !== $data[$i]["folder_id"]) {
$folder = FolderQuery::create()->findPk($data[$i]["folder_id"]);
$this->assertNotNull($folder);
$contentFolder = ContentFolderQuery::create()->filterByContent($content)->filterByFolder($folder)->findOne();
$this->assertNotNull($contentFolder);
$folder->setLocale($this->lang->getLocale());
$this->assertEquals($folder->getTitle(), $data[$i]["folder_title"]);
$this->assertEquals($contentFolder->getDefaultFolder(), (bool) (int) $data[$i]["is_default_folder"]);
}
} while (isset($data[++$i]["id"]) && $data[$i - 1]["id"] === $data[$i]["id"] && ++$max);
}
}
示例2: buildDataSet
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria|\Thelia\Core\Template\Element\BaseLoop
*/
public function buildDataSet(Lang $lang)
{
$locale = $lang->getLocale();
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$attributeAvJoin = new Join(AttributeAvTableMap::ID, AttributeAvI18nTableMap::ID, Criteria::LEFT_JOIN);
$query = AttributeCombinationQuery::create()->useProductSaleElementsQuery()->useProductPriceQuery()->useCurrencyQuery()->addAsColumn("currency_CODE", CurrencyTableMap::CODE)->endUse()->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)->endUse()->useProductQuery()->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_ID", ProductTableMap::ID)->endUse()->addAsColumn("product_sale_elements_REF", ProductSaleElementsTableMap::REF)->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)->endUse()->useAttributeAvQuery()->addJoinObject($attributeAvJoin, "attribute_av_join")->addJoinCondition("attribute_av_join", AttributeAvI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("attribute_av_i18n_ATTRIBUTES", "GROUP_CONCAT(DISTINCT " . AttributeAvI18nTableMap::TITLE . ")")->endUse()->select(["product_sale_elements_REF", "product_sale_elements_EAN_CODE", "product_sale_elements_PROMO", "price_PRICE", "price_PROMO_PRICE", "currency_CODE", "product_TITLE", "attribute_av_i18n_ATTRIBUTES"])->groupBy("product_sale_elements_REF");
return $query;
}
示例3: getQuery
/**
* @return ContentQuery
*/
public function getQuery(Lang $lang)
{
$locale = $lang->getLocale();
$contentI18nJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
$folderI18nJoin = new Join(FolderTableMap::ID, FolderI18nTableMap::ID, Criteria::LEFT_JOIN);
$urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$query = ContentQuery::create()->select([ContentTableMap::ID, ContentTableMap::VISIBLE, "content_TITLE", "content_CHAPO", "content_DESCRIPTION", "content_CONCLUSION", "content_seo_TITLE", "content_seo_DESCRIPTION", "content_seo_KEYWORDS", "url_URL", "folder_TITLE", "folder_ID", "folder_IS_DEFAULT"])->_if($this->isImageExport())->useContentImageQuery("content_image_join", Criteria::LEFT_JOIN)->addAsColumn("content_IMAGES", "GROUP_CONCAT(DISTINCT `content_image_join`.FILE)")->addSelectColumn("content_IMAGES")->groupByContentId()->endUse()->_endif()->_if($this->isDocumentExport())->useContentDocumentQuery("content_document_join", Criteria::LEFT_JOIN)->addAsColumn("content_DOCUMENTS", "GROUP_CONCAT(DISTINCT `content_document_join`.FILE)")->addSelectColumn("content_DOCUMENTS")->groupByContentId()->endUse()->_endif()->useContentFolderQuery(null, Criteria::LEFT_JOIN)->useFolderQuery(null, Criteria::LEFT_JOIN)->_if($this->isDocumentExport())->useFolderDocumentQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_DOCUMENTS", "GROUP_CONCAT(DISTINCT " . FolderDocumentTableMap::FILE . ")")->addSelectColumn("folder_DOCUMENTS")->endUse()->_endif()->_if($this->isImageExport())->useFolderImageQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_IMAGES", "GROUP_CONCAT(DISTINCT " . FolderImageTableMap::FILE . ")")->addSelectColumn("folder_IMAGES")->endUse()->_endif()->addJoinObject($folderI18nJoin, "folder_i18n_join")->addJoinCondition("folder_i18n_join", FolderI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("folder_TITLE", FolderI18nTableMap::TITLE)->addAsColumn("folder_ID", FolderTableMap::ID)->endUse()->addAsColumn("folder_IS_DEFAULT", ContentFolderTableMap::DEFAULT_FOLDER)->endUse()->addJoinObject($contentI18nJoin, "content_i18n_join")->addJoinCondition("content_i18n_join", ContentI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)->addAsColumn("content_CHAPO", ContentI18nTableMap::CHAPO)->addAsColumn("content_DESCRIPTION", ContentI18nTableMap::DESCRIPTION)->addAsColumn("content_CONCLUSION", ContentI18nTableMap::POSTSCRIPTUM)->addAsColumn("content_seo_TITLE", ContentI18nTableMap::META_TITLE)->addAsColumn("content_seo_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)->addAsColumn("content_seo_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)->addJoinObject($urlJoin, "url_rewriting_join")->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW . " = ?", (new Content())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("url_URL", RewritingUrlTableMap::URL)->groupBy(ContentTableMap::ID)->groupBy("folder_ID")->orderById();
return $query;
}
示例4: buildDataSet
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildDataSet(Lang $lang)
{
$locale = $this->locale = $lang->getLocale();
$query = ProductQuery::create();
$urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$query->addJoinObject($urlJoin, "rewriting_url_join")->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW . " = ?", (new Product())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", "ISNULL(" . RewritingUrlTableMap::REDIRECTED . ")")->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR);
$query->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_REF", ProductTableMap::REF)->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)->addAsColumn("product_seo_TITLE", ProductI18nTableMap::META_TITLE)->addAsColumn("product_seo_META_DESCRIPTION", ProductI18nTableMap::META_DESCRIPTION)->addAsColumn("product_seo_META_KEYWORDS", ProductI18nTableMap::META_KEYWORDS)->addAsColumn("product_URL", RewritingUrlTableMap::URL)->select(["product_REF", "product_VISIBLE", "product_i18n_TITLE", "product_URL", "product_seo_TITLE", "product_seo_META_DESCRIPTION", "product_seo_META_KEYWORDS"]);
return $query;
}
示例5: getQuery
protected function getQuery(Lang $lang)
{
$locale = $lang->getLocale();
$query = OrderQuery::create()->useCurrencyQuery()->addAsColumn("currency_CODE", CurrencyTableMap::CODE)->endUse()->useCustomerQuery()->addAsColumn("customer_REF", CustomerTableMap::REF)->endUse()->useOrderProductQuery()->useOrderProductTaxQuery(null, Criteria::LEFT_JOIN)->addAsColumn("product_TAX", "IF(" . OrderProductTableMap::WAS_IN_PROMO . "," . "SUM(" . OrderProductTaxTableMap::PROMO_AMOUNT . ")," . "SUM(" . OrderProductTaxTableMap::AMOUNT . ")" . ")")->addAsColumn("tax_TITLE", OrderProductTableMap::TAX_RULE_TITLE)->endUse()->addAsColumn("product_TITLE", OrderProductTableMap::TITLE)->addAsColumn("product_PRICE", "IF(" . OrderProductTableMap::WAS_IN_PROMO . "," . OrderProductTableMap::PROMO_PRICE . "," . OrderProductTableMap::PRICE . ")")->addAsColumn("product_QUANTITY", OrderProductTableMap::QUANTITY)->addAsColumn("product_WAS_IN_PROMO", OrderProductTableMap::WAS_IN_PROMO)->groupById()->endUse()->orderById()->groupById()->useOrderCouponQuery(null, Criteria::LEFT_JOIN)->addAsColumn("coupon_COUPONS", "GROUP_CONCAT(" . OrderCouponTableMap::TITLE . ")")->groupBy(OrderCouponTableMap::ORDER_ID)->endUse()->useModuleRelatedByPaymentModuleIdQuery("payment_module")->addAsColumn("payment_module_TITLE", "`payment_module`.CODE")->endUse()->useModuleRelatedByDeliveryModuleIdQuery("delivery_module")->addAsColumn("delivery_module_TITLE", "`delivery_module`.CODE")->endUse()->useOrderAddressRelatedByDeliveryOrderAddressIdQuery("delivery_address_join")->useCustomerTitleQuery("delivery_address_customer_title_join")->useCustomerTitleI18nQuery("delivery_address_customer_title_i18n_join")->addAsColumn("delivery_address_TITLE", "`delivery_address_customer_title_i18n_join`.SHORT")->endUse()->endUse()->useCountryQuery("delivery_address_country_join")->useCountryI18nQuery("delivery_address_country_i18n_join")->addAsColumn("delivery_address_country_TITLE", "`delivery_address_country_i18n_join`.TITLE")->endUse()->addAsColumn("delivery_address_COMPANY", "`delivery_address_join`.COMPANY")->addAsColumn("delivery_address_FIRSTNAME", "`delivery_address_join`.FIRSTNAME")->addAsColumn("delivery_address_LASTNAME", "`delivery_address_join`.LASTNAME")->addAsColumn("delivery_address_ADDRESS1", "`delivery_address_join`.ADDRESS1")->addAsColumn("delivery_address_ADDRESS2", "`delivery_address_join`.ADDRESS2")->addAsColumn("delivery_address_ADDRESS3", "`delivery_address_join`.ADDRESS3")->addAsColumn("delivery_address_ZIPCODE", "`delivery_address_join`.ZIPCODE")->addAsColumn("delivery_address_CITY", "`delivery_address_join`.CITY")->addAsColumn("delivery_address_PHONE", "`delivery_address_join`.PHONE")->endUse()->endUse()->useOrderAddressRelatedByInvoiceOrderAddressIdQuery("invoice_address_join")->useCustomerTitleQuery("invoice_address_customer_title_join")->useCustomerTitleI18nQuery("invoice_address_customer_title_i18n_join")->addAsColumn("invoice_address_TITLE", "`invoice_address_customer_title_i18n_join`.SHORT")->endUse()->endUse()->useCountryQuery("invoice_address_country_join")->useCountryI18nQuery("invoice_address_country_i18n_join")->addAsColumn("invoice_address_country_TITLE", "`invoice_address_country_i18n_join`.TITLE")->endUse()->endUse()->addAsColumn("invoice_address_COMPANY", "`invoice_address_join`.COMPANY")->addAsColumn("invoice_address_FIRSTNAME", "`invoice_address_join`.FIRSTNAME")->addAsColumn("invoice_address_LASTNAME", "`invoice_address_join`.LASTNAME")->addAsColumn("invoice_address_ADDRESS1", "`invoice_address_join`.ADDRESS1")->addAsColumn("invoice_address_ADDRESS2", "`invoice_address_join`.ADDRESS2")->addAsColumn("invoice_address_ADDRESS3", "`invoice_address_join`.ADDRESS3")->addAsColumn("invoice_address_ZIPCODE", "`invoice_address_join`.ZIPCODE")->addAsColumn("invoice_address_CITY", "`invoice_address_join`.CITY")->addAsColumn("invoice_address_PHONE", "`invoice_address_join`.PHONE")->endUse()->useOrderStatusQuery()->useOrderStatusI18nQuery()->addAsColumn("order_status_TITLE", OrderStatusI18nTableMap::TITLE)->endUse()->endUse()->select([OrderTableMap::REF, "customer_REF", "product_TITLE", "product_PRICE", "product_TAX", "tax_TITLE", "product_QUANTITY", "product_WAS_IN_PROMO", OrderTableMap::DISCOUNT, "coupon_COUPONS", OrderTableMap::POSTAGE, "payment_module_TITLE", OrderTableMap::INVOICE_REF, OrderTableMap::DELIVERY_REF, "delivery_module_TITLE", "delivery_address_TITLE", "delivery_address_COMPANY", "delivery_address_FIRSTNAME", "delivery_address_LASTNAME", "delivery_address_ADDRESS1", "delivery_address_ADDRESS2", "delivery_address_ADDRESS3", "delivery_address_ZIPCODE", "delivery_address_CITY", "delivery_address_country_TITLE", "delivery_address_PHONE", "invoice_address_TITLE", "invoice_address_COMPANY", "invoice_address_FIRSTNAME", "invoice_address_LASTNAME", "invoice_address_ADDRESS1", "invoice_address_ADDRESS2", "invoice_address_ADDRESS3", "invoice_address_ZIPCODE", "invoice_address_CITY", "invoice_address_country_TITLE", "invoice_address_PHONE", "order_status_TITLE", "currency_CODE", OrderTableMap::CREATED_AT])->orderByCreatedAt(Criteria::DESC);
I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`delivery_address_customer_title_join`.ID", CustomerTitleI18nTableMap::ID, "`delivery_address_customer_title_i18n_join`.LOCALE", $locale);
I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`invoice_address_customer_title_join`.ID", CustomerTitleI18nTableMap::ID, "`invoice_address_customer_title_i18n_join`.LOCALE", $locale);
I18n::addI18nCondition($query, CountryI18nTableMap::TABLE_NAME, "`delivery_address_country_join`.ID", CountryI18nTableMap::ID, "`delivery_address_country_i18n_join`.LOCALE", $locale);
I18n::addI18nCondition($query, CountryI18nTableMap::TABLE_NAME, "`invoice_address_country_join`.ID", CountryI18nTableMap::ID, "`invoice_address_country_i18n_join`.LOCALE", $locale);
I18n::addI18nCondition($query, OrderStatusI18nTableMap::TABLE_NAME, OrderStatusI18nTableMap::ID, OrderStatusTableMap::ID, OrderStatusI18nTableMap::LOCALE, $locale);
return $query;
}
示例6: createOrder
/**
* @param EventDispatcherInterface $dispatcher
* @param ModelOrder $sessionOrder
* @param CurrencyModel $currency
* @param LangModel $lang
* @param CartModel $cart
* @param UserInterface $customer
* @param bool $manageStock decrement stock when order is created if true
* @return ModelOrder
* @throws \Exception
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, LangModel $lang, CartModel $cart, UserInterface $customer, $manageStock)
{
$con = Propel::getConnection(OrderTableMap::DATABASE_NAME);
$con->beginTransaction();
$placedOrder = $sessionOrder->copy();
$placedOrder->setDispatcher($dispatcher);
$deliveryAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenDeliveryAddress());
$taxCountry = $deliveryAddress->getCountry();
$invoiceAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenInvoiceAddress());
$cartItems = $cart->getCartItems();
/* fulfill order */
$placedOrder->setCustomerId($customer->getId());
$placedOrder->setCurrencyId($currency->getId());
$placedOrder->setCurrencyRate($currency->getRate());
$placedOrder->setLangId($lang->getId());
/* hard save the delivery and invoice addresses */
$deliveryOrderAddress = new OrderAddress();
$deliveryOrderAddress->setCustomerTitleId($deliveryAddress->getTitleId())->setCompany($deliveryAddress->getCompany())->setFirstname($deliveryAddress->getFirstname())->setLastname($deliveryAddress->getLastname())->setAddress1($deliveryAddress->getAddress1())->setAddress2($deliveryAddress->getAddress2())->setAddress3($deliveryAddress->getAddress3())->setZipcode($deliveryAddress->getZipcode())->setCity($deliveryAddress->getCity())->setPhone($deliveryAddress->getPhone())->setCountryId($deliveryAddress->getCountryId())->save($con);
$invoiceOrderAddress = new OrderAddress();
$invoiceOrderAddress->setCustomerTitleId($invoiceAddress->getTitleId())->setCompany($invoiceAddress->getCompany())->setFirstname($invoiceAddress->getFirstname())->setLastname($invoiceAddress->getLastname())->setAddress1($invoiceAddress->getAddress1())->setAddress2($invoiceAddress->getAddress2())->setAddress3($invoiceAddress->getAddress3())->setZipcode($invoiceAddress->getZipcode())->setCity($invoiceAddress->getCity())->setPhone($invoiceAddress->getPhone())->setCountryId($invoiceAddress->getCountryId())->save($con);
$placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId());
$placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId());
$placedOrder->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId());
$placedOrder->setCartId($cart->getId());
/* memorize discount */
$placedOrder->setDiscount($cart->getDiscount());
$placedOrder->save($con);
/* fulfill order_products and decrease stock */
foreach ($cartItems as $cartItem) {
$product = $cartItem->getProduct();
/* get translation */
/** @var ProductI18n $productI18n */
$productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId());
$pse = $cartItem->getProductSaleElements();
// get the virtual document path
$virtualDocumentEvent = new VirtualProductOrderHandleEvent($placedOrder, $pse->getId());
// essentially used for virtual product. modules that handles virtual product can
// allow the use of stock even for virtual products
$useStock = true;
$virtual = 0;
// if the product is virtual, dispatch an event to collect information
if ($product->getVirtual() === 1) {
$dispatcher->dispatch(TheliaEvents::VIRTUAL_PRODUCT_ORDER_HANDLE, $virtualDocumentEvent);
$useStock = $virtualDocumentEvent->isUseStock();
$virtual = $virtualDocumentEvent->isVirtual() ? 1 : 0;
}
/* check still in stock */
if ($cartItem->getQuantity() > $pse->getQuantity() && true === ConfigQuery::checkAvailableStock() && $useStock) {
throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem);
}
if ($useStock && $manageStock) {
/* decrease stock for non virtual product */
$allowNegativeStock = intval(ConfigQuery::read('allow_negative_stock', 0));
$newStock = $pse->getQuantity() - $cartItem->getQuantity();
//Forbid negative stock
if ($newStock < 0 && 0 === $allowNegativeStock) {
$newStock = 0;
}
$pse->setQuantity($newStock);
$pse->save($con);
}
/* get tax */
/** @var TaxRuleI18n $taxRuleI18n */
$taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId());
$taxDetail = $product->getTaxRule()->getTaxDetail($product, $taxCountry, $cartItem->getPrice(), $cartItem->getPromoPrice(), $lang->getLocale());
$orderProduct = new OrderProduct();
$orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($productI18n->getTitle())->setChapo($productI18n->getChapo())->setDescription($productI18n->getDescription())->setPostscriptum($productI18n->getPostscriptum())->setVirtual($virtual)->setVirtualDocument($virtualDocumentEvent->getPath())->setQuantity($cartItem->getQuantity())->setPrice($cartItem->getPrice())->setPromoPrice($cartItem->getPromoPrice())->setWasNew($pse->getNewness())->setWasInPromo($cartItem->getPromo())->setWeight($pse->getWeight())->setTaxRuleTitle($taxRuleI18n->getTitle())->setTaxRuleDescription($taxRuleI18n->getDescription())->setEanCode($pse->getEanCode())->setCartItemId($cartItem->getId())->setDispatcher($dispatcher)->save($con);
/* fulfill order_product_tax */
/** @var OrderProductTax $tax */
foreach ($taxDetail as $tax) {
$tax->setOrderProductId($orderProduct->getId());
$tax->save($con);
}
/* fulfill order_attribute_combination and decrease stock */
foreach ($pse->getAttributeCombinations() as $attributeCombination) {
/** @var \Thelia\Model\Attribute $attribute */
$attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId());
/** @var \Thelia\Model\AttributeAv $attributeAv */
$attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId());
$orderAttributeCombination = new OrderProductAttributeCombination();
$orderAttributeCombination->setOrderProductId($orderProduct->getId())->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save($con);
}
}
$con->commit();
return $placedOrder;
}
示例7: buildDataSet
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*
* The tax engine of Thelia is in PHP, so we can't compute orders for each customers
* directly in SQL, we need two SQL queries, and some computing to get the last order amount and total amount.
*/
public function buildDataSet(Lang $lang)
{
$locale = $lang->getLocale();
/**
* This first query get each customer info and addresses.
*/
$newsletterJoin = new Join(CustomerTableMap::EMAIL, NewsletterTableMap::EMAIL, Criteria::LEFT_JOIN);
$query = CustomerQuery::create()->useCustomerTitleQuery("customer_title_")->useCustomerTitleI18nQuery("customer_title_i18n_")->addAsColumn("title_TITLE", "customer_title_i18n_.SHORT")->endUse()->endUse()->useAddressQuery()->useCountryQuery()->useCountryI18nQuery()->addAsColumn("address_COUNTRY", CountryI18nTableMap::TITLE)->endUse()->endUse()->useCustomerTitleQuery("address_title")->useCustomerTitleI18nQuery("address_title_i18n")->addAsColumn("address_TITLE", "address_title_i18n.SHORT")->endUse()->endUse()->addAsColumn("address_LABEL", AddressTableMap::LABEL)->addAsColumn("address_FIRST_NAME", AddressTableMap::FIRSTNAME)->addAsColumn("address_LAST_NAME", AddressTableMap::LASTNAME)->addAsColumn("address_COMPANY", AddressTableMap::COMPANY)->addAsColumn("address_ADDRESS1", AddressTableMap::ADDRESS1)->addAsColumn("address_ADDRESS2", AddressTableMap::ADDRESS2)->addAsColumn("address_ADDRESS3", AddressTableMap::ADDRESS3)->addAsColumn("address_ZIPCODE", AddressTableMap::ZIPCODE)->addAsColumn("address_CITY", AddressTableMap::CITY)->addAsColumn("address_PHONE", AddressTableMap::PHONE)->addAsColumn("address_CELLPHONE", AddressTableMap::CELLPHONE)->addAsColumn("address_IS_DEFAULT", AddressTableMap::IS_DEFAULT)->endUse()->addJoinObject($newsletterJoin)->addAsColumn("newsletter_IS_REGISTRED", "IF(NOT ISNULL(" . NewsletterTableMap::EMAIL . "),1,0)")->select([CustomerTableMap::ID, CustomerTableMap::REF, CustomerTableMap::LASTNAME, CustomerTableMap::FIRSTNAME, CustomerTableMap::EMAIL, CustomerTableMap::DISCOUNT, CustomerTableMap::CREATED_AT, "title_TITLE", "address_TITLE", "address_LABEL", "address_COMPANY", "address_FIRST_NAME", "address_LAST_NAME", "address_ADDRESS1", "address_ADDRESS2", "address_ADDRESS3", "address_ZIPCODE", "address_CITY", "address_COUNTRY", "address_PHONE", "address_CELLPHONE", "address_IS_DEFAULT", "newsletter_IS_REGISTRED"])->orderById();
I18n::addI18nCondition($query, CountryI18nTableMap::TABLE_NAME, CountryTableMap::ID, CountryI18nTableMap::ID, CountryI18nTableMap::LOCALE, $locale);
I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`customer_title_`.ID", "`customer_title_i18n_`.ID", "`customer_title_i18n_`.LOCALE", $locale);
I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`address_title`.ID", "`address_title_i18n`.ID", "`address_title_i18n`.LOCALE", $locale);
/** @var CustomerQuery $query */
$results = $query->find()->toArray();
/**
* Then get the orders
*/
$orders = OrderQuery::create()->useCustomerQuery()->orderById()->endUse()->find();
/**
* And add them info the array
*/
$orders->rewind();
$arrayLength = count($results);
$previousCustomerId = null;
for ($i = 0; $i < $arrayLength; ++$i) {
$currentCustomer =& $results[$i];
$currentCustomerId = $currentCustomer[CustomerTableMap::ID];
unset($currentCustomer[CustomerTableMap::ID]);
if ($currentCustomerId === $previousCustomerId) {
$currentCustomer["title_TITLE"] = "";
$currentCustomer[CustomerTableMap::LASTNAME] = "";
$currentCustomer[CustomerTableMap::FIRSTNAME] = "";
$currentCustomer[CustomerTableMap::EMAIL] = "";
$currentCustomer["address_COMPANY"] = "";
$currentCustomer["newsletter_IS_REGISTRED"] = "";
$currentCustomer[CustomerTableMap::CREATED_AT] = "";
$currentCustomer[CustomerTableMap::DISCOUNT] = "";
$currentCustomer += ["order_TOTAL" => "", "last_order_AMOUNT" => "", "last_order_DATE" => ""];
} else {
/**
* Reformat created_at date
*/
$date = $currentCustomer[CustomerTableMap::CREATED_AT];
$dateTime = new \DateTime($date);
$currentCustomer[CustomerTableMap::CREATED_AT] = $dateTime->format($lang->getDatetimeFormat());
/**
* Then compute everything about the orders
*/
$total = 0;
$lastOrderAmount = 0;
$lastOrderDate = null;
$lastOrder = null;
$lastOrderCurrencyCode = null;
$lastOrderId = 0;
$defaultCurrency = Currency::getDefaultCurrency();
$defaultCurrencyCode = $defaultCurrency->getCode();
if (empty($defaultCurrencyCode)) {
$defaultCurrencyCode = $defaultCurrency->getCode();
}
$formattedDate = null;
/** @var \Thelia\Model\Order $currentOrder */
while (false !== ($currentOrder = $orders->current())) {
if ($currentCustomerId != $currentOrder->getCustomerId()) {
break;
}
$amount = $currentOrder->getTotalAmount($tax);
if (0 < ($rate = $currentOrder->getCurrencyRate())) {
$amount = round($amount / $rate, 2);
}
$total += $amount;
/** @var \DateTime $date */
$date = $currentOrder->getCreatedAt();
if (null === $lastOrderDate || $date >= $lastOrderDate && $lastOrderId < $currentOrder->getId()) {
$lastOrder = $currentOrder;
$lastOrderDate = $date;
$lastOrderId = $currentOrder->getId();
}
$orders->next();
}
if ($lastOrderDate !== null) {
$formattedDate = $lastOrderDate->format($lang->getDatetimeFormat());
$orderCurrency = $lastOrder->getCurrency();
$lastOrderCurrencyCode = $orderCurrency->getCode();
if (empty($lastOrderCurrencyCode)) {
$lastOrderCurrencyCode = $orderCurrency->getCode();
}
$lastOrderAmount = $lastOrder->getTotalAmount($tax_);
}
$currentCustomer += ["order_TOTAL" => $total . " " . $defaultCurrencyCode, "last_order_AMOUNT" => $lastOrderAmount === 0 ? "" : $lastOrderAmount . " " . $lastOrderCurrencyCode, "last_order_DATE" => $formattedDate];
}
$previousCustomerId = $currentCustomerId;
}
return $results;
}
示例8: createOrder
protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, LangModel $lang, CartModel $cart, CustomerModel $customer)
{
$con = \Propel\Runtime\Propel::getConnection(OrderTableMap::DATABASE_NAME);
$con->beginTransaction();
$placedOrder = $sessionOrder->copy();
$placedOrder->setDispatcher($dispatcher);
$deliveryAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenDeliveryAddress());
$taxCountry = $deliveryAddress->getCountry();
$invoiceAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenInvoiceAddress());
$cartItems = $cart->getCartItems();
/* fulfill order */
$placedOrder->setCustomerId($customer->getId());
$placedOrder->setCurrencyId($currency->getId());
$placedOrder->setCurrencyRate($currency->getRate());
$placedOrder->setLangId($lang->getId());
/* hard save the delivery and invoice addresses */
$deliveryOrderAddress = new OrderAddress();
$deliveryOrderAddress->setCustomerTitleId($deliveryAddress->getTitleId())->setCompany($deliveryAddress->getCompany())->setFirstname($deliveryAddress->getFirstname())->setLastname($deliveryAddress->getLastname())->setAddress1($deliveryAddress->getAddress1())->setAddress2($deliveryAddress->getAddress2())->setAddress3($deliveryAddress->getAddress3())->setZipcode($deliveryAddress->getZipcode())->setCity($deliveryAddress->getCity())->setPhone($deliveryAddress->getPhone())->setCountryId($deliveryAddress->getCountryId())->save($con);
$invoiceOrderAddress = new OrderAddress();
$invoiceOrderAddress->setCustomerTitleId($invoiceAddress->getTitleId())->setCompany($invoiceAddress->getCompany())->setFirstname($invoiceAddress->getFirstname())->setLastname($invoiceAddress->getLastname())->setAddress1($invoiceAddress->getAddress1())->setAddress2($invoiceAddress->getAddress2())->setAddress3($invoiceAddress->getAddress3())->setZipcode($invoiceAddress->getZipcode())->setCity($invoiceAddress->getCity())->setPhone($invoiceAddress->getPhone())->setCountryId($invoiceAddress->getCountryId())->save($con);
$placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId());
$placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId());
$placedOrder->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId());
$placedOrder->setCart($cart);
/* memorize discount */
$placedOrder->setDiscount($cart->getDiscount());
$placedOrder->save($con);
/* fulfill order_products and decrease stock */
foreach ($cartItems as $cartItem) {
$product = $cartItem->getProduct();
/* get translation */
$productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId());
$pse = $cartItem->getProductSaleElements();
/* check still in stock */
if ($cartItem->getQuantity() > $pse->getQuantity() && true === ConfigQuery::checkAvailableStock() && 0 === $product->getVirtual()) {
throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem);
}
if (0 === $product->getVirtual()) {
/* decrease stock for non virtual product */
$allowNegativeStock = intval(ConfigQuery::read('allow_negative_stock', 0));
$newStock = $pse->getQuantity() - $cartItem->getQuantity();
//Forbid negative stock
if ($newStock < 0 && 0 === $allowNegativeStock) {
$newStock = 0;
}
$pse->setQuantity($newStock);
$pse->save($con);
}
/* get tax */
$taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId());
$taxDetail = $product->getTaxRule()->getTaxDetail($product, $taxCountry, $cartItem->getPrice(), $cartItem->getPromoPrice(), $lang->getLocale());
// get the virtual document path
$virtualDocumentPath = null;
if ($product->getVirtual() === 1) {
// try to find the associated document
if (null !== ($documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $pse->getId()))) {
$productDocument = ProductDocumentQuery::create()->findPk($documentId);
if (null !== $productDocument) {
$virtualDocumentPath = $productDocument->getFile();
}
}
}
$orderProduct = new OrderProduct();
$orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($productI18n->getTitle())->setChapo($productI18n->getChapo())->setDescription($productI18n->getDescription())->setPostscriptum($productI18n->getPostscriptum())->setVirtual($product->getVirtual())->setVirtualDocument($virtualDocumentPath)->setQuantity($cartItem->getQuantity())->setPrice($cartItem->getPrice())->setPromoPrice($cartItem->getPromoPrice())->setWasNew($pse->getNewness())->setWasInPromo($cartItem->getPromo())->setWeight($pse->getWeight())->setTaxRuleTitle($taxRuleI18n->getTitle())->setTaxRuleDescription($taxRuleI18n->getDescription())->setEanCode($pse->getEanCode())->setCartIemId($cartItem->getId())->setDispatcher($dispatcher)->save($con);
/* fulfill order_product_tax */
foreach ($taxDetail as $tax) {
$tax->setOrderProductId($orderProduct->getId());
$tax->save($con);
}
/* fulfill order_attribute_combination and decrease stock */
foreach ($pse->getAttributeCombinations() as $attributeCombination) {
$attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId());
$attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId());
$orderAttributeCombination = new OrderProductAttributeCombination();
$orderAttributeCombination->setOrderProductId($orderProduct->getId())->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save($con);
}
}
$con->commit();
return $placedOrder;
}