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;
 }
 public function onCriteriaSearchSearchPage(HookRenderEvent $event)
 {
     $request = $this->getRequest();
     $params['category_id'] = $event->getArgument('category_id');
     $categorieTaxeRule = CriteriaSearchCategoryTaxRuleQuery::create()->findOneByCategoryId($params['category_id']);
     //Enable price filter only if a tax rule is chosen for this category
     if (null !== $categorieTaxeRule && null !== $categorieTaxeRule->getTaxRuleId()) {
         $params['price_filter'] = CriteriaSearch::getConfigValue('price_filter');
     }
     $params['brand_filter'] = CriteriaSearch::getConfigValue('brand_filter');
     $params['new_filter'] = CriteriaSearch::getConfigValue('new_filter');
     $params['promo_filter'] = CriteriaSearch::getConfigValue('promo_filter');
     $params['stock_filter'] = CriteriaSearch::getConfigValue('stock_filter');
     $this->criteriaSearchHandler->getLoopParamsFromQuery($params, $request);
     if (null !== $params['category_id']) {
         $categoryProductMaxPrice = ProductPriceQuery::create()->useProductSaleElementsQuery()->useProductQuery()->useProductCategoryQuery()->filterByCategoryId($params['category_id'])->endUse()->endUse()->endUse()->select('price')->orderBy('price', Criteria::DESC)->limit(1)->findOne();
         $params['max_price_filter'] = ceil($categoryProductMaxPrice / 10) * 10;
         if ($params['max_price_filter'] > 0) {
             $params['value_price_filter'] = [];
             $priceSlice = $params['max_price_filter'] / 4;
             for ($i = 0; $i <= $params['max_price_filter']; $i = $i + $priceSlice) {
                 $params['value_price_filter'][] = $i;
             }
         }
     }
     $event->add($this->render('criteria-search/search-page.html', $params));
 }
 public static function indexProduct(Product $product)
 {
     /************************************
      * Get name of index and handler to work with OSS API
      ************************************/
     $index = OpensearchserverConfigQuery::read('index_name');
     $oss_api = OpenSearchServerSearchHelper::getHandler();
     /************************************
      * Create/update document
      ************************************/
     //get price from first combination SaleElement
     $collSaleElements = $product->getProductSaleElementss();
     $infos = $collSaleElements->getFirst()->toArray();
     $price = ProductPriceQuery::create()->findOneByProductSaleElementsId($infos['Id'])->toArray();
     //create one document by translation
     $translations = $product->getProductI18ns();
     //Prepare request for OSS
     $request = new \OpenSearchServer\Document\Put();
     $request->index($index);
     foreach ($translations as $translation) {
         $document = new \OpenSearchServer\Document\Document();
         $productI18nInfos = $translation->toArray();
         switch ($productI18nInfos['Locale']) {
             case 'fr_Fr':
             case 'fr_FR':
                 $document->lang(\OpenSearchServer\Request::LANG_FR);
                 break;
             case 'en_EN':
             case 'en_US':
                 $document->lang(\OpenSearchServer\Request::LANG_EN);
                 break;
             case 'es_ES':
                 $document->lang(\OpenSearchServer\Request::LANG_ES);
                 break;
             case 'it_IT':
                 $document->lang(\OpenSearchServer\Request::LANG_IT);
                 break;
             case 'ru_RU':
                 $document->lang(\OpenSearchServer\Request::LANG_RU);
                 break;
             default:
                 $document->lang(\OpenSearchServer\Request::LANG_UNDEFINED);
                 break;
         }
         $document->field('uniqueId', OpenSearchServerSearchHelper::makeProductUniqueId($productI18nInfos['Locale'], $product))->field('id', $product->getId())->field('title', $productI18nInfos['Title'])->field('locale', $productI18nInfos['Locale'])->field('description', $productI18nInfos['Description'])->field('chapo', $productI18nInfos['Chapo'])->field('price', self::formatPrice($price['Price']))->field('currency', $price['CurrencyId'])->field('reference', $product->getRef());
         $request->addDocument($document);
     }
     $response = $oss_api->submit($request);
     return $response->isSuccess();
     //var_dump($oss_api->getLastRequest());
     //var_dump($response);
     //exit;
 }
 /**
  * Set the good item's price when added to cart
  *
  * @param CartEvent $event
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function itemAddedToCart(CartEvent $event)
 {
     $cartItem = $event->getCartItem();
     // Check if the product has some digressive prices
     $dpq = DigressivePriceQuery::create()->findByProductId($cartItem->getProductId());
     if (count($dpq) != 0) {
         // Check if the quantity is into a range
         $dpq = DigressivePriceQuery::create()->filterByProductId($cartItem->getProductId())->filterByQuantityFrom($cartItem->getQuantity(), Criteria::LESS_EQUAL)->filterByQuantityTo($cartItem->getQuantity(), Criteria::GREATER_EQUAL)->find();
         if ($dpq->count() === 1) {
             // Change cart item's prices with those from the corresponding range
             $cartItem->setPrice($dpq[0]->getPrice())->setPromoPrice($dpq[0]->getPromoPrice())->save();
         } else {
             // Change cart item's prices with the default out of range ones
             $prices = ProductPriceQuery::create()->findOneByProductSaleElementsId($cartItem->getProductSaleElementsId());
             $cartItem->setPrice($prices->getPrice())->setPromoPrice($prices->getPromoPrice())->save();
         }
     }
 }
예제 #5
0
 /**
  * @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;
 }
예제 #6
0
파일: faker.php 프로젝트: hadesain/thelia
 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();
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 Model\BrandImageQuery::create()->deleteAll();
 Model\ProductDocumentQuery::create()->deleteAll();
 Model\CategoryDocumentQuery::create()->deleteAll();
 Model\FolderDocumentQuery::create()->deleteAll();
 Model\ContentDocumentQuery::create()->deleteAll();
 Model\BrandDocumentQuery::create()->deleteAll();
 Model\CouponQuery::create()->deleteAll();
 Model\OrderQuery::create()->deleteAll();
 Model\SaleQuery::create()->deleteAll();
예제 #7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see ProductPrice::setDeleted()
  * @see ProductPrice::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(ProductPriceTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildProductPriceQuery::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;
     }
 }
예제 #8
0
파일: import.php 프로젝트: alex63530/thelia
function clearTables($con)
{
    echo "Clearing tables\n";
    $productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create()->find($con);
    $productAssociatedContent->delete($con);
    $categoryAssociatedContent = Thelia\Model\CategoryAssociatedContentQuery::create()->find($con);
    $categoryAssociatedContent->delete($con);
    $featureProduct = Thelia\Model\FeatureProductQuery::create()->find($con);
    $featureProduct->delete($con);
    $attributeCombination = Thelia\Model\AttributeCombinationQuery::create()->find($con);
    $attributeCombination->delete($con);
    $feature = Thelia\Model\FeatureQuery::create()->find($con);
    $feature->delete($con);
    $feature = Thelia\Model\FeatureI18nQuery::create()->find($con);
    $feature->delete($con);
    $featureAv = Thelia\Model\FeatureAvQuery::create()->find($con);
    $featureAv->delete($con);
    $featureAv = Thelia\Model\FeatureAvI18nQuery::create()->find($con);
    $featureAv->delete($con);
    $attribute = Thelia\Model\AttributeQuery::create()->find($con);
    $attribute->delete($con);
    $attribute = Thelia\Model\AttributeI18nQuery::create()->find($con);
    $attribute->delete($con);
    $attributeAv = Thelia\Model\AttributeAvQuery::create()->find($con);
    $attributeAv->delete($con);
    $attributeAv = Thelia\Model\AttributeAvI18nQuery::create()->find($con);
    $attributeAv->delete($con);
    $brand = Thelia\Model\BrandQuery::create()->find($con);
    $brand->delete($con);
    $brand = Thelia\Model\BrandI18nQuery::create()->find($con);
    $brand->delete($con);
    $category = Thelia\Model\CategoryQuery::create()->find($con);
    $category->delete($con);
    $category = Thelia\Model\CategoryI18nQuery::create()->find($con);
    $category->delete($con);
    $product = Thelia\Model\ProductQuery::create()->find($con);
    $product->delete($con);
    $product = Thelia\Model\ProductI18nQuery::create()->find($con);
    $product->delete($con);
    $folder = Thelia\Model\FolderQuery::create()->find($con);
    $folder->delete($con);
    $folder = Thelia\Model\FolderI18nQuery::create()->find($con);
    $folder->delete($con);
    $content = Thelia\Model\ContentQuery::create()->find($con);
    $content->delete($con);
    $content = Thelia\Model\ContentI18nQuery::create()->find($con);
    $content->delete($con);
    $accessory = Thelia\Model\AccessoryQuery::create()->find($con);
    $accessory->delete($con);
    $stock = \Thelia\Model\ProductSaleElementsQuery::create()->find($con);
    $stock->delete($con);
    $productPrice = \Thelia\Model\ProductPriceQuery::create()->find($con);
    $productPrice->delete($con);
    \Thelia\Model\ProductImageQuery::create()->find($con)->delete($con);
    $customer = Thelia\Model\CustomerQuery::create()->find($con);
    $customer->delete($con);
    echo "Tables cleared with success\n";
}
예제 #9
0
 public function preImport()
 {
     // Delete table before proceeding
     ProductQuery::create()->deleteAll();
     ProductImageQuery::create()->deleteAll();
     ProductDocumentQuery::create()->deleteAll();
     TaxRuleQuery::create()->deleteAll();
     TaxQuery::create()->deleteAll();
     ProductSaleElementsQuery::create()->deleteAll();
     ProductPriceQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->product_corresp->reset();
     $this->tax_corresp->reset();
     // Importer les taxes
     $this->importTaxes();
 }
예제 #10
0
 /**
  * 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)));
 }
예제 #11
0
 $customer->delete();
 $admin = Thelia\Model\AdminQuery::create()->find();
 $admin->delete();
 $folder = Thelia\Model\FolderQuery::create()->find();
 $folder->delete();
 $folder = Thelia\Model\FolderI18nQuery::create()->find();
 $folder->delete();
 $content = Thelia\Model\ContentQuery::create()->find();
 $content->delete();
 $content = Thelia\Model\ContentI18nQuery::create()->find();
 $content->delete();
 $accessory = Thelia\Model\AccessoryQuery::create()->find();
 $accessory->delete();
 $stock = \Thelia\Model\ProductSaleElementsQuery::create()->find();
 $stock->delete();
 $productPrice = \Thelia\Model\ProductPriceQuery::create()->find();
 $productPrice->delete();
 $brand = Thelia\Model\BrandQuery::create()->find();
 $brand->delete();
 $brand = Thelia\Model\BrandI18nQuery::create()->find();
 $brand->delete();
 \Thelia\Model\ProductImageQuery::create()->find()->delete();
 \Thelia\Model\CategoryImageQuery::create()->find()->delete();
 \Thelia\Model\FolderImageQuery::create()->find()->delete();
 \Thelia\Model\ContentImageQuery::create()->find()->delete();
 \Thelia\Model\BrandImageQuery::create()->find()->delete();
 \Thelia\Model\ProductDocumentQuery::create()->find()->delete();
 \Thelia\Model\CategoryDocumentQuery::create()->find()->delete();
 \Thelia\Model\FolderDocumentQuery::create()->find()->delete();
 \Thelia\Model\ContentDocumentQuery::create()->find()->delete();
 \Thelia\Model\BrandDocumentQuery::create()->find()->delete();
예제 #12
0
파일: Product.php 프로젝트: savvagee/thelia
 /**
  * @param ProductCloneEvent $event
  * @throws \Exception
  */
 public function cloneProduct(ProductCloneEvent $event)
 {
     $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         // Get important datas
         $lang = $event->getLang();
         $originalProduct = $event->getOriginalProduct();
         $dispatcher = $event->getDispatcher();
         $originalProductDefaultI18n = ProductI18nQuery::create()->findPk([$originalProduct->getId(), $lang]);
         $originalProductDefaultPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalProduct->getDefaultSaleElements()->getId());
         // Cloning process
         $this->createClone($event, $originalProductDefaultI18n, $originalProductDefaultPrice);
         $this->updateClone($event, $originalProductDefaultPrice);
         $this->cloneFeatureCombination($event);
         $this->cloneAssociatedContent($event);
         // Dispatch event for file cloning
         $dispatcher->dispatch(TheliaEvents::FILE_CLONE, $event);
         // Dispatch event for PSE cloning
         $dispatcher->dispatch(TheliaEvents::PSE_CLONE, $event);
         $con->commit();
     } catch (\Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
예제 #13
0
 public function updateClonePSE(ProductCloneEvent $event, $clonedProductPSEId, ProductSaleElements $originalProductPSE, $key)
 {
     $originalProductPSEPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalProductPSE->getId());
     $clonedProductUpdatePSEEvent = new ProductSaleElementUpdateEvent($event->getClonedProduct(), $clonedProductPSEId);
     $clonedProductUpdatePSEEvent->setReference($event->getClonedProduct()->getRef() . '-' . ($key + 1))->setIsdefault($originalProductPSE->getIsDefault())->setFromDefaultCurrency(0)->setWeight($originalProductPSE->getWeight())->setQuantity($originalProductPSE->getQuantity())->setOnsale($originalProductPSE->getPromo())->setIsnew($originalProductPSE->getNewness())->setEanCode($originalProductPSE->getEanCode())->setTaxRuleId($event->getOriginalProduct()->getTaxRuleId())->setPrice($originalProductPSEPrice->getPrice())->setSalePrice($originalProductPSEPrice->getPromoPrice())->setCurrencyId($originalProductPSEPrice->getCurrencyId());
     $this->eventDispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $clonedProductUpdatePSEEvent);
 }
예제 #14
0
 /**
  * Update an existing product sale element
  *
  * @param  ProductSaleElementUpdateEvent $event
  * @throws \Exception
  */
 public function update(ProductSaleElementUpdateEvent $event)
 {
     $salesElement = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId());
     $con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         // Update the product's tax rule
         $event->getProduct()->setTaxRuleId($event->getTaxRuleId())->save($con);
         // If product sale element is not defined, create it.
         if ($salesElement == null) {
             $salesElement = new ProductSaleElements();
             $salesElement->setProduct($event->getProduct());
         }
         // If this PSE is the default one, be sure to have *only one* default for this product
         if ($event->getIsDefault()) {
             ProductSaleElementsQuery::create()->filterByProduct($event->getProduct())->filterByIsDefault(true)->filterById($event->getProductSaleElementId(), Criteria::NOT_EQUAL)->update(['IsDefault' => false], $con);
         }
         // Update sale element
         $salesElement->setRef($event->getReference())->setQuantity($event->getQuantity())->setPromo($event->getOnsale())->setNewness($event->getIsnew())->setWeight($event->getWeight())->setIsDefault($event->getIsDefault())->setEanCode($event->getEanCode())->save();
         // Update/create price for current currency
         $productPrice = ProductPriceQuery::create()->filterByCurrencyId($event->getCurrencyId())->filterByProductSaleElementsId($salesElement->getId())->findOne($con);
         // If price is not defined, create it.
         if ($productPrice == null) {
             $productPrice = new ProductPrice();
             $productPrice->setProductSaleElements($salesElement)->setCurrencyId($event->getCurrencyId());
         }
         // Check if we have to store the price
         $productPrice->setFromDefaultCurrency($event->getFromDefaultCurrency());
         if ($event->getFromDefaultCurrency() == 0) {
             // Store the price
             $productPrice->setPromoPrice($event->getSalePrice())->setPrice($event->getPrice());
         } else {
             // Do not store the price.
             $productPrice->setPromoPrice(0)->setPrice(0);
         }
         $productPrice->save($con);
         // Store all the stuff !
         $con->commit();
     } catch (\Exception $ex) {
         $con->rollback();
         throw $ex;
     }
 }
 /**
  * Performs an INSERT on the database, given a ProductPrice or Criteria object.
  *
  * @param mixed               $criteria Criteria or ProductPrice 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(ProductPriceTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from ProductPrice object
     }
     // Set the correct dbName
     $query = ProductPriceQuery::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;
 }
예제 #16
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this ProductSaleElements is new, it will return
  * an empty collection; or if this ProductSaleElements has previously
  * been saved, it will retrieve related ProductPrices from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in ProductSaleElements.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return Collection|ChildProductPrice[] List of ChildProductPrice objects
  */
 public function getProductPricesJoinCurrency($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildProductPriceQuery::create(null, $criteria);
     $query->joinWith('Currency', $joinBehavior);
     return $this->getProductPrices($query, $con);
 }
 protected function retrievePrices(ProductSaleElements $pse)
 {
     $query = ProductPriceQuery::create()->useCurrencyQuery()->orderByByDefault()->endUse();
     $prices = $pse->getProductPrices($query);
     if ($prices->count() === 0) {
         return array(null, null, null, null);
     }
     /** @var \Thelia\Model\ProductPrice $currentPrices */
     $currentPrices = $prices->get(0);
     return [$currentPrices->getPrice(), $currentPrices->getPromoPrice(), $currentPrices->getCurrencyId(), $currentPrices->getFromDefaultCurrency()];
 }
예제 #18
0
 /**
  * @covers \Thelia\Action\ProductSaleElement::updateClonePSE
  * @depends testCreateClonePSE
  * @param array $params
  * @return array
  */
 public function testUpdateClonePSE(array $params)
 {
     $event = $params['event'];
     $originalPSE = $params['originalPSE'];
     $clonePSE = $params['clonePSE'];
     // Call function to test
     $action = new ProductSaleElement();
     $action->updateClonePSE($event, $clonePSE->getId(), $originalPSE, 1);
     // Get updated PSE
     $clonePSE = ProductSaleElementsQuery::create()->findOneById($clonePSE->getId());
     // Check clone PSE information
     $this->assertInstanceOf('Thelia\\Model\\ProductSaleElements', $clonePSE, 'Instance of clone PSE must be Thelia\\Model\\ProductSaleElements');
     $this->assertStringStartsWith($event->getClonedProduct()->getRef(), $clonePSE->getRef(), 'PSE\'s ref must start with product\'s ref');
     $this->assertEquals($originalPSE->getQuantity(), $clonePSE->getQuantity(), 'Quantity must be equal');
     $this->assertEquals($originalPSE->getPromo(), $clonePSE->getPromo(), 'Promo must be equal');
     $this->assertEquals($originalPSE->getNewness(), $clonePSE->getNewness(), 'Newness must be equal');
     $this->assertEquals($originalPSE->getWeight(), $clonePSE->getWeight(), 'Weight must be equal');
     $this->assertEquals($originalPSE->getIsDefault(), $clonePSE->getIsDefault(), 'IsDefault must be equal');
     $this->assertEquals($originalPSE->getEanCode(), $clonePSE->getEanCode(), 'EAN code must be equal');
     // Get PSE's product price
     $originalProductPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalPSE->getId());
     $cloneProductPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($clonePSE->getId());
     // Check clone PSE's product price
     $this->assertInstanceOf('Thelia\\Model\\ProductPrice', $cloneProductPrice, 'Instance of clone product price must be Thelia\\Model\\ProductPrice');
     $this->assertEquals($originalProductPrice->getCurrencyId(), $cloneProductPrice->getCurrencyId(), 'CurrencyID must be equal');
     $this->assertEquals($originalProductPrice->getPrice(), $cloneProductPrice->getPrice(), 'Price must be equal');
     $this->assertEquals($originalProductPrice->getPromoPrice(), $cloneProductPrice->getPromoPrice(), 'Promo price must be equal');
     $this->assertEquals(0, $cloneProductPrice->getFromDefaultCurrency(), 'From default currency must be equal to 0');
     return ['event' => $event, 'cloneProductId' => $event->getClonedProduct()->getId(), 'clonePSEId' => $clonePSE->getId(), 'originalPSE' => $originalPSE];
 }