Merge branch 'master' into tax
This commit is contained in:
@@ -8,7 +8,9 @@ use Propel\Runtime\Propel;
|
||||
use Thelia\Core\Event\Country\CountryEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Base\Country as BaseCountry;
|
||||
|
||||
use Thelia\Model\Map\CountryTableMap;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class Country extends BaseCountry
|
||||
{
|
||||
@@ -79,4 +81,31 @@ class Country extends BaseCountry
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETECOUNTRY, new CountryEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default country
|
||||
*
|
||||
* @throws LogicException if no default country is defined
|
||||
*/
|
||||
public static function getDefaultCountry() {
|
||||
$dc = CountryQuery::create()->findOneByByDefault(true);
|
||||
|
||||
if ($dc == null)
|
||||
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
|
||||
|
||||
return $dc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shop country
|
||||
*
|
||||
* @throws LogicException if no shop country is defined
|
||||
*/
|
||||
public static function getShopLocation() {
|
||||
$dc = CountryQuery::create()->findOneByShopCountry(true);
|
||||
|
||||
if ($dc == null)
|
||||
throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
|
||||
|
||||
return $dc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Thelia\Core\Event\Product\ProductEvent;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
|
||||
class Product extends BaseProduct
|
||||
{
|
||||
@@ -47,6 +48,20 @@ class Product extends BaseProduct
|
||||
return $taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default PSE for this product.
|
||||
*/
|
||||
public function getDefaultSaleElements() {
|
||||
return ProductSaleElementsQuery::create()->filterByProductId($this->id)->filterByIsDefault(true)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PSE count fir this product.
|
||||
*/
|
||||
public function countSaleElements() {
|
||||
return ProductSaleElementsQuery::create()->filterByProductId($this->id)->filterByIsDefault(true)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current default category ID for this product
|
||||
*/
|
||||
@@ -100,7 +115,7 @@ class Product extends BaseProduct
|
||||
;
|
||||
|
||||
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
|
||||
exit;
|
||||
|
||||
// Delete the old default category
|
||||
if ($productCategory !== null) $productCategory->delete();
|
||||
|
||||
@@ -131,10 +146,10 @@ class Product extends BaseProduct
|
||||
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
|
||||
|
||||
$con->beginTransaction();
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
|
||||
|
||||
try {
|
||||
|
||||
// Create the product
|
||||
$this->save($con);
|
||||
|
||||
@@ -146,29 +161,8 @@ class Product extends BaseProduct
|
||||
|
||||
$this->setTaxRuleId($taxRuleId);
|
||||
|
||||
// Create an empty product sale element
|
||||
$sale_elements = new ProductSaleElements();
|
||||
|
||||
$sale_elements
|
||||
->setProduct($this)
|
||||
->setRef($this->getRef())
|
||||
->setPromo(0)
|
||||
->setNewness(0)
|
||||
->setWeight($baseWeight)
|
||||
->setIsDefault(true)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
// Create an empty product price in the default currency
|
||||
$product_price = new ProductPrice();
|
||||
|
||||
$product_price
|
||||
->setProductSaleElements($sale_elements)
|
||||
->setPromoPrice($basePrice)
|
||||
->setPrice($basePrice)
|
||||
->setCurrencyId($priceCurrencyId)
|
||||
->save($con)
|
||||
;
|
||||
// Create the default product sale element of this product
|
||||
$sale_elements = $this->createDefaultProductSaleElement($con, $baseWeight, $basePrice, $priceCurrencyId, true);
|
||||
|
||||
// Store all the stuff !
|
||||
$con->commit();
|
||||
@@ -183,6 +177,38 @@ class Product extends BaseProduct
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a basic product sale element attached to this product.
|
||||
*/
|
||||
public function createDefaultProductSaleElement(ConnectionInterface $con, $weight, $basePrice, $currencyId, $isDefault) {
|
||||
|
||||
// Create an empty product sale element
|
||||
$sale_elements = new ProductSaleElements();
|
||||
|
||||
$sale_elements
|
||||
->setProduct($this)
|
||||
->setRef($this->getRef())
|
||||
->setPromo(0)
|
||||
->setNewness(0)
|
||||
->setWeight($weight)
|
||||
->setIsDefault($isDefault)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
// Create an empty product price in the default currency
|
||||
$product_price = new ProductPrice();
|
||||
|
||||
$product_price
|
||||
->setProductSaleElements($sale_elements)
|
||||
->setPromoPrice($basePrice)
|
||||
->setPrice($basePrice)
|
||||
->setCurrencyId($currencyId)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
return $sale_elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our default category
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Profile as BaseProfile;
|
||||
@@ -8,4 +7,4 @@ use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
class Profile extends BaseProfile
|
||||
{
|
||||
use ModelEventDispatcherTrait;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user