/**
  * 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]);
     }
 }
示例#2
0
 public function checkDuplicateRef($value, ExecutionContextInterface $context)
 {
     $count = ProductQuery::create()->filterByRef($value)->count();
     if ($count > 0) {
         $context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value)));
     }
 }
 /**
  * @param $productId
  * @return array
  */
 public function getDelayForProduct($productId)
 {
     $delay = ProductDelayQuery::create()->filterByProductId($productId)->findOneOrCreate();
     $defaultDelay = (new ProductDelay())->getDefaultValue();
     $product = ProductQuery::create()->findOneById($productId);
     if (!$product) {
         return null;
     }
     $quantity = $this->productHasQuantity($product);
     if (true === $quantity) {
         $delayMin = $delay->getDeliveryDelayMin() ? $delay->getDeliveryDelayMin() : $defaultDelay->getDeliveryDelayMin();
         $delayMax = $delay->getDeliveryDelayMax() ? $delay->getDeliveryDelayMax() : $defaultDelay->getDeliveryDelayMax();
     } else {
         $delayMin = $delay->getRestockDelayMin() ? $delay->getRestockDelayMin() : $defaultDelay->getRestockDelayMin();
         $delayMax = $delay->getRestockDelayMax() ? $delay->getRestockDelayMax() : $defaultDelay->getRestockDelayMax();
     }
     $startDate = date("Y-m-d");
     $delivery["deliveryDateStart"] = null;
     if (null !== $delay->getDeliveryDateStart() && time() < strtotime($delay->getDeliveryDateStart())) {
         $startDate = $delivery["deliveryDateStart"] = $delay->getDeliveryDateStart();
     }
     $delivery["deliveryType"] = $delay->getDeliveryType();
     $delivery["deliveryMin"] = $this->computeDeliveryDate($startDate, $delayMin);
     $delivery["deliveryMax"] = $this->computeDeliveryDate($startDate, $delayMax);
     return $delivery;
 }
 public function parseResults(LoopResult $loopResult)
 {
     $loopResult = parent::parseResults($loopResult);
     /** @var LoopResultRow $loopResultRow */
     foreach ($loopResult as $loopResultRow) {
         // do nothing if no count is present (simple mode)
         if ($loopResultRow->get('PSE_COUNT') === null) {
             continue;
         }
         $product = ProductQuery::create()->findPk($loopResultRow->get('ID'));
         //  do nothing if we don't use legacy attributes for this product
         $productCheckEvent = new ProductCheckEvent($product->getId());
         $this->dispatcher->dispatch(LegacyProductAttributesEvents::PRODUCT_CHECK_LEGACY_ATTRIBUTES_APPLY, $productCheckEvent);
         if (!$productCheckEvent->getResult()) {
             continue;
         }
         // nothing to do if the product has no template (and thus no attributes)
         if ($product->getTemplate() === null) {
             continue;
         }
         $virtualPseCount = 1;
         foreach ($product->getTemplate()->getAttributes() as $attribute) {
             $virtualPseCount *= $attribute->countAttributeAvs();
         }
         $loopResultRow->set('PSE_COUNT', $virtualPseCount);
     }
     return $loopResult;
 }
示例#5
0
 public function testQuery()
 {
     new Translator(new Container());
     $export = new ProductSEOExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["ref", "visible", "product_title", "url", "page_title", "meta_description", "meta_keywords"];
     sort($keys);
     $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);
         $product = ProductQuery::create()->findOneByRef($row["ref"]);
         $this->assertNotNull($product);
         $this->assertEquals($product->getVisible(), $row["visible"]);
         $this->assertEquals($product->getTitle(), $row["product_title"]);
         $this->assertEquals($product->getMetaTitle(), $row["page_title"]);
         $this->assertEquals($product->getMetaDescription(), $row["meta_description"]);
         $this->assertEquals($product->getMetaKeywords(), $row["meta_keywords"]);
         $this->assertEquals($product->getRewrittenUrl("en_US"), $row["url"]);
     }
 }
示例#6
0
 public function testCreate()
 {
     // get a product
     $product = ProductQuery::create()->findOne();
     // simple
     $event = new MetaDataCreateOrUpdateEvent();
     $event->setMetaKey('test')->setElementKey(get_class($product))->setElementId($product->getId())->setValue('test')->setDispatcher($this->dispatcher);
     $action = new MetaData();
     $action->createOrUpdate($event);
     $created = $event->getMetaData();
     $this->assertInstanceOf('Thelia\\Model\\MetaData', $created);
     $this->assertFalse($created->isNew());
     $this->assertEquals('test', $created->getMetaKey());
     $this->assertEquals(get_class($product), $created->getElementKey());
     $this->assertEquals($product->getId(), $created->getElementId());
     $this->assertEquals('test', $created->getValue());
     $this->assertEquals(false, $created->getIsSerialized());
     // complex
     $event = new MetaDataCreateOrUpdateEvent();
     $event->setMetaKey('test2')->setElementKey(get_class($product))->setElementId($product->getId())->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"))->setDispatcher($this->dispatcher);
     $action = new MetaData();
     $action->createOrUpdate($event);
     $created = $event->getMetaData();
     $this->assertInstanceOf('Thelia\\Model\\MetaData', $created);
     $this->assertFalse($created->isNew());
     $this->assertEquals('test2', $created->getMetaKey());
     $this->assertEquals(get_class($product), $created->getElementKey());
     $this->assertEquals($product->getId(), $created->getElementId());
     $this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $created->getValue());
     $this->assertEquals(true, $created->getIsSerialized());
     return $product;
 }
 public function onMainBodyBottom(HookRenderEvent $event)
 {
     $options = array();
     switch ($this->getRequest()->get('_view')) {
         // Category page viewed
         case 'category':
             $categoryId = $this->getRequest()->get('category_id');
             $defaultCategory = CategoryQuery::create()->findPk($categoryId);
             $options[] = array('setEcommerceView', false, false, $defaultCategory->getTitle());
             break;
             // Product detail page viewed
         // Product detail page viewed
         case 'product':
             $productId = $this->getRequest()->getProductId();
             $product = ProductQuery::create()->findPk($productId);
             if ($defaultCategoryId = $product->getDefaultCategoryId()) {
                 $defaultCategory = CategoryQuery::create()->findPk($defaultCategoryId);
             }
             $options[] = array('setEcommerceView', $product->getRef() ? $product->getRef() : $product->getId(), $product->getTitle(), isset($defaultCategory) ? $defaultCategory->getTitle() : false, false);
             break;
     }
     if ($code = $this->generateTrackingCode($options)) {
         $event->add($code);
     }
 }
示例#8
0
 public function checkRefDifferent($value, ExecutionContextInterface $context)
 {
     $originalRef = ProductQuery::create()->filterByRef($value, Criteria::EQUAL)->count();
     if ($originalRef !== 0) {
         $context->addViolation($this->translator->trans('This product reference is already assigned to another product.'));
     }
 }
示例#9
0
 public function checkProduct($value, ExecutionContextInterface $context)
 {
     $product = ProductQuery::create()->findPk($value);
     if (is_null($product) || $product->getVisible() == 0) {
         throw new ProductNotFoundException(sprintf(Translator::getInstance()->trans("this product id does not exists : %d"), $value));
     }
 }
 /**
  * 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));
 }
 public function find(FindViewEvent $event)
 {
     $objectType = $event->getObjectType();
     $objectId = $event->getObjectId();
     // Try to find a direct match. A view is defined for the object.
     if (null !== ($viewObj = ViewQuery::create()->filterBySourceId($objectId)->findOneBySource($objectType))) {
         $viewName = $viewObj->getView();
         if (!empty($viewName)) {
             $event->setView($viewName)->setViewObject($viewObj);
             return;
         }
     }
     $foundView = $sourceView = null;
     if ($objectType == 'category') {
         $foundView = $this->searchInParents($objectId, $objectType, CategoryQuery::create(), false, $sourceView);
     } elseif ($objectType == 'folder') {
         $foundView = $this->searchInParents($objectId, $objectType, FolderQuery::create(), false, $sourceView);
     } elseif ($objectType == 'product') {
         if (null !== ($product = ProductQuery::create()->findPk($objectId))) {
             $foundView = $this->searchInParents($product->getDefaultCategoryId(), 'category', CategoryQuery::create(), true, $sourceView);
         }
     } elseif ($objectType == 'content') {
         if (null !== ($content = ContentQuery::create()->findPk($objectId))) {
             $foundView = $this->searchInParents($content->getDefaultFolderId(), 'folder', FolderQuery::create(), true, $sourceView);
         }
     }
     $event->setView($foundView)->setViewObject($sourceView);
 }
示例#12
0
 public function getData()
 {
     $locale = $this->language->getLocale();
     $urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
     $productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
     $query = ProductQuery::create()->addSelfSelectColumns()->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)->addAsColumn('product_i18n_TITLE', ProductI18nTableMap::TITLE)->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);
     return $query;
 }
示例#13
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $currency = CurrencyQuery::create()->filterByCode('EUR')->findOne();
     // Find a product
     $this->freeProduct = ProductQuery::create()->findOne();
     $this->originalPrice = $this->freeProduct->getDefaultSaleElements()->getPricesByCurrency($currency)->getPrice();
     $this->originalPromo = $this->freeProduct->getDefaultSaleElements()->getPromo();
     $this->freeProduct->getDefaultSaleElements()->setPromo(false)->save();
 }
示例#14
0
 /**
  * @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;
 }
示例#15
0
 /**
  *
  * count all products for current category and sub categories
  *
  * /!\ the number of queries is exponential, use it with caution
  *
  * @return int
  */
 public function countAllProducts()
 {
     $children = CategoryQuery::findAllChild($this->getId());
     array_push($children, $this);
     $countProduct = 0;
     foreach ($children as $child) {
         $countProduct += ProductQuery::create()->filterByCategory($child)->count();
     }
     return $countProduct;
 }
 public function trackOrder(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $order = $event->getPlacedOrder();
     $taxTotal = 0;
     foreach ($order->getOrderProducts() as $orderProduct) {
         $product = ProductQuery::create()->findPk($orderProduct->getVirtualColumn('product_id'));
         $defaultCategory = CategoryQuery::create()->findPk($product->getDefaultCategoryId());
         $taxTotal += $orderProduct->getVirtualColumn('TOTAL_TAX');
         $this->tracker->addEcommerceItem($orderProduct->getProductSaleElementsRef() || $orderProduct->getProductRef() || $orderProduct->getId() || $orderProduct->getProductSaleElementsId(), $orderProduct->getTitle(), $defaultCategory->getTitle(), $orderProduct->getPrice(), $orderProduct->getQuantity());
     }
     $this->tracker->doTrackEcommerceOrder($order->getRef(), $order->getTotalAmount($taxTotal, true, true), $order->getTotalAmount($taxTotal, false, true), $taxTotal, $order->getPostage() + $order->getPostageTax(), $order->getDiscount());
 }
示例#17
0
 /**
  * Delete a product template entry
  *
  * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
  */
 public function delete(TemplateDeleteEvent $event)
 {
     if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
         // Check if template is used by a product
         $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count();
         if ($product_count <= 0) {
             $template->setDispatcher($event->getDispatcher())->delete();
         }
         $event->setTemplate($template);
         $event->setProductCount($product_count);
     }
 }
示例#18
0
 public function onMainBeforeContent(HookRenderEvent $event)
 {
     if ($this->securityContext->isGranted(["ADMIN"], [AdminResources::PRODUCT], [], [AccessManager::VIEW])) {
         $products = ProductQuery::create()->filterByVirtual(1)->filterByVisible(1)->count();
         if ($products > 0) {
             $deliveryModule = ModuleQuery::create()->retrieveVirtualProductDelivery();
             if (false === $deliveryModule) {
                 $event->add($this->render('virtual-delivery-warning.html'));
             }
         }
     }
 }
 public function testGetAction()
 {
     $client = static::createClient();
     $product = ProductQuery::create()->joinProductImage()->findOne();
     if (null === $product) {
         $this->markTestSkipped("This test can't be run as there is no product that has an image");
     }
     $productImage = $product->getProductImages()->get(0);
     $client->request('GET', '/api/products/' . $product->getId() . '/images/' . $productImage->getId() . '?sign=' . $this->getSignParameter(""), [], [], $this->getServerParameters());
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
     $content = json_decode($client->getResponse()->getContent(), true);
     $this->assertCount(1, $content, 'image get action must retrieve 1 image');
 }
示例#20
0
 public function testSearchByIdComplex()
 {
     $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
     if (null === $product) {
         $product = new \Thelia\Model\Product();
         $product->setDefaultCategory(0);
         $product->setVisible(1);
         $product->setTitle('foo');
         $product->save();
     }
     $otherParameters = array("visible" => "*", "complex" => 1);
     $this->baseTestSearchById($product->getId(), $otherParameters);
 }
 /**
  * Get the selected legacy product attributes.
  *
  * @param CartEvent $event
  */
 protected function getLegacyProductAttributes(CartEvent $event)
 {
     $product = ProductQuery::create()->findPk($event->getProduct());
     $productAttributes = $product->getTemplate()->getAttributes();
     $this->legacyProductAttributes = [];
     /** @var Attribute $productAttribute */
     foreach ($productAttributes as $productAttribute) {
         $legacyProductAttributeFieldKey = CartAddFormExtension::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId();
         if ($event->{$legacyProductAttributeFieldKey} !== null) {
             $this->legacyProductAttributes[$productAttribute->getId()] = $event->{$legacyProductAttributeFieldKey};
         }
     }
 }
示例#22
0
 /**
  * Insert the legacy product attributes configuration tab.
  *
  * @param HookRenderBlockEvent $event
  */
 public function onProductTab(HookRenderBlockEvent $event)
 {
     $product = ProductQuery::create()->findPk($event->getArgument('id'));
     $productCheckEvent = new ProductCheckEvent($this->getRequest()->getProductId());
     $this->dispatcher->dispatch(LegacyProductAttributesEvents::PRODUCT_CHECK_LEGACY_ATTRIBUTES_APPLY, $productCheckEvent);
     if (!$productCheckEvent->getResult()) {
         $content = $this->render('product-edit-tab-legacy-product-attributes-does-not-apply.html');
     } elseif ($product->getTemplate() === null) {
         $content = $this->render('product-edit-tab-legacy-product-attributes-no-template.html');
     } else {
         $content = $this->render('product-edit-tab-legacy-product-attributes.html');
     }
     $event->add(['id' => 'legacy-product-attributes', 'title' => Translator::getInstance()->trans('Attributes configuration', [], LegacyProductAttributes::MESSAGE_DOMAIN_BO), 'content' => $content]);
 }
 /**
  * Get the selected product attribute values from the card add form.
  *
  * @param Form $form Cart add form.
  *
  * @return array A map of attribute ids => selected attribute value id.
  */
 protected function getLegacyProductAttributesInForm(Form $form)
 {
     $product = ProductQuery::create()->findPk($form->get('product')->getData());
     if (null === $product) {
         return [];
     }
     $legacyProductAttributes = [];
     foreach ($product->getTemplate()->getAttributes() as $attribute) {
         $legacyProductAttributeFieldKey = CartAddFormExtension::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $attribute->getId();
         if (null !== $form->get($legacyProductAttributeFieldKey)) {
             $legacyProductAttributes[$attribute->getId()] = $form->get($legacyProductAttributeFieldKey)->getData();
         }
     }
     return $legacyProductAttributes;
 }
示例#24
0
 public function preImport()
 {
     // Delete table before proceeding
     ProductQuery::create()->deleteAll();
     CategoryQuery::create()->deleteAll();
     FeatureTemplateQuery::create()->deleteAll();
     AttributeTemplateQuery::create()->deleteAll();
     TemplateQuery::create()->deleteAll();
     CategoryImageQuery::create()->deleteAll();
     CategoryDocumentQuery::create()->deleteAll();
     CategoryAssociatedContentQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->cat_corresp->reset();
     $this->tpl_corresp->reset();
 }
示例#25
0
 public function parseResults(LoopResult $loopResult)
 {
     foreach ($loopResult->getResultDataCollection() as $digressivePrice) {
         $loopResultRow = new LoopResultRow($digressivePrice);
         // Get product
         $productId = $digressivePrice->getProductId();
         $product = ProductQuery::create()->findOneById($productId);
         // Get prices
         $price = $digressivePrice->getPrice();
         $promo = $digressivePrice->getPromoPrice();
         // Get country
         $taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
         // Get taxed prices
         $taxedPrice = $product->getTaxedPrice($taxCountry, $price);
         $taxedPromoPrice = $product->getTaxedPromoPrice($taxCountry, $promo);
         $loopResultRow->set("ID", $digressivePrice->getId())->set("PRODUCT_ID", $productId)->set("QUANTITY_FROM", $digressivePrice->getQuantityFrom())->set("QUANTITY_TO", $digressivePrice->getQuantityTo())->set("PRICE", $price)->set("PROMO_PRICE", $promo)->set("TAXED_PRICE", $taxedPrice)->set("TAXED_PROMO_PRICE", $taxedPromoPrice);
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
 public function buildModelCriteria()
 {
     $categoryId = $this->getCategoryId();
     $productId = $this->getProductId();
     $productOrders = $this->getProductOrder();
     $query = ProductQuery::create()->joinWithI18n($this->getLocale());
     if (true === $this->getVisible()) {
         $query->filterByVisible(true);
     }
     if ($categoryId) {
         $query->useProductCategoryQuery()->filterByDefaultCategory(true)->filterByCategoryId($categoryId)->endUse();
     }
     if ($productId) {
         $query->filterById($productId);
     }
     if ($productOrders) {
         foreach ($productOrders as $productOrder) {
             switch ($productOrder) {
                 case "id":
                     $query->orderById(Criteria::ASC);
                     break;
                 case "id_reverse":
                     $query->orderById(Criteria::DESC);
                     break;
                 case "alpha":
                     $query->addAscendingOrderByColumn('product_i18n.TITLE');
                     break;
                 case "alpha_reverse":
                     $query->addDescendingOrderByColumn('product_i18n.TITLE');
                     break;
                 case "ref":
                     $query->orderByRef(Criteria::ASC);
                     break;
                 case "ref_reverse":
                     $query->orderByRef(Criteria::DESC);
                     break;
             }
         }
     }
     return $query;
 }
示例#27
0
 public function testUpdateUrl()
 {
     $object = null;
     $event = $this->getUpdateSeoEvent($object);
     $event->setDispatcher($this->dispatcher);
     $currentUrl = $object->getRewrittenUrl($object->getLocale());
     /* get a brand new URL */
     $exist = true;
     while (true === $exist) {
         $newUrl = md5(rand(1, 999999)) . ".html";
         try {
             new RewritingResolver($newUrl);
         } catch (UrlRewritingException $e) {
             if ($e->getCode() === UrlRewritingException::URL_NOT_FOUND) {
                 /* It's all good if URL is not found */
                 $exist = false;
             } else {
                 throw $e;
             }
         }
     }
     $event->setUrl($newUrl);
     $updatedObject = $this->processUpdateSeoAction($event);
     /* new URL is updated */
     $this->assertEquals($newUrl, $updatedObject->getRewrittenUrl($object->getLocale()));
     /* old url must be redirected to the new one */
     $newUrlEntry = RewritingUrlQuery::create()->findOneByUrl($newUrl);
     $oldUrlEntry = RewritingUrlQuery::create()->findOneByUrl($currentUrl);
     $this->assertEquals($oldUrlEntry->getRedirected(), $newUrlEntry->getId());
     /* we can reassign old Url to another object */
     $aRandomProduct = ProductQuery::create()->filterById($object->getId(), Criteria::NOT_EQUAL)->findOne();
     $failReassign = true;
     try {
         $aRandomProduct->setRewrittenUrl($aRandomProduct->getLocale(), $currentUrl);
         $failReassign = false;
     } catch (\Exception $e) {
     }
     $this->assertFalse($failReassign);
 }
 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']]);
 }
示例#29
0
 /**
  * Delete a product template entry
  *
  * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
  * @throws \Exception
  */
 public function delete(TemplateDeleteEvent $event)
 {
     if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
         // Check if template is used by a product
         $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count();
         if ($product_count <= 0) {
             $con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME);
             $con->beginTransaction();
             try {
                 $template->setDispatcher($event->getDispatcher())->delete($con);
                 // We have to also delete any reference of this template in category tables
                 // We can't use a FK here, as the DefaultTemplateId column may be NULL
                 // so let's take care of this.
                 CategoryQuery::create()->filterByDefaultTemplateId($event->getTemplateId())->update(['DefaultTemplateId' => null], $con);
                 $con->commit();
             } catch (\Exception $ex) {
                 $con->rollback();
                 throw $ex;
             }
         }
         $event->setTemplate($template);
         $event->setProductCount($product_count);
     }
 }
示例#30
0
 public function testDeleteFileProductImage()
 {
     $this->doTestDeleteFile(new ProductImage(), ProductQuery::create()->findOne(), 'images', 'product');
 }