/** * Add fields for attribute values selection in our own way (since the product on has its default PSE, it has * no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes). * * @param TheliaFormEvent $event */ public function cartFormAfterBuild(TheliaFormEvent $event) { $sessionLocale = null; $session = $this->request->getSession(); if ($session !== null) { $sessionLang = $session->getLang(); if ($sessionLang !== null) { $sessionLocale = $sessionLang->getLocale(); } } $product = ProductQuery::create()->findPk($this->request->getProductId()); if ($product === null || $product->getTemplate() === null) { return; } $productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find(); /** @var Attribute $productAttribute */ foreach ($productAttributes as $productAttribute) { $attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId()); $choices = []; /** @var AttributeAv $attributeValue */ foreach ($attributeValues as $attributeValue) { if ($sessionLocale !== null) { $attributeValue->setLocale($sessionLocale); } $choices[$attributeValue->getId()] = $attributeValue->getTitle(); } $event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]); } }
protected function checkEan(Product $product, $colorAttributeId, $sizeAttributeId) { $isCombination = false; $defaultPse = $product->getDefaultSaleElements(); $combinationAttribute = $colorAttributeId . ',' . $sizeAttributeId; if (null !== $combinationAttribute) { $combination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $combinationAttribute), Criteria::IN)->filterByProductSaleElementsId($defaultPse->getId())->endUse()->findOne(); if (null !== $combination) { $isCombination = true; } } if (false === $isCombination) { if (null === $defaultPse->getEanCode()) { return false; } } else { $productSaleElementss = $product->getProductSaleElementss(); foreach ($productSaleElementss as $productSaleElements) { if (null === $productSaleElements->getEanCode()) { return false; } } } return true; }
protected function getExistingObject() { $attributeAv = AttributeAvQuery::create()->findOneById($this->getRequest()->get('attributeav_id', 0)); if (null !== $attributeAv) { $attributeAv->setLocale($this->getCurrentEditionLocale()); } return $attributeAv; }
public function buildModelCriteria() { $search = AttributeAvQuery::create(); /* manage translations */ $this->configureI18nProcessing($search); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $exclude = $this->getExclude(); if (null !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } $attribute = $this->getAttribute(); if (null !== $attribute) { $search->filterByAttributeId($attribute, Criteria::IN); } $product = $this->getProduct(); if (null !== $product) { // Return only Attributes Av that are part on a product's combination /* The request is: select * from attribute_av aav left join attribute_combination ac on ac.attribute_av_id = aav.id left join product_sale_elements pse on pse.id = ac.product_sale_elements_id where aav.attribute_id=3 and pse.product_id = 279 group by aav.id */ $pseJoin = new Join(); $pseJoin->addCondition(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID, Criteria::EQUAL); $pseJoin->setJoinType(Criteria::LEFT_JOIN); $search->leftJoinAttributeCombination('attribute_combination')->groupById()->addJoinObject($pseJoin)->where(ProductSaleElementsTableMap::PRODUCT_ID . "=?", $product, \PDO::PARAM_INT); } $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case 'id': $search->orderById(Criteria::ASC); break; case 'id_reverse': $search->orderById(Criteria::DESC); break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha_reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual": $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": $search->orderByPosition(Criteria::DESC); break; } } return $search; }
public function preImport() { AttributeQuery::create()->deleteAll(); AttributeAvQuery::create()->deleteAll(); // Create T1 <-> T2 IDs correspondance tables $this->attr_corresp = new CorrespondanceTable(CorrespondanceTable::ATTRIBUTES, $this->t1db); $this->attr_corresp->reset(); $this->attr_av_corresp = new CorrespondanceTable(CorrespondanceTable::ATTRIBUTES_AV, $this->t1db); $this->attr_av_corresp->reset(); }
public function testListWithTranslation() { $client = static::createClient(); $attributeAvCount = AttributeAvQuery::create()->count(); if ($attributeAvCount > 10) { $attributeAvCount = 10; } $client->request('GET', '/api/attribute-avs?lang=fr_FR&sign=' . $this->getSignParameter(''), [], [], $this->getServerParameters()); $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action'); $content = json_decode($client->getResponse()->getContent(), true); $this->assertCount($attributeAvCount, $content, "10 results must be return by default"); $firstResult = $content[0]; $this->assertEquals(1, $firstResult['IS_TRANSLATED'], 'content must be translated'); $this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the locale must be fr_FR'); }
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']]); }
public function checkCombination(ObjectCollection $productSaleElements) { $pse = $productSaleElements->getFirst(); $colorAttributeId = GoogleShopping::getConfigValue('attribute_color'); $sizeAttributeId = GoogleShopping::getConfigValue('attribute_size'); $color = false; $size = false; if (null !== $colorAttributeId) { $colorCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $colorAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne(); if (null !== $colorCombination) { $color = true; } } if (null !== $sizeAttributeId) { $sizeCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $sizeAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne(); if (null !== $sizeCombination) { $size = true; } } if (true === $color || true === $size) { return true; } return false; }
/** * Create a combination for a given product sale element * * @param ConnectionInterface $con the Propel connection * @param ProductSaleElements $salesElement the product sale element * @param array $combinationAttributes an array oif attributes av IDs */ protected function createCombination(ConnectionInterface $con, ProductSaleElements $salesElement, $combinationAttributes) { foreach ($combinationAttributes as $attributeAvId) { $attributeAv = AttributeAvQuery::create()->findPk($attributeAvId); if ($attributeAv !== null) { $attributeCombination = new AttributeCombination(); $attributeCombination->setAttributeAvId($attributeAvId)->setAttribute($attributeAv->getAttribute())->setProductSaleElements($salesElement)->save($con); } } }
/** * Performs an INSERT on the database, given a AttributeAv or Criteria object. * * @param mixed $criteria Criteria or AttributeAv 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(AttributeAvTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from AttributeAv object } if ($criteria->containsKey(AttributeAvTableMap::ID) && $criteria->keyContainsValue(AttributeAvTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeAvTableMap::ID . ')'); } // Set the correct dbName $query = AttributeAvQuery::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; }
/** * Get the associated ChildAttributeAv object * * @param ConnectionInterface $con Optional Connection object. * @return ChildAttributeAv The associated ChildAttributeAv object. * @throws PropelException */ public function getAttributeAv(ConnectionInterface $con = null) { if ($this->aAttributeAv === null && $this->attribute_av_id !== null) { $this->aAttributeAv = ChildAttributeAvQuery::create()->findPk($this->attribute_av_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAttributeAv->addAttributeCombinations($this); */ } return $this->aAttributeAv; }
/** * Changes position, selecting absolute ou relative change. * * @param UpdatePositionEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher */ public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $this->genericUpdatePosition(AttributeAvQuery::create(), $event); }
//\Thelia\Log\Tlog::getInstance()->setLevel(\Thelia\Log\Tlog::ERROR); try { $stmt = $con->prepare("SET foreign_key_checks = 0"); $stmt->execute(); echo "Clearing tables\n"; Model\ProductAssociatedContentQuery::create()->deleteAll(); Model\CategoryAssociatedContentQuery::create()->deleteAll(); Model\FeatureProductQuery::create()->deleteAll(); Model\AttributeCombinationQuery::create()->deleteAll(); Model\FeatureQuery::create()->deleteAll(); Model\FeatureI18nQuery::create()->deleteAll(); Model\FeatureAvQuery::create()->deleteAll(); Model\FeatureAvI18nQuery::create()->deleteAll(); Model\AttributeQuery::create()->deleteAll(); Model\AttributeI18nQuery::create()->deleteAll(); Model\AttributeAvQuery::create()->deleteAll(); Model\AttributeAvI18nQuery::create()->deleteAll(); Model\CategoryQuery::create()->deleteAll(); Model\CategoryI18nQuery::create()->deleteAll(); Model\ProductQuery::create()->deleteAll(); Model\ProductI18nQuery::create()->deleteAll(); Model\CustomerQuery::create()->deleteAll(); Model\AdminQuery::create()->deleteAll(); Model\FolderQuery::create()->deleteAll(); Model\FolderI18nQuery::create()->deleteAll(); Model\ContentQuery::create()->deleteAll(); Model\ContentI18nQuery::create()->deleteAll(); Model\AccessoryQuery::create()->deleteAll(); Model\ProductSaleElementsQuery::create()->deleteAll(); Model\ProductPriceQuery::create()->deleteAll(); Model\BrandQuery::create()->deleteAll();
public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination) { $result = array(); // Get attribute for this product $attributeAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAvId); if ($attributeAv !== null) { $addIt = true; $attribute = $attributeAv->getAttribute(); // Check if this attribute is not already present $combinationArray = explode(',', $combination); foreach ($combinationArray as $id) { $attrAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($id); if ($attrAv !== null) { if ($attrAv->getAttributeId() == $attribute->getId()) { $result['error'] = $this->getTranslator()->trans('A value for attribute "%name" is already present in the combination', array('%name' => $attribute->getTitle())); $addIt = false; } $result[] = array('id' => $attrAv->getId(), 'title' => $attrAv->getAttribute()->getTitle() . " : " . $attrAv->getTitle()); } } if ($addIt) { $result[] = array('id' => $attributeAv->getId(), 'title' => $attribute->getTitle() . " : " . $attributeAv->getTitle()); } } return $this->jsonResponse(json_encode($result)); }
/** * Changes position, selecting absolute ou relative change. * * @param CategoryChangePositionEvent $event */ public function updatePosition(UpdatePositionEvent $event) { $this->genericUpdatePosition(AttributeAvQuery::create(), $event); }
public function testUpdatePseSale() { $sale = $this->getRandomSale(); $date = new \DateTime(); $product = ProductQuery::create()->findOne(); $attrAv = AttributeAvQuery::create()->findOne(); $event = new SaleUpdateEvent($sale->getId()); $event->setStartDate($date->setTimestamp(strtotime("today - 1 month")))->setEndDate($date->setTimestamp(strtotime("today + 1 month")))->setActive(1)->setDisplayInitialPrice(1)->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)->setPriceOffsets([CurrencyQuery::create()->findOne()->getId() => 10])->setProducts([$product->getId()])->setProductAttributes([$product->getId() => [$attrAv->getId()]])->setLocale('en_US')->setTitle('test update sale title')->setChapo('test update sale short description')->setDescription('test update sale description')->setPostscriptum('test update sale postscriptum')->setSaleLabel('test create sale label'); $saleAction = new Sale($this->getMockEventDispatcher()); $saleAction->update($event, null, $this->getMockEventDispatcher()); $updatedSale = $event->getSale(); $this->assertInstanceOf('Thelia\\Model\\Sale', $updatedSale); $this->assertEquals(1, $updatedSale->getActive()); $this->assertEquals('test update sale title', $updatedSale->getTitle()); $this->assertEquals('test update sale short description', $updatedSale->getChapo()); $this->assertEquals('test update sale description', $updatedSale->getDescription()); $this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum()); $this->assertEquals('test create sale label', $updatedSale->getSaleLabel()); }
/** * Returns the number of related AttributeAv objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related AttributeAv objects. * @throws PropelException */ public function countAttributeAvs(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collAttributeAvsPartial && !$this->isNew(); if (null === $this->collAttributeAvs || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collAttributeAvs) { return 0; } if ($partial && !$criteria) { return count($this->getAttributeAvs()); } $query = ChildAttributeAvQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByAttribute($this)->count($con); } return count($this->collAttributeAvs); }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see AttributeAv::setDeleted() * @see AttributeAv::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(AttributeAvTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildAttributeAvQuery::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; } }
public function testCreateMultiplePSEInOneShot() { $client = static::createClient(); $product = $this->getProduct(); $currency = $this->getCurrency(); $taxRule = $this->getTaxRule(); $attributeAvs = AttributeAvQuery::create()->limit(2)->select(AttributeAvTableMap::ID)->find()->toArray(); $data = ["pse" => [["product_id" => $product->getId(), "tax_rule_id" => $taxRule->getId(), "currency_id" => $currency->getId(), "price" => "3.12", "reference" => "foo", "quantity" => 1, "attribute_av" => $attributeAvs, "onsale" => true, "isnew" => true], ["product_id" => $product->getId(), "tax_rule_id" => $taxRule->getId(), "currency_id" => $currency->getId(), "price" => "3.33", "reference" => "bar", "quantity" => 10, "attribute_av" => [$attributeAvs[0]], "onsale" => true, "isnew" => true], ["product_id" => $product->getId(), "tax_rule_id" => $taxRule->getId(), "currency_id" => $currency->getId(), "price" => "12.09", "reference" => "baz", "quantity" => 100, "attribute_av" => [$attributeAvs[1]], "onsale" => true, "isnew" => true]]]; $requestContent = json_encode($data); $servers = $this->getServerParameters(); $servers['CONTENT_TYPE'] = 'application/json'; $client->request('POST', '/api/pse?order=quantity&sign=' . $this->getSignParameter($requestContent), [], [], $servers, $requestContent); $this->assertEquals(201, $client->getResponse()->getStatusCode(), sprintf('Http status code must be 201. Error: %s', $client->getResponse()->getContent())); $content = json_decode($client->getResponse()->getContent(), true); $this->assertCount(3, $content); $this->assertEquals('3.12', $content[0]['PRICE']); $this->assertEquals('3.33', $content[1]['PRICE']); $this->assertEquals('12.09', $content[2]['PRICE']); $ids = array(); foreach ($content as $entry) { $ids[] = $entry["ID"]; } return $ids; }