本文整理汇总了PHP中Thelia\Model\ProductSaleElementsQuery::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductSaleElementsQuery::create方法的具体用法?PHP ProductSaleElementsQuery::create怎么用?PHP ProductSaleElementsQuery::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thelia\Model\ProductSaleElementsQuery
的用法示例。
在下文中一共展示了ProductSaleElementsQuery::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importData
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;
}
示例2: addItem
/**
*
* add an article in the current cart
* @param \Thelia\Core\Event\Cart\CartEvent $event
*/
public function addItem(CartEvent $event)
{
$cart = $event->getCart();
$newness = $event->getNewness();
$append = $event->getAppend();
$quantity = $event->getQuantity();
$currency = $cart->getCurrency();
$customer = $cart->getCustomer();
$discount = 0;
if (null !== $customer && $customer->getDiscount() > 0) {
$discount = $customer->getDiscount();
}
$productSaleElementsId = $event->getProductSaleElementsId();
$productId = $event->getProduct();
$cartItem = $this->findItem($cart->getId(), $productId, $productSaleElementsId);
if ($cartItem === null || $newness) {
$productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId);
if (null !== $productSaleElements) {
$productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);
$event->setCartItem($this->doAddItem($event->getDispatcher(), $cart, $productId, $productSaleElements, $quantity, $productPrices));
}
}
if ($append && $cartItem !== null) {
$cartItem->addQuantity($quantity)->save();
$event->setCartItem($cartItem);
}
}
示例3: testImport
public function testImport()
{
$currency = Currency::getDefaultCurrency();
$query = ProductSaleElementsQuery::create()->addAscendingOrderByColumn('RAND()')->limit(3)->find();
$jsonData = [];
$data = [];
/** @var \Thelia\Model\ProductSaleElements $pse */
foreach ($query as $pse) {
$entry = [];
$entry["ref"] = $pse->getRef();
/**
* Be sure to get a different value.
*/
while ($pse->getPricesByCurrency($currency)->getPrice() === ($entry["price"] = rand(0, 1000))) {
}
while ($pse->getPricesByCurrency($currency)->getPromoPrice() === ($entry["promo_price"] = rand(0, 1000))) {
}
while ($pse->getPromo() === ($entry["promo_price"] = rand(0, 1000))) {
}
$data[$pse->getId()] = $entry;
$jsonData[] = $entry;
}
$jsonString = json_encode($jsonData);
$this->assertEquals("Import successfully done, 3 row(s) have been changed", $this->controller->processImport($jsonString, $this->import, new JsonFormatter(), null));
$query = ProductSaleElementsQuery::create()->findPks(array_keys($data));
/** @var \Thelia\Model\ProductSaleElements $entry */
foreach ($query as $entry) {
$this->assertEquals($data[$entry->getId()], ["price" => $entry->getPricesByCurrency($currency)->getPrice(), "promo_price" => $entry->getPricesByCurrency($currency)->getPromoPrice(), "ref" => $entry->getRef()]);
}
}
示例4: testUpdateStock
public function testUpdateStock()
{
$query = ProductSaleElementsQuery::create()->addAscendingOrderByColumn('RAND()')->limit(3)->find();
$jsonData = [];
$data = [];
/** @var \Thelia\Model\ProductSaleElements $pse */
foreach ($query as $pse) {
$entry = [];
$entry["id"] = $pse->getId();
/**
* Be sure to get a different value.
*/
while ($pse->getQuantity() === ($entry["stock"] = rand(0, 1000))) {
}
$data[$pse->getId()] = $entry["stock"];
$jsonData[] = $entry;
}
$jsonString = json_encode($jsonData);
$this->assertEquals("Import successfully done, 3 row(s) have been changed", $this->controller->processImport($jsonString, $this->import, new JsonFormatter(), null));
$query = ProductSaleElementsQuery::create()->findPks(array_keys($data));
/** @var \Thelia\Model\ProductSaleElements $entry */
foreach ($query as $entry) {
$this->assertEquals($data[$entry->getId()], $entry->getQuantity());
}
}
示例5: getGoogleProduct
/** Todo Remove this function replaced by statusBatch()*/
public function getGoogleProduct($id)
{
$query = $this->getRequest()->query;
$merchantId = $query->get('account');
$targetCountry = CountryQuery::create()->findOneById($query->get('country'));
if ($targetCountry) {
$isoAlpha2 = $targetCountry->getIsoalpha2();
} else {
$isoAlpha2 = Country::getDefaultCountry()->getIsoalpha2();
}
$lang = LangQuery::create()->findOneById($query->get('lang'));
if ($lang) {
$langCode = $lang->getCode();
} else {
$langCode = Lang::getDefaultLanguage()->getCode();
}
$productSaleElements = ProductSaleElementsQuery::create()->findOneByProductId($id);
$googleProductId = "online:" . $langCode . ":" . $isoAlpha2 . ":" . $productSaleElements->getId();
try {
$googleShoppingHandler = new GoogleShoppingHandler($this->container, $this->getRequest());
$client = $googleShoppingHandler->createGoogleClient();
$googleShoppingService = new \Google_Service_ShoppingContent($client);
$googleProduct = $googleShoppingService->products->get($merchantId, $googleProductId);
$response = ["id" => $googleProduct->getOfferId(), "identifier" => $googleProduct->getIdentifierExists()];
return new JsonResponse($response);
} catch (\Exception $e) {
return new JsonResponse();
}
}
示例6: 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 = ProductSaleElementsQuery::create()->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()->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)->useAttributeAvQuery(null, Criteria::LEFT_JOIN)->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()->endUse()->addAsColumn("product_sale_elements_ID", ProductSaleElementsTableMap::ID)->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)->select(["product_sale_elements_ID", "product_sale_elements_EAN_CODE", "product_sale_elements_PROMO", "price_PRICE", "price_PROMO_PRICE", "currency_CODE", "product_TITLE", "attribute_av_i18n_ATTRIBUTES"])->orderBy("product_sale_elements_ID")->groupBy("product_sale_elements_ID");
return $query;
}
示例7: getData
protected function getData()
{
$locale = $this->language->getLocale();
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$attributeAvJoin = new Join(AttributeAvTableMap::ID, AttributeAvI18nTableMap::ID, Criteria::LEFT_JOIN);
$query = ProductSaleElementsQuery::create()->addSelfSelectColumns()->useProductPriceQuery()->useCurrencyQuery()->withColumn(CurrencyTableMap::CODE)->endUse()->withColumn(ProductPriceTableMap::PRICE)->withColumn(ProductPriceTableMap::PROMO_PRICE)->endUse()->useProductQuery()->addJoinObject($productJoin, 'product_join')->addJoinCondition('product_join', ProductI18nTableMap::LOCALE . ' = ?', $locale, null, \PDO::PARAM_STR)->withColumn(ProductI18nTableMap::TITLE)->withColumn(ProductTableMap::ID)->endUse()->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)->useAttributeAvQuery(null, Criteria::LEFT_JOIN)->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()->endUse()->orderBy(ProductSaleElementsTableMap::ID)->groupBy(ProductSaleElementsTableMap::ID);
return $query;
}
示例8: checkStock
public function checkStock($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (null === $data["product_sale_elements_id"]) {
$context->addViolationAt("quantity", Translator::getInstance()->trans("Invalid product_sale_elements"));
} else {
$productSaleElements = ProductSaleElementsQuery::create()->filterById($data["product_sale_elements_id"])->filterByProductId($data["product"])->findOne();
$product = $productSaleElements->getProduct();
if ($productSaleElements->getQuantity() < $value && $product->getVirtual() === 0 && ConfigQuery::checkAvailableStock()) {
$context->addViolation(Translator::getInstance()->trans("quantity value is not valid"));
}
}
}
示例9: importData
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 {
$pse->setQuantity($data['stock']);
if (isset($data['ean']) && !empty($data['ean'])) {
$pse->setEanCode($data['ean']);
}
$pse->save();
$this->importedRows++;
}
return null;
}
示例10: testPrices
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"]);
}
}
示例11: testPrices
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"]);
}
}
示例12: testAssociatePSEDocument
public function testAssociatePSEDocument()
{
/**
* Get a product sale elements which has a related product image
*/
$pse = ProductSaleElementsQuery::create()->useProductQuery()->joinProductDocument()->endUse()->findOne();
if (null === $pse) {
$this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
}
/**
* Get this image and check if they are associated
*/
$productDocument = ProductDocumentQuery::create()->findOneByProductId($pse->getProductId());
$association = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElements($pse)->findOneByProductDocumentId($productDocument->getId());
$isAssociated = $association !== null;
$this->controller->getAssociationResponseData($pse->getId(), "document", $productDocument->getId());
$newAssociation = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElements($pse)->findOneByProductDocumentId($productDocument->getId());
$isNowAssociated = $newAssociation !== null;
$this->assertFalse($isAssociated === $isNowAssociated);
}
示例13: retrieveFromFormatterData
/**
* @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 = [];
while (null !== ($row = $data->popRow())) {
/**
* Check for mandatory columns
*/
$this->checkMandatoryColumns($row);
$obj = ProductSaleElementsQuery::create()->findPk($row["id"]);
if ($obj === null) {
$errors[] = $this->translator->trans("The product sale element reference %id doesn't exist", ["%id" => $row["id"]]);
} else {
$obj->setQuantity($row["stock"]);
if (isset($row["ean"]) && !empty($row["ean"])) {
$obj->setEanCode($row["ean"]);
}
$obj->save();
$this->importedRows++;
}
}
return $errors;
}
示例14: buildDataSet
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;
}
示例15: retrieveFromFormatterData
/**
* @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;
}