php Thelia-Model-CurrencyQuery类(方法)实例源码

下面列出了php Thelia-Model-CurrencyQuery 类(方法)源码代码实例,从而了解它的用法。

作者:GuiminZHO    项目:theli   
public function testFormatMoneyForceCurrency()
 {
     /********************/
     /*** Test for EUR ***/
     /********************/
     $currency = CurrencyQuery::create()->findOneByCode('EUR');
     // new format_money method, thelia >= 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency' => $currency->getId()]);
     $this->assertEquals("10.00 " . $currency->getSymbol(), $data);
     // old format_money method, thelia < 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency_symbol' => $currency->getSymbol()]);
     $this->assertEquals("10.00 " . $currency->getSymbol(), $data);
     /********************/
     /*** Test for USD ***/
     /********************/
     $currency = CurrencyQuery::create()->findOneByCode('USD');
     // new format_money method, thelia >= 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency' => $currency->getId()]);
     $this->assertEquals($currency->getSymbol() . "10.00", $data);
     // old format_money method, thelia < 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency_symbol' => $currency->getSymbol()]);
     $this->assertEquals($currency->getSymbol() . "10.00", $data);
     /********************/
     /*** Test for GBP ***/
     /********************/
     $currency = CurrencyQuery::create()->findOneByCode('GBP');
     // new format_money method, thelia >= 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency' => $currency->getId()]);
     $this->assertEquals($currency->getSymbol() . "10.00", $data);
     // old format_money method, thelia < 2.3
     $data = $this->render("testFormatMoney.html", ['number' => 9.9999, 'currency_symbol' => $currency->getSymbol()]);
     $this->assertEquals($currency->getSymbol() . "10.00", $data);
 }

作者:vigourouxjulie    项目:theli   
public function importData(array $data)
 {
     $pse = ProductSaleElementsQuery::create()->findPk($data['id']);
     if ($pse === null) {
         return Translator::getInstance()->trans('The product sale element id %id doesn\'t exist', ['%id' => $data['id']]);
     } else {
         $currency = null;
         if (isset($data['currency'])) {
             $currency = CurrencyQuery::create()->findOneByCode($data['currency']);
         }
         if ($currency === null) {
             $currency = Currency::getDefaultCurrency();
         }
         $price = ProductPriceQuery::create()->filterByProductSaleElementsId($pse->getId())->findOneByCurrencyId($currency->getId());
         if ($price === null) {
             $price = new ProductPrice();
             $price->setProductSaleElements($pse)->setCurrency($currency);
         }
         $price->setPrice($data['price']);
         if (isset($data['promo_price'])) {
             $price->setPromoPrice($data['promo_price']);
         }
         if (isset($data['promo'])) {
             $price->getProductSaleElements()->setPromo((int) $data['promo'])->save();
         }
         $price->save();
         $this->importedRows++;
     }
     return null;
 }

作者:vigourouxjulie    项目:theli   
public function checkDuplicateCode($value, ExecutionContextInterface $context)
 {
     $currency = CurrencyQuery::create()->findOneByCode($value);
     if ($currency) {
         $context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value]));
     }
 }

作者:fachriz    项目:theli   
/**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $stubDispatcher = $this->getMockBuilder('\\Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $stubDispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($dummy, $cartEvent) {
         $ci = new CartItem();
         $ci->setId(3)->setPrice(123)->setPromo(0);
         $cartEvent->setCartItem($ci);
     }));
     $stubFacade->expects($this->any())->method('getDispatcher')->will($this->returnValue($stubDispatcher));
     $stubSession = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock();
     $stubSession->expects($this->any())->method('get')->will($this->onConsecutiveCalls(-1, 3));
     $stubRequest = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $stubRequest->expects($this->any())->method('getSession')->will($this->returnValue($stubSession));
     $stubFacade->expects($this->any())->method('getRequest')->will($this->returnValue($stubRequest));
     return $stubFacade;
 }

作者:bcbr    项目:LegacyProductAttribute   
/**
  * Get the untaxed price and, if the product is in sale, promo price of a product.
  *
  * @param ProductGetPricesEvent $event
  */
 public function getPrices(ProductGetPricesEvent $event)
 {
     $product = ProductQuery::create()->findPk($event->getProductId());
     if (null === $product) {
         throw new \InvalidArgumentException('No product given');
     }
     $currency = CurrencyQuery::create()->findPk($event->getCurrencyId());
     if (null === $currency) {
         $currency = CurrencyQuery::create()->findOneByByDefault(true);
     }
     // get the base prices given in the event
     // or, by default, the prices of the product's default PSE
     if (null !== $event->getBasePrices()) {
         $price = $event->getBasePrices()->getPrice();
         $promoPrice = $event->getBasePrices()->getPromoPrice();
     } else {
         $prices = $product->getDefaultSaleElements()->getPricesByCurrency($currency);
         $price = $prices->getPrice();
         $promoPrice = $prices->getPromoPrice();
     }
     // adjust the prices with the configured price delta from legacy attributes
     $legacyProductAttributeValues = LegacyProductAttributeValueQuery::create()->filterByProductId($product->getId())->filterByAttributeAvId(array_values($event->getLegacyProductAttributes()), Criteria::IN)->find();
     /** @var LegacyProductAttributeValue $legacyProductAttributeValue */
     foreach ($legacyProductAttributeValues as $legacyProductAttributeValue) {
         $legacyProductAttributeValuePrice = $legacyProductAttributeValue->getPriceForCurrency($event->getCurrencyId());
         if ($legacyProductAttributeValuePrice === null) {
             continue;
         }
         $price += $legacyProductAttributeValuePrice->getDelta();
         $promoPrice += $legacyProductAttributeValuePrice->getDelta();
     }
     $event->setPrices(new ProductPriceTools($price, $promoPrice));
 }

作者:badela    项目:theli   
protected function getExistingObject()
 {
     $currency = CurrencyQuery::create()->findOneById($this->getRequest()->get('currency_id'));
     if (null !== $currency) {
         $currency->setLocale($this->getCurrentEditionLocale());
     }
     return $currency;
 }

作者:MaximeMorill    项目:theli   
/**
  * @since 2.3
  * @param float $number
  * @param int $decimals
  * @param string $decPoint
  * @param string $thousandsSep
  * @param int|null $currencyId
  * @return string
  */
 public function formatByCurrency($number, $decimals = null, $decPoint = null, $thousandsSep = null, $currencyId = null)
 {
     $number = parent::format($number, $decimals, $decPoint, $thousandsSep);
     $currency = $currencyId !== null ? CurrencyQuery::create()->findPk($currencyId) : $this->request->getSession()->getCurrency();
     if ($currency !== null && strpos($currency->getFormat(), '%n') !== false) {
         return str_replace(['%n', '%s', '%c'], [$number, $currency->getSymbol(), $currency->getCode()], $currency->getFormat());
     }
     return $number;
 }

作者:alex6353    项目:theli   
/**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $currencies = CurrencyQuery::create()->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubFacade->expects($this->any())->method('getCartTotalTaxPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     return $stubFacade;
 }

作者:vigourouxjulie    项目:theli   
public function testCheckCurrency()
 {
     $listener = $this->getRequestListener();
     $event = $this->getGetResponseEvent();
     /** @var Session $session */
     $session = $event->getRequest()->getSession();
     // Test with a session that has no currency
     $listener->checkCurrency($event);
     $currentCurrency = $session->getCurrency();
     $this->assertInstanceOf('Thelia\\Model\\Currency', $currentCurrency);
     // Test change currency
     $newCurrency = CurrencyQuery::create()->filterById($currentCurrency->getId(), Criteria::NOT_IN)->findOne();
     $event->getRequest()->query->set('currency', $newCurrency->getCode());
     $listener->checkCurrency($event);
     $this->assertEquals($session->getCurrency()->getId(), $newCurrency->getId());
 }

作者:hadesai    项目:theli   
public function testCreateAction()
 {
     $client = static::createClient();
     $category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     $defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
     $taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
     $product = ['ref' => uniqid('testCreateProduct'), 'locale' => 'en_US', 'title' => 'product create from api', 'description' => 'product description from api', 'default_category' => $category->getId(), 'visible' => 1, 'price' => '10', 'currency' => $defaultCurrency->getId(), 'tax_rule' => $taxRule->getId(), 'weight' => 10, 'brand_id' => 0];
     $requestContent = json_encode($product);
     $servers = $this->getServerParameters();
     $servers['CONTENT_TYPE'] = 'application/json';
     $client->request('POST', '/api/products?&sign=' . $this->getSignParameter($requestContent), [], [], $servers, $requestContent);
     $this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
     $content = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals('en_US', $content[0]['LOCALE']);
     return $content['0']['ID'];
 }

作者:alex6353    项目:theli   
public function testPrices()
 {
     $container = new Container();
     new Translator($container);
     $handler = new ProductTaxedPricesExport($container);
     $lang = Lang::getDefaultLanguage();
     $data = $handler->buildData($lang)->getData();
     foreach ($data as $line) {
         $product = ProductSaleElementsQuery::create()->findOneByRef($line["ref"]);
         $currency = CurrencyQuery::create()->findOneByCode($line["currency"]);
         $this->assertNotNull($product);
         $prices = $product->getPricesByCurrency($currency);
         $this->assertEquals($prices->getPrice(), $line["price"]);
         $this->assertEquals($prices->getPromoPrice(), $line["promo_price"]);
     }
 }

作者:marger    项目:theli   
public function testPrices()
 {
     new Translator(new Container());
     $export = new ProductTaxedPricesExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["attributes", "currency", "ean", "id", "price", "product_id", "promo", "promo_price", "tax_id", "tax_title", "title"];
     $rawData = $data->getData();
     $max = count($rawData);
     /**
      * If there are more than 50 entries, a test on 50 entries will be as efficient
      * and quicker than a test on all the entries
      */
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max; ++$i) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         $this->assertTrue(sort($rowKeys));
         $this->assertEquals($keys, $rowKeys);
         $pse = ProductSaleElementsQuery::create()->findPk($row["id"]);
         $this->assertNotNull($pse);
         $this->assertEquals($pse->getEanCode(), $row["ean"]);
         $this->assertEquals($pse->getPromo(), $row["promo"]);
         $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
         $this->assertNotNull($currency);
         $price = $pse->getPricesByCurrency($currency);
         $this->assertEquals(round($price->getPrice(), 3), round($row["price"], 3));
         $this->assertEquals(round($price->getPromoPrice(), 3), round($row["promo_price"], 3));
         $this->assertEquals($pse->getProduct()->getTitle(), $row["title"]);
         $attributeCombinations = $pse->getAttributeCombinations();
         $attributes = [];
         foreach ($attributeCombinations as $attributeCombination) {
             if (!in_array($attributeCombination->getAttributeAv()->getTitle(), $attributes)) {
                 $attributes[] = $attributeCombination->getAttributeAv()->getTitle();
             }
         }
         $rowAttributes = !empty($row["attributes"]) ? explode(",", $row["attributes"]) : [];
         sort($rowAttributes);
         sort($attributes);
         $this->assertEquals($attributes, $rowAttributes);
         $taxId = $pse->getProduct()->getTaxRule()->getId();
         $this->assertEquals($taxId, $row["tax_id"]);
         $taxTitle = $pse->getProduct()->getTaxRule()->getTitle();
         $this->assertEquals($taxTitle, $row["tax_title"]);
     }
 }

作者:badela    项目:theli   
public function testQuery()
 {
     new Translator(new Container());
     $export = new ProductPricesExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["attributes", "currency", "ean", "id", "price", "product_id", "promo", "promo_price", "title"];
     $rawData = $data->getData();
     $max = count($rawData);
     /**
      * If there's more that 50 entries,
      * just pick 50, it would be faster and as tested as if we test 1000 entries.
      */
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max; ++$i) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         $this->assertTrue(sort($rowKeys));
         $this->assertEquals($keys, $rowKeys);
         $pse = ProductSaleElementsQuery::create()->findPk($row["id"]);
         $this->assertNotNull($pse);
         $this->assertEquals($pse->getEanCode(), $row["ean"]);
         $this->assertEquals($pse->getPromo(), $row["promo"]);
         $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
         $this->assertNotNull($currency);
         $price = $pse->getPricesByCurrency($currency);
         // The substr is a patch for php 5.4 float round
         $this->assertEquals(round($price->getPrice(), 3), round($row["price"], 3));
         $this->assertEquals(round($price->getPromoPrice(), 3), round($row["promo_price"], 3));
         $this->assertEquals($pse->getProduct()->getTitle(), $row["title"]);
         $attributeCombinations = $pse->getAttributeCombinations();
         $attributes = [];
         foreach ($attributeCombinations as $attributeCombination) {
             if (!in_array($attributeCombination->getAttributeAv()->getTitle(), $attributes)) {
                 $attributes[] = $attributeCombination->getAttributeAv()->getTitle();
             }
         }
         $rowAttributes = explode(",", $row["attributes"]);
         sort($rowAttributes);
         sort($attributes);
         $this->assertEquals($attributes, $rowAttributes);
     }
 }

作者:bcbr    项目:LegacyProductAttribute   
protected function buildForm()
 {
     $this->formBuilder->add('product_id', 'integer', ['label' => Translator::getInstance()->trans('Product'), 'required' => true, 'constraints' => [new NotBlank()]])->add('currency_id', 'integer', ['label' => Translator::getInstance()->trans('Currency'), 'required' => true, 'constraints' => [new NotBlank()]]);
     $productId = $this->request->get('product_id');
     if ($productId === null) {
         $productId = $this->request->get($this->getName())['product_id'];
     }
     $product = ProductQuery::create()->findPk($productId);
     if ($product->getTemplate() === null) {
         return;
     }
     $currencyId = $this->request->get('edit_currency_id');
     if ($currencyId === null) {
         $defaultCurrency = CurrencyQuery::create()->findOneByByDefault(true);
         if ($defaultCurrency !== null) {
             $currencyId = $defaultCurrency->getId();
         }
     }
     $productAttributeAvs = AttributeAvQuery::create()->useAttributeQuery()->filterByTemplate($product->getTemplate())->endUse()->find();
     $formData = ['price_delta' => [], 'price_delta_with_tax' => []];
     /** @var TaxEngine $taxEngine */
     $taxEngine = $this->container->get('thelia.taxEngine');
     $taxCalculator = (new Calculator())->load($product, $taxEngine->getDeliveryCountry());
     /** @var AttributeAv $productAttributeAv */
     foreach ($productAttributeAvs as $productAttributeAv) {
         $legacyProductAttributeValuePrice = LegacyProductAttributeValuePriceQuery::create()->findPk([$product->getId(), $productAttributeAv->getId(), $currencyId]);
         $priceDelta = 0;
         $priceDeltaWithTax = 0;
         if (null !== $legacyProductAttributeValuePrice) {
             $priceDelta = $legacyProductAttributeValuePrice->getDelta();
             $priceDeltaWithTax = $taxCalculator->getTaxedPrice($legacyProductAttributeValuePrice->getDelta());
         }
         $numberFormatter = NumberFormat::getInstance($this->getRequest());
         $formData['price_delta'][$productAttributeAv->getId()] = $numberFormatter->formatStandardNumber($priceDelta);
         $formData['price_delta_with_tax'][$productAttributeAv->getId()] = $numberFormatter->formatStandardNumber($priceDeltaWithTax);
     }
     $this->formBuilder->add('legacy_product_attribute_value_price_delta', 'collection', ['label' => Translator::getInstance()->trans('Price difference excluding taxes', [], LegacyProductAttributes::MESSAGE_DOMAIN_BO), 'type' => 'number', 'allow_add' => true, 'allow_delete' => true, 'data' => $formData['price_delta']])->add('legacy_product_attribute_value_price_delta_with_tax', 'collection', ['label' => Translator::getInstance()->trans('Price difference including taxes', [], LegacyProductAttributes::MESSAGE_DOMAIN_BO), 'type' => 'number', 'allow_add' => true, 'allow_delete' => true, 'data' => $formData['price_delta_with_tax']]);
 }

作者:NandoKstroNe    项目:theli   
public function buildDataSet(Lang $lang)
 {
     /** @var \Thelia\Model\AttributeCombinationQuery $query */
     $query = parent::buildDataSet($lang);
     $pseJoin = new Join(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID);
     $pseJoin->setRightTableAlias("pse_tax_join");
     $productJoin = new Join(ProductSaleElementsTableMap::ID, ProductTableMap::ID);
     $productJoin->setRightTableAlias("product_tax_join");
     $taxJoin = new Join("`product_tax_join`.TAX_RULE_ID", TaxRuleTableMap::ID, Criteria::LEFT_JOIN);
     $taxI18nJoin = new Join(TaxRuleTableMap::ID, TaxRuleI18nTableMap::ID, Criteria::LEFT_JOIN);
     $query->addJoinObject($pseJoin, "pse_tax_join")->addJoinObject($productJoin, "product_tax_join")->addJoinObject($productJoin)->addJoinObject($taxJoin)->addJoinObject($taxI18nJoin)->addAsColumn("product_TAX_TITLE", TaxRuleI18nTableMap::TITLE)->addAsColumn("tax_ID", TaxRuleTableMap::ID)->select($query->getSelect() + ["product_TAX_TITLE", "tax_ID"]);
     I18n::addI18nCondition($query, TaxRuleI18nTableMap::TABLE_NAME, TaxRuleTableMap::ID, TaxRuleI18nTableMap::ID, TaxRuleI18nTableMap::LOCALE, $lang->getLocale());
     $dataSet = $query->keepQuery(true)->find()->toArray();
     $productSaleElements = ProductSaleElementsQuery::create()->find()->toKeyIndex("Id");
     $currencies = CurrencyQuery::create()->find()->toKeyIndex("Code");
     foreach ($dataSet as &$line) {
         /** @var \Thelia\Model\ProductSaleElements $pse */
         $pse = $productSaleElements[$line["product_sale_elements_ID"]];
         $pricesTools = $pse->getPricesByCurrency($currencies[$line["currency_CODE"]]);
         $line["price_PRICE"] = $pricesTools->getPrice();
         $line["price_PROMO_PRICE"] = $pricesTools->getPromoPrice();
     }
     return $dataSet;
 }

作者:alex6353    项目:theli   
/**
  * @param \Thelia\Core\FileFormat\Formatting\FormatterData
  * @return string|array error messages
  *
  * The method does the import routine from a FormatterData
  */
 public function retrieveFromFormatterData(FormatterData $data)
 {
     $errors = [];
     $translator = Translator::getInstance();
     while (null !== ($row = $data->popRow())) {
         $this->checkMandatoryColumns($row);
         $obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]);
         if ($obj === null) {
             $errorMessage = $translator->trans("The product sale element reference %ref doesn't exist", ["%ref" => $row["ref"]]);
             $errors[] = $errorMessage;
         } else {
             $currency = null;
             if (isset($row["currency"])) {
                 $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
             }
             if ($currency === null) {
                 $currency = Currency::getDefaultCurrency();
             }
             $price = ProductPriceQuery::create()->filterByProductSaleElementsId($obj->getId())->findOneByCurrencyId($currency->getId());
             if ($price === null) {
                 $price = new ProductPrice();
                 $price->setProductSaleElements($obj)->setCurrency($currency);
             }
             $price->setPrice($row["price"]);
             if (isset($row["promo_price"])) {
                 $price->setPromoPrice($row["promo_price"]);
             }
             if (isset($row["promo"])) {
                 $price->getProductSaleElements()->setPromo((int) $row["promo"])->save();
             }
             $price->save();
             $this->importedRows++;
         }
     }
     return $errors;
 }

作者:hadesai    项目:theli   
$product = $pse->getProduct();
         $orderProduct = new \Thelia\Model\OrderProduct();
         $orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($product->getTitle())->setChapo($product->getChapo())->setDescription($product->getDescription())->setPostscriptum($product->getPostscriptum())->setQuantity(mt_rand(1, 10))->setPrice($price = mt_rand(1, 100))->setPromoPrice(mt_rand(1, $price))->setWasNew($pse->getNewness())->setWasInPromo(rand(0, 1) == 1)->setWeight($pse->getWeight())->setTaxRuleTitle(getRealText(20))->setTaxRuleDescription(getRealText(50))->setEanCode($pse->getEanCode())->save($con);
     }
 }
 echo "Generating coupons fixtures\n";
 generateCouponFixtures($thelia);
 echo "Generating sales\n";
 for ($idx = 1; $idx <= 5; $idx++) {
     $sale = new \Thelia\Model\Sale();
     $start = new \DateTime();
     $end = new \DateTime();
     $sale->setActive(0)->setStartDate($start->setTimestamp(strtotime("today - 1 month")))->setEndDate($end->setTimestamp(strtotime("today + 1 month")))->setPriceOffsetType(\Thelia\Model\Sale::OFFSET_TYPE_PERCENTAGE)->setDisplayInitialPrice(true);
     setI18n($sale, ['SaleLabel' => 20, 'Title' => 20, 'Chapo' => 30, 'Postscriptum' => 30, 'Description' => 50]);
     $sale->save();
     $currencies = \Thelia\Model\CurrencyQuery::create()->find();
     foreach ($currencies as $currency) {
         $saleOffset = new \Thelia\Model\SaleOffsetCurrency();
         $saleOffset->setCurrencyId($currency->getId())->setSaleId($sale->getId())->setPriceOffsetValue($faker->numberBetween(10, 70))->save();
     }
     $products = \Thelia\Model\ProductQuery::create()->addAscendingOrderByColumn('RAND()')->find();
     $count = $faker->numberBetween(5, 20);
     foreach ($products as $product) {
         if (--$count < 0) {
             break;
         }
         $saleProduct = new \Thelia\Model\SaleProduct();
         $saleProduct->setSaleId($sale->getId())->setProductId($product->getId())->setAttributeAvId(null)->save();
     }
 }
 $con->commit();

作者:alex6353    项目:theli   
public function fillCart()
 {
     $currency = CurrencyQuery::create()->findOne();
     //create a fake cart in database;
     $cart = new Cart();
     $cart->setToken(uniqid("createorder", true))->setCustomer($this->customer)->setCurrency($currency)->save();
     /* add 3 items */
     $productList = array();
     for ($i = 0; $i < 3; $i++) {
         $pse = ProductSaleElementsQuery::create()->filterByProduct(ProductQuery::create()->filterByVisible(1)->filterById($productList, Criteria::NOT_IN)->find())->filterByQuantity(5, Criteria::GREATER_EQUAL)->joinProductPrice('pp', Criteria::INNER_JOIN)->addJoinCondition('pp', 'currency_id = ?', $currency->getId(), null, \PDO::PARAM_INT)->withColumn('`pp`.price', 'price_PRICE')->withColumn('`pp`.promo_price', 'price_PROMO_PRICE')->findOne();
         $productList[] = $pse->getProductId();
         $cartItem = new CartItem();
         $cartItem->setCart($cart)->setProduct($pse->getProduct())->setProductSaleElements($pse)->setQuantity($i + 1)->setPrice($pse->getPrice())->setPromoPrice($pse->getPromoPrice())->setPromo($pse->getPromo())->setPriceEndOfLife(time() + 60 * 60 * 24 * 30)->save();
         $this->cartItems[] = $cartItem;
     }
     $this->request->getSession()->setCart($cart->getId());
     return $cart;
 }

作者:shiron    项目:theli   
/**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Currency::setDeleted()
  * @see Currency::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(CurrencyTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCurrencyQuery::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;
     }
 }

作者:patrickd2    项目:theli   
/**
  * Calculate all prices
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function loadConvertedPrices()
 {
     $product_sale_element_id = intval($this->getRequest()->get('product_sale_element_id', 0));
     $currency_id = intval($this->getRequest()->get('currency_id', 0));
     $price_with_tax = $price_without_tax = $sale_price_with_tax = $sale_price_without_tax = 0;
     if (null !== ($pse = ProductSaleElementsQuery::create()->findPk($product_sale_element_id))) {
         if ($currency_id > 0 && $currency_id != Currency::getDefaultCurrency()->getId() && null !== ($currency = CurrencyQuery::create()->findPk($currency_id))) {
             // Get the default currency price
             $productPrice = ProductPriceQuery::create()->filterByCurrency(Currency::getDefaultCurrency())->filterByProductSaleElementsId($product_sale_element_id)->findOne();
             // Calculate the converted price
             if (null !== $productPrice) {
                 $price_without_tax = $productPrice->getPrice() * $currency->getRate();
                 $sale_price_without_tax = $productPrice->getPromoPrice() * $currency->getRate();
             }
         }
         if (null !== ($product = $pse->getProduct())) {
             $price_with_tax = $this->computePrice($price_without_tax, 'with_tax', $product);
             $sale_price_with_tax = $this->computePrice($sale_price_without_tax, 'with_tax', $product);
         }
     }
     return new JsonResponse(array('price_with_tax' => $this->formatPrice($price_with_tax), 'price_without_tax' => $this->formatPrice($price_without_tax), 'sale_price_with_tax' => $this->formatPrice($sale_price_with_tax), 'sale_price_without_tax' => $this->formatPrice($sale_price_without_tax)));
 }


问题


面经


文章

微信
公众号

扫码关注公众号