From 38e4b6a09de4e048548cdcec85901a1c61f5d896 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 23 Jul 2013 16:01:00 +0200 Subject: [PATCH] cart is persist now --- core/lib/Thelia/Model/Base/Address.php | 718 +++++- core/lib/Thelia/Model/Base/AddressQuery.php | 188 +- core/lib/Thelia/Model/Base/Cart.php | 2165 +++++++++++++++++ core/lib/Thelia/Model/Base/CartItem.php | 1707 +++++++++++++ core/lib/Thelia/Model/Base/CartItemQuery.php | 930 +++++++ core/lib/Thelia/Model/Base/CartQuery.php | 1121 +++++++++ core/lib/Thelia/Model/Base/Combination.php | 323 +++ .../Thelia/Model/Base/CombinationQuery.php | 77 + core/lib/Thelia/Model/Base/Currency.php | 348 +++ core/lib/Thelia/Model/Base/CurrencyQuery.php | 77 + core/lib/Thelia/Model/Base/Customer.php | 348 +++ core/lib/Thelia/Model/Base/CustomerQuery.php | 81 +- core/lib/Thelia/Model/Base/CustomerTitle.php | 9 +- .../Thelia/Model/Base/CustomerTitleQuery.php | 4 +- core/lib/Thelia/Model/Base/Product.php | 322 +++ core/lib/Thelia/Model/Base/ProductQuery.php | 77 + core/lib/Thelia/Model/Base/Stock.php | 48 +- core/lib/Thelia/Model/Base/StockQuery.php | 34 +- core/lib/Thelia/Model/Cart.php | 10 + core/lib/Thelia/Model/CartItem.php | 10 + core/lib/Thelia/Model/CartItemQuery.php | 21 + core/lib/Thelia/Model/CartQuery.php | 21 + core/lib/Thelia/Model/Map/AddressTableMap.php | 32 +- .../lib/Thelia/Model/Map/CartItemTableMap.php | 465 ++++ core/lib/Thelia/Model/Map/CartTableMap.php | 475 ++++ .../Thelia/Model/Map/CombinationTableMap.php | 1 + .../lib/Thelia/Model/Map/CurrencyTableMap.php | 1 + .../lib/Thelia/Model/Map/CustomerTableMap.php | 3 +- core/lib/Thelia/Model/Map/ProductTableMap.php | 1 + core/lib/Thelia/Model/Map/StockTableMap.php | 30 +- install/thelia.sql | 68 +- local/config/schema.xml | 64 +- 32 files changed, 9653 insertions(+), 126 deletions(-) create mode 100644 core/lib/Thelia/Model/Base/Cart.php create mode 100644 core/lib/Thelia/Model/Base/CartItem.php create mode 100644 core/lib/Thelia/Model/Base/CartItemQuery.php create mode 100644 core/lib/Thelia/Model/Base/CartQuery.php create mode 100644 core/lib/Thelia/Model/Cart.php create mode 100644 core/lib/Thelia/Model/CartItem.php create mode 100644 core/lib/Thelia/Model/CartItemQuery.php create mode 100644 core/lib/Thelia/Model/CartQuery.php create mode 100644 core/lib/Thelia/Model/Map/CartItemTableMap.php create mode 100644 core/lib/Thelia/Model/Map/CartTableMap.php diff --git a/core/lib/Thelia/Model/Base/Address.php b/core/lib/Thelia/Model/Base/Address.php index e0864f269..4605db484 100755 --- a/core/lib/Thelia/Model/Base/Address.php +++ b/core/lib/Thelia/Model/Base/Address.php @@ -10,6 +10,7 @@ use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\ActiveRecord\ActiveRecordInterface; use Propel\Runtime\Collection\Collection; +use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\BadMethodCallException; use Propel\Runtime\Exception\PropelException; @@ -18,6 +19,8 @@ use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\Address as ChildAddress; use Thelia\Model\AddressQuery as ChildAddressQuery; +use Thelia\Model\Cart as ChildCart; +use Thelia\Model\CartQuery as ChildCartQuery; use Thelia\Model\Customer as ChildCustomer; use Thelia\Model\CustomerQuery as ChildCustomerQuery; use Thelia\Model\CustomerTitle as ChildCustomerTitle; @@ -149,11 +152,11 @@ abstract class Address implements ActiveRecordInterface protected $cellphone; /** - * The value for the is_default field. + * The value for the default field. * Note: this column has a database default value of: 0 * @var int */ - protected $is_default; + protected $default; /** * The value for the created_at field. @@ -177,6 +180,18 @@ abstract class Address implements ActiveRecordInterface */ protected $aCustomerTitle; + /** + * @var ObjectCollection|ChildCart[] Collection to store aggregation of ChildCart objects. + */ + protected $collCartsRelatedByAddressDeliveryId; + protected $collCartsRelatedByAddressDeliveryIdPartial; + + /** + * @var ObjectCollection|ChildCart[] Collection to store aggregation of ChildCart objects. + */ + protected $collCartsRelatedByAddressInvoiceId; + protected $collCartsRelatedByAddressInvoiceIdPartial; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -185,6 +200,18 @@ abstract class Address implements ActiveRecordInterface */ protected $alreadyInSave = false; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartsRelatedByAddressDeliveryIdScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartsRelatedByAddressInvoiceIdScheduledForDeletion = null; + /** * Applies default values to this object. * This method should be called from the object's constructor (or @@ -193,7 +220,7 @@ abstract class Address implements ActiveRecordInterface */ public function applyDefaultValues() { - $this->is_default = 0; + $this->default = 0; } /** @@ -618,14 +645,14 @@ abstract class Address implements ActiveRecordInterface } /** - * Get the [is_default] column value. + * Get the [default] column value. * * @return int */ - public function getIsDefault() + public function getDefault() { - return $this->is_default; + return $this->default; } /** @@ -992,25 +1019,25 @@ abstract class Address implements ActiveRecordInterface } // setCellphone() /** - * Set the value of [is_default] column. + * Set the value of [default] column. * * @param int $v new value * @return \Thelia\Model\Address The current object (for fluent API support) */ - public function setIsDefault($v) + public function setDefault($v) { if ($v !== null) { $v = (int) $v; } - if ($this->is_default !== $v) { - $this->is_default = $v; - $this->modifiedColumns[] = AddressTableMap::IS_DEFAULT; + if ($this->default !== $v) { + $this->default = $v; + $this->modifiedColumns[] = AddressTableMap::DEFAULT; } return $this; - } // setIsDefault() + } // setDefault() /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. @@ -1064,7 +1091,7 @@ abstract class Address implements ActiveRecordInterface */ public function hasOnlyDefaultValues() { - if ($this->is_default !== 0) { + if ($this->default !== 0) { return false; } @@ -1140,8 +1167,8 @@ abstract class Address implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : AddressTableMap::translateFieldName('Cellphone', TableMap::TYPE_PHPNAME, $indexType)]; $this->cellphone = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : AddressTableMap::translateFieldName('IsDefault', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_default = (null !== $col) ? (int) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : AddressTableMap::translateFieldName('Default', TableMap::TYPE_PHPNAME, $indexType)]; + $this->default = (null !== $col) ? (int) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 16 + $startcol : AddressTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { @@ -1231,6 +1258,10 @@ abstract class Address implements ActiveRecordInterface $this->aCustomer = null; $this->aCustomerTitle = null; + $this->collCartsRelatedByAddressDeliveryId = null; + + $this->collCartsRelatedByAddressInvoiceId = null; + } // if (deep) } @@ -1383,6 +1414,42 @@ abstract class Address implements ActiveRecordInterface $this->resetModified(); } + if ($this->cartsRelatedByAddressDeliveryIdScheduledForDeletion !== null) { + if (!$this->cartsRelatedByAddressDeliveryIdScheduledForDeletion->isEmpty()) { + foreach ($this->cartsRelatedByAddressDeliveryIdScheduledForDeletion as $cartRelatedByAddressDeliveryId) { + // need to save related object because we set the relation to null + $cartRelatedByAddressDeliveryId->save($con); + } + $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion = null; + } + } + + if ($this->collCartsRelatedByAddressDeliveryId !== null) { + foreach ($this->collCartsRelatedByAddressDeliveryId as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->cartsRelatedByAddressInvoiceIdScheduledForDeletion !== null) { + if (!$this->cartsRelatedByAddressInvoiceIdScheduledForDeletion->isEmpty()) { + foreach ($this->cartsRelatedByAddressInvoiceIdScheduledForDeletion as $cartRelatedByAddressInvoiceId) { + // need to save related object because we set the relation to null + $cartRelatedByAddressInvoiceId->save($con); + } + $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion = null; + } + } + + if ($this->collCartsRelatedByAddressInvoiceId !== null) { + foreach ($this->collCartsRelatedByAddressInvoiceId as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + $this->alreadyInSave = false; } @@ -1454,8 +1521,8 @@ abstract class Address implements ActiveRecordInterface if ($this->isColumnModified(AddressTableMap::CELLPHONE)) { $modifiedColumns[':p' . $index++] = 'CELLPHONE'; } - if ($this->isColumnModified(AddressTableMap::IS_DEFAULT)) { - $modifiedColumns[':p' . $index++] = 'IS_DEFAULT'; + if ($this->isColumnModified(AddressTableMap::DEFAULT)) { + $modifiedColumns[':p' . $index++] = 'DEFAULT'; } if ($this->isColumnModified(AddressTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; @@ -1519,8 +1586,8 @@ abstract class Address implements ActiveRecordInterface case 'CELLPHONE': $stmt->bindValue($identifier, $this->cellphone, PDO::PARAM_STR); break; - case 'IS_DEFAULT': - $stmt->bindValue($identifier, $this->is_default, PDO::PARAM_INT); + case 'DEFAULT': + $stmt->bindValue($identifier, $this->default, PDO::PARAM_INT); break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); @@ -1636,7 +1703,7 @@ abstract class Address implements ActiveRecordInterface return $this->getCellphone(); break; case 15: - return $this->getIsDefault(); + return $this->getDefault(); break; case 16: return $this->getCreatedAt(); @@ -1688,7 +1755,7 @@ abstract class Address implements ActiveRecordInterface $keys[12] => $this->getCountryId(), $keys[13] => $this->getPhone(), $keys[14] => $this->getCellphone(), - $keys[15] => $this->getIsDefault(), + $keys[15] => $this->getDefault(), $keys[16] => $this->getCreatedAt(), $keys[17] => $this->getUpdatedAt(), ); @@ -1705,6 +1772,12 @@ abstract class Address implements ActiveRecordInterface if (null !== $this->aCustomerTitle) { $result['CustomerTitle'] = $this->aCustomerTitle->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } + if (null !== $this->collCartsRelatedByAddressDeliveryId) { + $result['CartsRelatedByAddressDeliveryId'] = $this->collCartsRelatedByAddressDeliveryId->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collCartsRelatedByAddressInvoiceId) { + $result['CartsRelatedByAddressInvoiceId'] = $this->collCartsRelatedByAddressInvoiceId->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } } return $result; @@ -1785,7 +1858,7 @@ abstract class Address implements ActiveRecordInterface $this->setCellphone($value); break; case 15: - $this->setIsDefault($value); + $this->setDefault($value); break; case 16: $this->setCreatedAt($value); @@ -1832,7 +1905,7 @@ abstract class Address implements ActiveRecordInterface if (array_key_exists($keys[12], $arr)) $this->setCountryId($arr[$keys[12]]); if (array_key_exists($keys[13], $arr)) $this->setPhone($arr[$keys[13]]); if (array_key_exists($keys[14], $arr)) $this->setCellphone($arr[$keys[14]]); - if (array_key_exists($keys[15], $arr)) $this->setIsDefault($arr[$keys[15]]); + if (array_key_exists($keys[15], $arr)) $this->setDefault($arr[$keys[15]]); if (array_key_exists($keys[16], $arr)) $this->setCreatedAt($arr[$keys[16]]); if (array_key_exists($keys[17], $arr)) $this->setUpdatedAt($arr[$keys[17]]); } @@ -1861,7 +1934,7 @@ abstract class Address implements ActiveRecordInterface if ($this->isColumnModified(AddressTableMap::COUNTRY_ID)) $criteria->add(AddressTableMap::COUNTRY_ID, $this->country_id); if ($this->isColumnModified(AddressTableMap::PHONE)) $criteria->add(AddressTableMap::PHONE, $this->phone); if ($this->isColumnModified(AddressTableMap::CELLPHONE)) $criteria->add(AddressTableMap::CELLPHONE, $this->cellphone); - if ($this->isColumnModified(AddressTableMap::IS_DEFAULT)) $criteria->add(AddressTableMap::IS_DEFAULT, $this->is_default); + if ($this->isColumnModified(AddressTableMap::DEFAULT)) $criteria->add(AddressTableMap::DEFAULT, $this->default); if ($this->isColumnModified(AddressTableMap::CREATED_AT)) $criteria->add(AddressTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AddressTableMap::UPDATED_AT)) $criteria->add(AddressTableMap::UPDATED_AT, $this->updated_at); @@ -1941,9 +2014,29 @@ abstract class Address implements ActiveRecordInterface $copyObj->setCountryId($this->getCountryId()); $copyObj->setPhone($this->getPhone()); $copyObj->setCellphone($this->getCellphone()); - $copyObj->setIsDefault($this->getIsDefault()); + $copyObj->setDefault($this->getDefault()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getCartsRelatedByAddressDeliveryId() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCartRelatedByAddressDeliveryId($relObj->copy($deepCopy)); + } + } + + foreach ($this->getCartsRelatedByAddressInvoiceId() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCartRelatedByAddressInvoiceId($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + if ($makeNew) { $copyObj->setNew(true); $copyObj->setId(NULL); // this is a auto-increment column, so set to default value @@ -2074,6 +2167,561 @@ abstract class Address implements ActiveRecordInterface return $this->aCustomerTitle; } + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('CartRelatedByAddressDeliveryId' == $relationName) { + return $this->initCartsRelatedByAddressDeliveryId(); + } + if ('CartRelatedByAddressInvoiceId' == $relationName) { + return $this->initCartsRelatedByAddressInvoiceId(); + } + } + + /** + * Clears out the collCartsRelatedByAddressDeliveryId collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCartsRelatedByAddressDeliveryId() + */ + public function clearCartsRelatedByAddressDeliveryId() + { + $this->collCartsRelatedByAddressDeliveryId = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCartsRelatedByAddressDeliveryId collection loaded partially. + */ + public function resetPartialCartsRelatedByAddressDeliveryId($v = true) + { + $this->collCartsRelatedByAddressDeliveryIdPartial = $v; + } + + /** + * Initializes the collCartsRelatedByAddressDeliveryId collection. + * + * By default this just sets the collCartsRelatedByAddressDeliveryId collection to an empty array (like clearcollCartsRelatedByAddressDeliveryId()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCartsRelatedByAddressDeliveryId($overrideExisting = true) + { + if (null !== $this->collCartsRelatedByAddressDeliveryId && !$overrideExisting) { + return; + } + $this->collCartsRelatedByAddressDeliveryId = new ObjectCollection(); + $this->collCartsRelatedByAddressDeliveryId->setModel('\Thelia\Model\Cart'); + } + + /** + * Gets an array of ChildCart objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildAddress is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCart[] List of ChildCart objects + * @throws PropelException + */ + public function getCartsRelatedByAddressDeliveryId($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartsRelatedByAddressDeliveryIdPartial && !$this->isNew(); + if (null === $this->collCartsRelatedByAddressDeliveryId || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartsRelatedByAddressDeliveryId) { + // return empty collection + $this->initCartsRelatedByAddressDeliveryId(); + } else { + $collCartsRelatedByAddressDeliveryId = ChildCartQuery::create(null, $criteria) + ->filterByAddressRelatedByAddressDeliveryId($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartsRelatedByAddressDeliveryIdPartial && count($collCartsRelatedByAddressDeliveryId)) { + $this->initCartsRelatedByAddressDeliveryId(false); + + foreach ($collCartsRelatedByAddressDeliveryId as $obj) { + if (false == $this->collCartsRelatedByAddressDeliveryId->contains($obj)) { + $this->collCartsRelatedByAddressDeliveryId->append($obj); + } + } + + $this->collCartsRelatedByAddressDeliveryIdPartial = true; + } + + $collCartsRelatedByAddressDeliveryId->getInternalIterator()->rewind(); + + return $collCartsRelatedByAddressDeliveryId; + } + + if ($partial && $this->collCartsRelatedByAddressDeliveryId) { + foreach ($this->collCartsRelatedByAddressDeliveryId as $obj) { + if ($obj->isNew()) { + $collCartsRelatedByAddressDeliveryId[] = $obj; + } + } + } + + $this->collCartsRelatedByAddressDeliveryId = $collCartsRelatedByAddressDeliveryId; + $this->collCartsRelatedByAddressDeliveryIdPartial = false; + } + } + + return $this->collCartsRelatedByAddressDeliveryId; + } + + /** + * Sets a collection of CartRelatedByAddressDeliveryId objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $cartsRelatedByAddressDeliveryId A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildAddress The current object (for fluent API support) + */ + public function setCartsRelatedByAddressDeliveryId(Collection $cartsRelatedByAddressDeliveryId, ConnectionInterface $con = null) + { + $cartsRelatedByAddressDeliveryIdToDelete = $this->getCartsRelatedByAddressDeliveryId(new Criteria(), $con)->diff($cartsRelatedByAddressDeliveryId); + + + $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion = $cartsRelatedByAddressDeliveryIdToDelete; + + foreach ($cartsRelatedByAddressDeliveryIdToDelete as $cartRelatedByAddressDeliveryIdRemoved) { + $cartRelatedByAddressDeliveryIdRemoved->setAddressRelatedByAddressDeliveryId(null); + } + + $this->collCartsRelatedByAddressDeliveryId = null; + foreach ($cartsRelatedByAddressDeliveryId as $cartRelatedByAddressDeliveryId) { + $this->addCartRelatedByAddressDeliveryId($cartRelatedByAddressDeliveryId); + } + + $this->collCartsRelatedByAddressDeliveryId = $cartsRelatedByAddressDeliveryId; + $this->collCartsRelatedByAddressDeliveryIdPartial = false; + + return $this; + } + + /** + * Returns the number of related Cart objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Cart objects. + * @throws PropelException + */ + public function countCartsRelatedByAddressDeliveryId(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartsRelatedByAddressDeliveryIdPartial && !$this->isNew(); + if (null === $this->collCartsRelatedByAddressDeliveryId || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartsRelatedByAddressDeliveryId) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCartsRelatedByAddressDeliveryId()); + } + + $query = ChildCartQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByAddressRelatedByAddressDeliveryId($this) + ->count($con); + } + + return count($this->collCartsRelatedByAddressDeliveryId); + } + + /** + * Method called to associate a ChildCart object to this object + * through the ChildCart foreign key attribute. + * + * @param ChildCart $l ChildCart + * @return \Thelia\Model\Address The current object (for fluent API support) + */ + public function addCartRelatedByAddressDeliveryId(ChildCart $l) + { + if ($this->collCartsRelatedByAddressDeliveryId === null) { + $this->initCartsRelatedByAddressDeliveryId(); + $this->collCartsRelatedByAddressDeliveryIdPartial = true; + } + + if (!in_array($l, $this->collCartsRelatedByAddressDeliveryId->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCartRelatedByAddressDeliveryId($l); + } + + return $this; + } + + /** + * @param CartRelatedByAddressDeliveryId $cartRelatedByAddressDeliveryId The cartRelatedByAddressDeliveryId object to add. + */ + protected function doAddCartRelatedByAddressDeliveryId($cartRelatedByAddressDeliveryId) + { + $this->collCartsRelatedByAddressDeliveryId[]= $cartRelatedByAddressDeliveryId; + $cartRelatedByAddressDeliveryId->setAddressRelatedByAddressDeliveryId($this); + } + + /** + * @param CartRelatedByAddressDeliveryId $cartRelatedByAddressDeliveryId The cartRelatedByAddressDeliveryId object to remove. + * @return ChildAddress The current object (for fluent API support) + */ + public function removeCartRelatedByAddressDeliveryId($cartRelatedByAddressDeliveryId) + { + if ($this->getCartsRelatedByAddressDeliveryId()->contains($cartRelatedByAddressDeliveryId)) { + $this->collCartsRelatedByAddressDeliveryId->remove($this->collCartsRelatedByAddressDeliveryId->search($cartRelatedByAddressDeliveryId)); + if (null === $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion) { + $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion = clone $this->collCartsRelatedByAddressDeliveryId; + $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion->clear(); + } + $this->cartsRelatedByAddressDeliveryIdScheduledForDeletion[]= $cartRelatedByAddressDeliveryId; + $cartRelatedByAddressDeliveryId->setAddressRelatedByAddressDeliveryId(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Address is new, it will return + * an empty collection; or if this Address has previously + * been saved, it will retrieve related CartsRelatedByAddressDeliveryId 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 Address. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsRelatedByAddressDeliveryIdJoinCustomer($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Customer', $joinBehavior); + + return $this->getCartsRelatedByAddressDeliveryId($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Address is new, it will return + * an empty collection; or if this Address has previously + * been saved, it will retrieve related CartsRelatedByAddressDeliveryId 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 Address. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsRelatedByAddressDeliveryIdJoinCurrency($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Currency', $joinBehavior); + + return $this->getCartsRelatedByAddressDeliveryId($query, $con); + } + + /** + * Clears out the collCartsRelatedByAddressInvoiceId collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCartsRelatedByAddressInvoiceId() + */ + public function clearCartsRelatedByAddressInvoiceId() + { + $this->collCartsRelatedByAddressInvoiceId = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCartsRelatedByAddressInvoiceId collection loaded partially. + */ + public function resetPartialCartsRelatedByAddressInvoiceId($v = true) + { + $this->collCartsRelatedByAddressInvoiceIdPartial = $v; + } + + /** + * Initializes the collCartsRelatedByAddressInvoiceId collection. + * + * By default this just sets the collCartsRelatedByAddressInvoiceId collection to an empty array (like clearcollCartsRelatedByAddressInvoiceId()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCartsRelatedByAddressInvoiceId($overrideExisting = true) + { + if (null !== $this->collCartsRelatedByAddressInvoiceId && !$overrideExisting) { + return; + } + $this->collCartsRelatedByAddressInvoiceId = new ObjectCollection(); + $this->collCartsRelatedByAddressInvoiceId->setModel('\Thelia\Model\Cart'); + } + + /** + * Gets an array of ChildCart objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildAddress is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCart[] List of ChildCart objects + * @throws PropelException + */ + public function getCartsRelatedByAddressInvoiceId($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartsRelatedByAddressInvoiceIdPartial && !$this->isNew(); + if (null === $this->collCartsRelatedByAddressInvoiceId || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartsRelatedByAddressInvoiceId) { + // return empty collection + $this->initCartsRelatedByAddressInvoiceId(); + } else { + $collCartsRelatedByAddressInvoiceId = ChildCartQuery::create(null, $criteria) + ->filterByAddressRelatedByAddressInvoiceId($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartsRelatedByAddressInvoiceIdPartial && count($collCartsRelatedByAddressInvoiceId)) { + $this->initCartsRelatedByAddressInvoiceId(false); + + foreach ($collCartsRelatedByAddressInvoiceId as $obj) { + if (false == $this->collCartsRelatedByAddressInvoiceId->contains($obj)) { + $this->collCartsRelatedByAddressInvoiceId->append($obj); + } + } + + $this->collCartsRelatedByAddressInvoiceIdPartial = true; + } + + $collCartsRelatedByAddressInvoiceId->getInternalIterator()->rewind(); + + return $collCartsRelatedByAddressInvoiceId; + } + + if ($partial && $this->collCartsRelatedByAddressInvoiceId) { + foreach ($this->collCartsRelatedByAddressInvoiceId as $obj) { + if ($obj->isNew()) { + $collCartsRelatedByAddressInvoiceId[] = $obj; + } + } + } + + $this->collCartsRelatedByAddressInvoiceId = $collCartsRelatedByAddressInvoiceId; + $this->collCartsRelatedByAddressInvoiceIdPartial = false; + } + } + + return $this->collCartsRelatedByAddressInvoiceId; + } + + /** + * Sets a collection of CartRelatedByAddressInvoiceId objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $cartsRelatedByAddressInvoiceId A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildAddress The current object (for fluent API support) + */ + public function setCartsRelatedByAddressInvoiceId(Collection $cartsRelatedByAddressInvoiceId, ConnectionInterface $con = null) + { + $cartsRelatedByAddressInvoiceIdToDelete = $this->getCartsRelatedByAddressInvoiceId(new Criteria(), $con)->diff($cartsRelatedByAddressInvoiceId); + + + $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion = $cartsRelatedByAddressInvoiceIdToDelete; + + foreach ($cartsRelatedByAddressInvoiceIdToDelete as $cartRelatedByAddressInvoiceIdRemoved) { + $cartRelatedByAddressInvoiceIdRemoved->setAddressRelatedByAddressInvoiceId(null); + } + + $this->collCartsRelatedByAddressInvoiceId = null; + foreach ($cartsRelatedByAddressInvoiceId as $cartRelatedByAddressInvoiceId) { + $this->addCartRelatedByAddressInvoiceId($cartRelatedByAddressInvoiceId); + } + + $this->collCartsRelatedByAddressInvoiceId = $cartsRelatedByAddressInvoiceId; + $this->collCartsRelatedByAddressInvoiceIdPartial = false; + + return $this; + } + + /** + * Returns the number of related Cart objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Cart objects. + * @throws PropelException + */ + public function countCartsRelatedByAddressInvoiceId(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartsRelatedByAddressInvoiceIdPartial && !$this->isNew(); + if (null === $this->collCartsRelatedByAddressInvoiceId || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartsRelatedByAddressInvoiceId) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCartsRelatedByAddressInvoiceId()); + } + + $query = ChildCartQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByAddressRelatedByAddressInvoiceId($this) + ->count($con); + } + + return count($this->collCartsRelatedByAddressInvoiceId); + } + + /** + * Method called to associate a ChildCart object to this object + * through the ChildCart foreign key attribute. + * + * @param ChildCart $l ChildCart + * @return \Thelia\Model\Address The current object (for fluent API support) + */ + public function addCartRelatedByAddressInvoiceId(ChildCart $l) + { + if ($this->collCartsRelatedByAddressInvoiceId === null) { + $this->initCartsRelatedByAddressInvoiceId(); + $this->collCartsRelatedByAddressInvoiceIdPartial = true; + } + + if (!in_array($l, $this->collCartsRelatedByAddressInvoiceId->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCartRelatedByAddressInvoiceId($l); + } + + return $this; + } + + /** + * @param CartRelatedByAddressInvoiceId $cartRelatedByAddressInvoiceId The cartRelatedByAddressInvoiceId object to add. + */ + protected function doAddCartRelatedByAddressInvoiceId($cartRelatedByAddressInvoiceId) + { + $this->collCartsRelatedByAddressInvoiceId[]= $cartRelatedByAddressInvoiceId; + $cartRelatedByAddressInvoiceId->setAddressRelatedByAddressInvoiceId($this); + } + + /** + * @param CartRelatedByAddressInvoiceId $cartRelatedByAddressInvoiceId The cartRelatedByAddressInvoiceId object to remove. + * @return ChildAddress The current object (for fluent API support) + */ + public function removeCartRelatedByAddressInvoiceId($cartRelatedByAddressInvoiceId) + { + if ($this->getCartsRelatedByAddressInvoiceId()->contains($cartRelatedByAddressInvoiceId)) { + $this->collCartsRelatedByAddressInvoiceId->remove($this->collCartsRelatedByAddressInvoiceId->search($cartRelatedByAddressInvoiceId)); + if (null === $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion) { + $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion = clone $this->collCartsRelatedByAddressInvoiceId; + $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion->clear(); + } + $this->cartsRelatedByAddressInvoiceIdScheduledForDeletion[]= $cartRelatedByAddressInvoiceId; + $cartRelatedByAddressInvoiceId->setAddressRelatedByAddressInvoiceId(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Address is new, it will return + * an empty collection; or if this Address has previously + * been saved, it will retrieve related CartsRelatedByAddressInvoiceId 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 Address. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsRelatedByAddressInvoiceIdJoinCustomer($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Customer', $joinBehavior); + + return $this->getCartsRelatedByAddressInvoiceId($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Address is new, it will return + * an empty collection; or if this Address has previously + * been saved, it will retrieve related CartsRelatedByAddressInvoiceId 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 Address. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsRelatedByAddressInvoiceIdJoinCurrency($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Currency', $joinBehavior); + + return $this->getCartsRelatedByAddressInvoiceId($query, $con); + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2094,7 +2742,7 @@ abstract class Address implements ActiveRecordInterface $this->country_id = null; $this->phone = null; $this->cellphone = null; - $this->is_default = null; + $this->default = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; @@ -2117,8 +2765,26 @@ abstract class Address implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { + if ($this->collCartsRelatedByAddressDeliveryId) { + foreach ($this->collCartsRelatedByAddressDeliveryId as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collCartsRelatedByAddressInvoiceId) { + foreach ($this->collCartsRelatedByAddressInvoiceId as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) + if ($this->collCartsRelatedByAddressDeliveryId instanceof Collection) { + $this->collCartsRelatedByAddressDeliveryId->clearIterator(); + } + $this->collCartsRelatedByAddressDeliveryId = null; + if ($this->collCartsRelatedByAddressInvoiceId instanceof Collection) { + $this->collCartsRelatedByAddressInvoiceId->clearIterator(); + } + $this->collCartsRelatedByAddressInvoiceId = null; $this->aCustomer = null; $this->aCustomerTitle = null; } diff --git a/core/lib/Thelia/Model/Base/AddressQuery.php b/core/lib/Thelia/Model/Base/AddressQuery.php index f9dc30efc..919578730 100755 --- a/core/lib/Thelia/Model/Base/AddressQuery.php +++ b/core/lib/Thelia/Model/Base/AddressQuery.php @@ -36,7 +36,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddressQuery orderByCountryId($order = Criteria::ASC) Order by the country_id column * @method ChildAddressQuery orderByPhone($order = Criteria::ASC) Order by the phone column * @method ChildAddressQuery orderByCellphone($order = Criteria::ASC) Order by the cellphone column - * @method ChildAddressQuery orderByIsDefault($order = Criteria::ASC) Order by the is_default column + * @method ChildAddressQuery orderByDefault($order = Criteria::ASC) Order by the default column * @method ChildAddressQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAddressQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -55,7 +55,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddressQuery groupByCountryId() Group by the country_id column * @method ChildAddressQuery groupByPhone() Group by the phone column * @method ChildAddressQuery groupByCellphone() Group by the cellphone column - * @method ChildAddressQuery groupByIsDefault() Group by the is_default column + * @method ChildAddressQuery groupByDefault() Group by the default column * @method ChildAddressQuery groupByCreatedAt() Group by the created_at column * @method ChildAddressQuery groupByUpdatedAt() Group by the updated_at column * @@ -71,6 +71,14 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddressQuery rightJoinCustomerTitle($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CustomerTitle relation * @method ChildAddressQuery innerJoinCustomerTitle($relationAlias = null) Adds a INNER JOIN clause to the query using the CustomerTitle relation * + * @method ChildAddressQuery leftJoinCartRelatedByAddressDeliveryId($relationAlias = null) Adds a LEFT JOIN clause to the query using the CartRelatedByAddressDeliveryId relation + * @method ChildAddressQuery rightJoinCartRelatedByAddressDeliveryId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CartRelatedByAddressDeliveryId relation + * @method ChildAddressQuery innerJoinCartRelatedByAddressDeliveryId($relationAlias = null) Adds a INNER JOIN clause to the query using the CartRelatedByAddressDeliveryId relation + * + * @method ChildAddressQuery leftJoinCartRelatedByAddressInvoiceId($relationAlias = null) Adds a LEFT JOIN clause to the query using the CartRelatedByAddressInvoiceId relation + * @method ChildAddressQuery rightJoinCartRelatedByAddressInvoiceId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CartRelatedByAddressInvoiceId relation + * @method ChildAddressQuery innerJoinCartRelatedByAddressInvoiceId($relationAlias = null) Adds a INNER JOIN clause to the query using the CartRelatedByAddressInvoiceId relation + * * @method ChildAddress findOne(ConnectionInterface $con = null) Return the first ChildAddress matching the query * @method ChildAddress findOneOrCreate(ConnectionInterface $con = null) Return the first ChildAddress matching the query, or a new ChildAddress object populated from the query conditions when no match is found * @@ -89,7 +97,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddress findOneByCountryId(int $country_id) Return the first ChildAddress filtered by the country_id column * @method ChildAddress findOneByPhone(string $phone) Return the first ChildAddress filtered by the phone column * @method ChildAddress findOneByCellphone(string $cellphone) Return the first ChildAddress filtered by the cellphone column - * @method ChildAddress findOneByIsDefault(int $is_default) Return the first ChildAddress filtered by the is_default column + * @method ChildAddress findOneByDefault(int $default) Return the first ChildAddress filtered by the default column * @method ChildAddress findOneByCreatedAt(string $created_at) Return the first ChildAddress filtered by the created_at column * @method ChildAddress findOneByUpdatedAt(string $updated_at) Return the first ChildAddress filtered by the updated_at column * @@ -108,7 +116,7 @@ use Thelia\Model\Map\AddressTableMap; * @method array findByCountryId(int $country_id) Return ChildAddress objects filtered by the country_id column * @method array findByPhone(string $phone) Return ChildAddress objects filtered by the phone column * @method array findByCellphone(string $cellphone) Return ChildAddress objects filtered by the cellphone column - * @method array findByIsDefault(int $is_default) Return ChildAddress objects filtered by the is_default column + * @method array findByDefault(int $default) Return ChildAddress objects filtered by the default column * @method array findByCreatedAt(string $created_at) Return ChildAddress objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAddress objects filtered by the updated_at column * @@ -199,7 +207,7 @@ abstract class AddressQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, TITLE, CUSTOMER_ID, CUSTOMER_TITLE_ID, COMPANY, FIRSTNAME, LASTNAME, ADDRESS1, ADDRESS2, ADDRESS3, ZIPCODE, CITY, COUNTRY_ID, PHONE, CELLPHONE, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM address WHERE ID = :p0'; + $sql = 'SELECT ID, TITLE, CUSTOMER_ID, CUSTOMER_TITLE_ID, COMPANY, FIRSTNAME, LASTNAME, ADDRESS1, ADDRESS2, ADDRESS3, ZIPCODE, CITY, COUNTRY_ID, PHONE, CELLPHONE, DEFAULT, CREATED_AT, UPDATED_AT FROM address WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -776,16 +784,16 @@ abstract class AddressQuery extends ModelCriteria } /** - * Filter the query on the is_default column + * Filter the query on the default column * * Example usage: * - * $query->filterByIsDefault(1234); // WHERE is_default = 1234 - * $query->filterByIsDefault(array(12, 34)); // WHERE is_default IN (12, 34) - * $query->filterByIsDefault(array('min' => 12)); // WHERE is_default > 12 + * $query->filterByDefault(1234); // WHERE default = 1234 + * $query->filterByDefault(array(12, 34)); // WHERE default IN (12, 34) + * $query->filterByDefault(array('min' => 12)); // WHERE default > 12 * * - * @param mixed $isDefault The value to use as filter. + * @param mixed $default The value to use as filter. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. @@ -793,16 +801,16 @@ abstract class AddressQuery extends ModelCriteria * * @return ChildAddressQuery The current query, for fluid interface */ - public function filterByIsDefault($isDefault = null, $comparison = null) + public function filterByDefault($default = null, $comparison = null) { - if (is_array($isDefault)) { + if (is_array($default)) { $useMinMax = false; - if (isset($isDefault['min'])) { - $this->addUsingAlias(AddressTableMap::IS_DEFAULT, $isDefault['min'], Criteria::GREATER_EQUAL); + if (isset($default['min'])) { + $this->addUsingAlias(AddressTableMap::DEFAULT, $default['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } - if (isset($isDefault['max'])) { - $this->addUsingAlias(AddressTableMap::IS_DEFAULT, $isDefault['max'], Criteria::LESS_EQUAL); + if (isset($default['max'])) { + $this->addUsingAlias(AddressTableMap::DEFAULT, $default['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -813,7 +821,7 @@ abstract class AddressQuery extends ModelCriteria } } - return $this->addUsingAlias(AddressTableMap::IS_DEFAULT, $isDefault, $comparison); + return $this->addUsingAlias(AddressTableMap::DEFAULT, $default, $comparison); } /** @@ -1052,6 +1060,152 @@ abstract class AddressQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'CustomerTitle', '\Thelia\Model\CustomerTitleQuery'); } + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressQuery The current query, for fluid interface + */ + public function filterByCartRelatedByAddressDeliveryId($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(AddressTableMap::ID, $cart->getAddressDeliveryId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + return $this + ->useCartRelatedByAddressDeliveryIdQuery() + ->filterByPrimaryKeys($cart->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCartRelatedByAddressDeliveryId() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CartRelatedByAddressDeliveryId relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildAddressQuery The current query, for fluid interface + */ + public function joinCartRelatedByAddressDeliveryId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CartRelatedByAddressDeliveryId'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CartRelatedByAddressDeliveryId'); + } + + return $this; + } + + /** + * Use the CartRelatedByAddressDeliveryId relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartRelatedByAddressDeliveryIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCartRelatedByAddressDeliveryId($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CartRelatedByAddressDeliveryId', '\Thelia\Model\CartQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressQuery The current query, for fluid interface + */ + public function filterByCartRelatedByAddressInvoiceId($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(AddressTableMap::ID, $cart->getAddressInvoiceId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + return $this + ->useCartRelatedByAddressInvoiceIdQuery() + ->filterByPrimaryKeys($cart->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCartRelatedByAddressInvoiceId() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CartRelatedByAddressInvoiceId relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildAddressQuery The current query, for fluid interface + */ + public function joinCartRelatedByAddressInvoiceId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CartRelatedByAddressInvoiceId'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CartRelatedByAddressInvoiceId'); + } + + return $this; + } + + /** + * Use the CartRelatedByAddressInvoiceId relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartRelatedByAddressInvoiceIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCartRelatedByAddressInvoiceId($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CartRelatedByAddressInvoiceId', '\Thelia\Model\CartQuery'); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Cart.php b/core/lib/Thelia/Model/Base/Cart.php new file mode 100644 index 000000000..58b28ad6b --- /dev/null +++ b/core/lib/Thelia/Model/Base/Cart.php @@ -0,0 +1,2165 @@ +modifiedColumns); + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return in_array($col, $this->modifiedColumns); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return array_unique($this->modifiedColumns); + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + while (false !== ($offset = array_search($col, $this->modifiedColumns))) { + array_splice($this->modifiedColumns, $offset, 1); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Cart instance. If + * obj is an instance of Cart, delegates to + * equals(Cart). Otherwise, returns false. + * + * @param obj The object to compare to. + * @return Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @param string $name The virtual column name + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @return boolean + */ + public function hasVirtualColumn($name) + { + return isset($this->virtualColumns[$name]); + } + + /** + * Get the value of a virtual column in this object + * + * @return mixed + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return Cart The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return Cart The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [token] column value. + * + * @return string + */ + public function getToken() + { + + return $this->token; + } + + /** + * Get the [customer_id] column value. + * + * @return int + */ + public function getCustomerId() + { + + return $this->customer_id; + } + + /** + * Get the [address_delivery_id] column value. + * + * @return int + */ + public function getAddressDeliveryId() + { + + return $this->address_delivery_id; + } + + /** + * Get the [address_invoice_id] column value. + * + * @return int + */ + public function getAddressInvoiceId() + { + + return $this->address_invoice_id; + } + + /** + * Get the [currency_id] column value. + * + * @return int + */ + public function getCurrencyId() + { + + return $this->currency_id; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at !== null ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at !== null ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[] = CartTableMap::ID; + } + + + return $this; + } // setId() + + /** + * Set the value of [token] column. + * + * @param string $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->token !== $v) { + $this->token = $v; + $this->modifiedColumns[] = CartTableMap::TOKEN; + } + + + return $this; + } // setToken() + + /** + * Set the value of [customer_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setCustomerId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->customer_id !== $v) { + $this->customer_id = $v; + $this->modifiedColumns[] = CartTableMap::CUSTOMER_ID; + } + + if ($this->aCustomer !== null && $this->aCustomer->getId() !== $v) { + $this->aCustomer = null; + } + + + return $this; + } // setCustomerId() + + /** + * Set the value of [address_delivery_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setAddressDeliveryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->address_delivery_id !== $v) { + $this->address_delivery_id = $v; + $this->modifiedColumns[] = CartTableMap::ADDRESS_DELIVERY_ID; + } + + if ($this->aAddressRelatedByAddressDeliveryId !== null && $this->aAddressRelatedByAddressDeliveryId->getId() !== $v) { + $this->aAddressRelatedByAddressDeliveryId = null; + } + + + return $this; + } // setAddressDeliveryId() + + /** + * Set the value of [address_invoice_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setAddressInvoiceId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->address_invoice_id !== $v) { + $this->address_invoice_id = $v; + $this->modifiedColumns[] = CartTableMap::ADDRESS_INVOICE_ID; + } + + if ($this->aAddressRelatedByAddressInvoiceId !== null && $this->aAddressRelatedByAddressInvoiceId->getId() !== $v) { + $this->aAddressRelatedByAddressInvoiceId = null; + } + + + return $this; + } // setAddressInvoiceId() + + /** + * Set the value of [currency_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setCurrencyId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->currency_id !== $v) { + $this->currency_id = $v; + $this->modifiedColumns[] = CartTableMap::CURRENCY_ID; + } + + if ($this->aCurrency !== null && $this->aCurrency->getId() !== $v) { + $this->aCurrency = null; + } + + + return $this; + } // setCurrencyId() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[] = CartTableMap::CREATED_AT; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[] = CartTableMap::UPDATED_AT; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : CartTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CartTableMap::translateFieldName('Token', TableMap::TYPE_PHPNAME, $indexType)]; + $this->token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CartTableMap::translateFieldName('CustomerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->customer_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CartTableMap::translateFieldName('AddressDeliveryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->address_delivery_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CartTableMap::translateFieldName('AddressInvoiceId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->address_invoice_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CartTableMap::translateFieldName('CurrencyId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->currency_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CartTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CartTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 8; // 8 = CartTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\Cart object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCustomer !== null && $this->customer_id !== $this->aCustomer->getId()) { + $this->aCustomer = null; + } + if ($this->aAddressRelatedByAddressDeliveryId !== null && $this->address_delivery_id !== $this->aAddressRelatedByAddressDeliveryId->getId()) { + $this->aAddressRelatedByAddressDeliveryId = null; + } + if ($this->aAddressRelatedByAddressInvoiceId !== null && $this->address_invoice_id !== $this->aAddressRelatedByAddressInvoiceId->getId()) { + $this->aAddressRelatedByAddressInvoiceId = null; + } + if ($this->aCurrency !== null && $this->currency_id !== $this->aCurrency->getId()) { + $this->aCurrency = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CartTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCartQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCustomer = null; + $this->aAddressRelatedByAddressDeliveryId = null; + $this->aAddressRelatedByAddressInvoiceId = null; + $this->aCurrency = null; + $this->collCartItems = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Cart::setDeleted() + * @see Cart::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(CartTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildCartQuery::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; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CartTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(CartTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(CartTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(CartTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + CartTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCustomer !== null) { + if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { + $affectedRows += $this->aCustomer->save($con); + } + $this->setCustomer($this->aCustomer); + } + + if ($this->aAddressRelatedByAddressDeliveryId !== null) { + if ($this->aAddressRelatedByAddressDeliveryId->isModified() || $this->aAddressRelatedByAddressDeliveryId->isNew()) { + $affectedRows += $this->aAddressRelatedByAddressDeliveryId->save($con); + } + $this->setAddressRelatedByAddressDeliveryId($this->aAddressRelatedByAddressDeliveryId); + } + + if ($this->aAddressRelatedByAddressInvoiceId !== null) { + if ($this->aAddressRelatedByAddressInvoiceId->isModified() || $this->aAddressRelatedByAddressInvoiceId->isNew()) { + $affectedRows += $this->aAddressRelatedByAddressInvoiceId->save($con); + } + $this->setAddressRelatedByAddressInvoiceId($this->aAddressRelatedByAddressInvoiceId); + } + + if ($this->aCurrency !== null) { + if ($this->aCurrency->isModified() || $this->aCurrency->isNew()) { + $affectedRows += $this->aCurrency->save($con); + } + $this->setCurrency($this->aCurrency); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->cartItemsScheduledForDeletion !== null) { + if (!$this->cartItemsScheduledForDeletion->isEmpty()) { + \Thelia\Model\CartItemQuery::create() + ->filterByPrimaryKeys($this->cartItemsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->cartItemsScheduledForDeletion = null; + } + } + + if ($this->collCartItems !== null) { + foreach ($this->collCartItems as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[] = CartTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CartTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(CartTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(CartTableMap::TOKEN)) { + $modifiedColumns[':p' . $index++] = 'TOKEN'; + } + if ($this->isColumnModified(CartTableMap::CUSTOMER_ID)) { + $modifiedColumns[':p' . $index++] = 'CUSTOMER_ID'; + } + if ($this->isColumnModified(CartTableMap::ADDRESS_DELIVERY_ID)) { + $modifiedColumns[':p' . $index++] = 'ADDRESS_DELIVERY_ID'; + } + if ($this->isColumnModified(CartTableMap::ADDRESS_INVOICE_ID)) { + $modifiedColumns[':p' . $index++] = 'ADDRESS_INVOICE_ID'; + } + if ($this->isColumnModified(CartTableMap::CURRENCY_ID)) { + $modifiedColumns[':p' . $index++] = 'CURRENCY_ID'; + } + if ($this->isColumnModified(CartTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(CartTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO cart (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'TOKEN': + $stmt->bindValue($identifier, $this->token, PDO::PARAM_STR); + break; + case 'CUSTOMER_ID': + $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT); + break; + case 'ADDRESS_DELIVERY_ID': + $stmt->bindValue($identifier, $this->address_delivery_id, PDO::PARAM_INT); + break; + case 'ADDRESS_INVOICE_ID': + $stmt->bindValue($identifier, $this->address_invoice_id, PDO::PARAM_INT); + break; + case 'CURRENCY_ID': + $stmt->bindValue($identifier, $this->currency_id, PDO::PARAM_INT); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = CartTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getToken(); + break; + case 2: + return $this->getCustomerId(); + break; + case 3: + return $this->getAddressDeliveryId(); + break; + case 4: + return $this->getAddressInvoiceId(); + break; + case 5: + return $this->getCurrencyId(); + break; + case 6: + return $this->getCreatedAt(); + break; + case 7: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['Cart'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Cart'][$this->getPrimaryKey()] = true; + $keys = CartTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getToken(), + $keys[2] => $this->getCustomerId(), + $keys[3] => $this->getAddressDeliveryId(), + $keys[4] => $this->getAddressInvoiceId(), + $keys[5] => $this->getCurrencyId(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCustomer) { + $result['Customer'] = $this->aCustomer->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aAddressRelatedByAddressDeliveryId) { + $result['AddressRelatedByAddressDeliveryId'] = $this->aAddressRelatedByAddressDeliveryId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aAddressRelatedByAddressInvoiceId) { + $result['AddressRelatedByAddressInvoiceId'] = $this->aAddressRelatedByAddressInvoiceId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aCurrency) { + $result['Currency'] = $this->aCurrency->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->collCartItems) { + $result['CartItems'] = $this->collCartItems->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = CartTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setToken($value); + break; + case 2: + $this->setCustomerId($value); + break; + case 3: + $this->setAddressDeliveryId($value); + break; + case 4: + $this->setAddressInvoiceId($value); + break; + case 5: + $this->setCurrencyId($value); + break; + case 6: + $this->setCreatedAt($value); + break; + case 7: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = CartTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setToken($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCustomerId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setAddressDeliveryId($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setAddressInvoiceId($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setCurrencyId($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(CartTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CartTableMap::ID)) $criteria->add(CartTableMap::ID, $this->id); + if ($this->isColumnModified(CartTableMap::TOKEN)) $criteria->add(CartTableMap::TOKEN, $this->token); + if ($this->isColumnModified(CartTableMap::CUSTOMER_ID)) $criteria->add(CartTableMap::CUSTOMER_ID, $this->customer_id); + if ($this->isColumnModified(CartTableMap::ADDRESS_DELIVERY_ID)) $criteria->add(CartTableMap::ADDRESS_DELIVERY_ID, $this->address_delivery_id); + if ($this->isColumnModified(CartTableMap::ADDRESS_INVOICE_ID)) $criteria->add(CartTableMap::ADDRESS_INVOICE_ID, $this->address_invoice_id); + if ($this->isColumnModified(CartTableMap::CURRENCY_ID)) $criteria->add(CartTableMap::CURRENCY_ID, $this->currency_id); + if ($this->isColumnModified(CartTableMap::CREATED_AT)) $criteria->add(CartTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(CartTableMap::UPDATED_AT)) $criteria->add(CartTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(CartTableMap::DATABASE_NAME); + $criteria->add(CartTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\Cart (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setToken($this->getToken()); + $copyObj->setCustomerId($this->getCustomerId()); + $copyObj->setAddressDeliveryId($this->getAddressDeliveryId()); + $copyObj->setAddressInvoiceId($this->getAddressInvoiceId()); + $copyObj->setCurrencyId($this->getCurrencyId()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getCartItems() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCartItem($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\Cart Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCustomer object. + * + * @param ChildCustomer $v + * @return \Thelia\Model\Cart The current object (for fluent API support) + * @throws PropelException + */ + public function setCustomer(ChildCustomer $v = null) + { + if ($v === null) { + $this->setCustomerId(NULL); + } else { + $this->setCustomerId($v->getId()); + } + + $this->aCustomer = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCustomer object, it will not be re-added. + if ($v !== null) { + $v->addCart($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCustomer object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCustomer The associated ChildCustomer object. + * @throws PropelException + */ + public function getCustomer(ConnectionInterface $con = null) + { + if ($this->aCustomer === null && ($this->customer_id !== null)) { + $this->aCustomer = ChildCustomerQuery::create()->findPk($this->customer_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->aCustomer->addCarts($this); + */ + } + + return $this->aCustomer; + } + + /** + * Declares an association between this object and a ChildAddress object. + * + * @param ChildAddress $v + * @return \Thelia\Model\Cart The current object (for fluent API support) + * @throws PropelException + */ + public function setAddressRelatedByAddressDeliveryId(ChildAddress $v = null) + { + if ($v === null) { + $this->setAddressDeliveryId(NULL); + } else { + $this->setAddressDeliveryId($v->getId()); + } + + $this->aAddressRelatedByAddressDeliveryId = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildAddress object, it will not be re-added. + if ($v !== null) { + $v->addCartRelatedByAddressDeliveryId($this); + } + + + return $this; + } + + + /** + * Get the associated ChildAddress object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildAddress The associated ChildAddress object. + * @throws PropelException + */ + public function getAddressRelatedByAddressDeliveryId(ConnectionInterface $con = null) + { + if ($this->aAddressRelatedByAddressDeliveryId === null && ($this->address_delivery_id !== null)) { + $this->aAddressRelatedByAddressDeliveryId = ChildAddressQuery::create()->findPk($this->address_delivery_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->aAddressRelatedByAddressDeliveryId->addCartsRelatedByAddressDeliveryId($this); + */ + } + + return $this->aAddressRelatedByAddressDeliveryId; + } + + /** + * Declares an association between this object and a ChildAddress object. + * + * @param ChildAddress $v + * @return \Thelia\Model\Cart The current object (for fluent API support) + * @throws PropelException + */ + public function setAddressRelatedByAddressInvoiceId(ChildAddress $v = null) + { + if ($v === null) { + $this->setAddressInvoiceId(NULL); + } else { + $this->setAddressInvoiceId($v->getId()); + } + + $this->aAddressRelatedByAddressInvoiceId = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildAddress object, it will not be re-added. + if ($v !== null) { + $v->addCartRelatedByAddressInvoiceId($this); + } + + + return $this; + } + + + /** + * Get the associated ChildAddress object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildAddress The associated ChildAddress object. + * @throws PropelException + */ + public function getAddressRelatedByAddressInvoiceId(ConnectionInterface $con = null) + { + if ($this->aAddressRelatedByAddressInvoiceId === null && ($this->address_invoice_id !== null)) { + $this->aAddressRelatedByAddressInvoiceId = ChildAddressQuery::create()->findPk($this->address_invoice_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->aAddressRelatedByAddressInvoiceId->addCartsRelatedByAddressInvoiceId($this); + */ + } + + return $this->aAddressRelatedByAddressInvoiceId; + } + + /** + * Declares an association between this object and a ChildCurrency object. + * + * @param ChildCurrency $v + * @return \Thelia\Model\Cart The current object (for fluent API support) + * @throws PropelException + */ + public function setCurrency(ChildCurrency $v = null) + { + if ($v === null) { + $this->setCurrencyId(NULL); + } else { + $this->setCurrencyId($v->getId()); + } + + $this->aCurrency = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCurrency object, it will not be re-added. + if ($v !== null) { + $v->addCart($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCurrency object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCurrency The associated ChildCurrency object. + * @throws PropelException + */ + public function getCurrency(ConnectionInterface $con = null) + { + if ($this->aCurrency === null && ($this->currency_id !== null)) { + $this->aCurrency = ChildCurrencyQuery::create()->findPk($this->currency_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->aCurrency->addCarts($this); + */ + } + + return $this->aCurrency; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('CartItem' == $relationName) { + return $this->initCartItems(); + } + } + + /** + * Clears out the collCartItems collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCartItems() + */ + public function clearCartItems() + { + $this->collCartItems = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCartItems collection loaded partially. + */ + public function resetPartialCartItems($v = true) + { + $this->collCartItemsPartial = $v; + } + + /** + * Initializes the collCartItems collection. + * + * By default this just sets the collCartItems collection to an empty array (like clearcollCartItems()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCartItems($overrideExisting = true) + { + if (null !== $this->collCartItems && !$overrideExisting) { + return; + } + $this->collCartItems = new ObjectCollection(); + $this->collCartItems->setModel('\Thelia\Model\CartItem'); + } + + /** + * Gets an array of ChildCartItem objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCart is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCartItem[] List of ChildCartItem objects + * @throws PropelException + */ + public function getCartItems($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + // return empty collection + $this->initCartItems(); + } else { + $collCartItems = ChildCartItemQuery::create(null, $criteria) + ->filterByCart($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartItemsPartial && count($collCartItems)) { + $this->initCartItems(false); + + foreach ($collCartItems as $obj) { + if (false == $this->collCartItems->contains($obj)) { + $this->collCartItems->append($obj); + } + } + + $this->collCartItemsPartial = true; + } + + $collCartItems->getInternalIterator()->rewind(); + + return $collCartItems; + } + + if ($partial && $this->collCartItems) { + foreach ($this->collCartItems as $obj) { + if ($obj->isNew()) { + $collCartItems[] = $obj; + } + } + } + + $this->collCartItems = $collCartItems; + $this->collCartItemsPartial = false; + } + } + + return $this->collCartItems; + } + + /** + * Sets a collection of CartItem objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $cartItems A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCart The current object (for fluent API support) + */ + public function setCartItems(Collection $cartItems, ConnectionInterface $con = null) + { + $cartItemsToDelete = $this->getCartItems(new Criteria(), $con)->diff($cartItems); + + + $this->cartItemsScheduledForDeletion = $cartItemsToDelete; + + foreach ($cartItemsToDelete as $cartItemRemoved) { + $cartItemRemoved->setCart(null); + } + + $this->collCartItems = null; + foreach ($cartItems as $cartItem) { + $this->addCartItem($cartItem); + } + + $this->collCartItems = $cartItems; + $this->collCartItemsPartial = false; + + return $this; + } + + /** + * Returns the number of related CartItem objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CartItem objects. + * @throws PropelException + */ + public function countCartItems(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCartItems()); + } + + $query = ChildCartItemQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCart($this) + ->count($con); + } + + return count($this->collCartItems); + } + + /** + * Method called to associate a ChildCartItem object to this object + * through the ChildCartItem foreign key attribute. + * + * @param ChildCartItem $l ChildCartItem + * @return \Thelia\Model\Cart The current object (for fluent API support) + */ + public function addCartItem(ChildCartItem $l) + { + if ($this->collCartItems === null) { + $this->initCartItems(); + $this->collCartItemsPartial = true; + } + + if (!in_array($l, $this->collCartItems->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCartItem($l); + } + + return $this; + } + + /** + * @param CartItem $cartItem The cartItem object to add. + */ + protected function doAddCartItem($cartItem) + { + $this->collCartItems[]= $cartItem; + $cartItem->setCart($this); + } + + /** + * @param CartItem $cartItem The cartItem object to remove. + * @return ChildCart The current object (for fluent API support) + */ + public function removeCartItem($cartItem) + { + if ($this->getCartItems()->contains($cartItem)) { + $this->collCartItems->remove($this->collCartItems->search($cartItem)); + if (null === $this->cartItemsScheduledForDeletion) { + $this->cartItemsScheduledForDeletion = clone $this->collCartItems; + $this->cartItemsScheduledForDeletion->clear(); + } + $this->cartItemsScheduledForDeletion[]= clone $cartItem; + $cartItem->setCart(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Cart is new, it will return + * an empty collection; or if this Cart has previously + * been saved, it will retrieve related CartItems 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 Cart. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinProduct($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Product', $joinBehavior); + + return $this->getCartItems($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Cart is new, it will return + * an empty collection; or if this Cart has previously + * been saved, it will retrieve related CartItems 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 Cart. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinCombination($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Combination', $joinBehavior); + + return $this->getCartItems($query, $con); + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->token = null; + $this->customer_id = null; + $this->address_delivery_id = null; + $this->address_invoice_id = null; + $this->currency_id = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collCartItems) { + foreach ($this->collCartItems as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + if ($this->collCartItems instanceof Collection) { + $this->collCartItems->clearIterator(); + } + $this->collCartItems = null; + $this->aCustomer = null; + $this->aAddressRelatedByAddressDeliveryId = null; + $this->aAddressRelatedByAddressInvoiceId = null; + $this->aCurrency = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CartTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildCart The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[] = CartTableMap::UPDATED_AT; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/CartItem.php b/core/lib/Thelia/Model/Base/CartItem.php new file mode 100644 index 000000000..f5eea36fc --- /dev/null +++ b/core/lib/Thelia/Model/Base/CartItem.php @@ -0,0 +1,1707 @@ +quantity = 1; + } + + /** + * Initializes internal state of Thelia\Model\Base\CartItem object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !empty($this->modifiedColumns); + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return in_array($col, $this->modifiedColumns); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return array_unique($this->modifiedColumns); + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + while (false !== ($offset = array_search($col, $this->modifiedColumns))) { + array_splice($this->modifiedColumns, $offset, 1); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another CartItem instance. If + * obj is an instance of CartItem, delegates to + * equals(CartItem). Otherwise, returns false. + * + * @param obj The object to compare to. + * @return Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @param string $name The virtual column name + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @return boolean + */ + public function hasVirtualColumn($name) + { + return isset($this->virtualColumns[$name]); + } + + /** + * Get the value of a virtual column in this object + * + * @return mixed + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return CartItem The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return CartItem The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [cart_id] column value. + * + * @return int + */ + public function getCartId() + { + + return $this->cart_id; + } + + /** + * Get the [product_id] column value. + * + * @return int + */ + public function getProductId() + { + + return $this->product_id; + } + + /** + * Get the [quantity] column value. + * + * @return double + */ + public function getQuantity() + { + + return $this->quantity; + } + + /** + * Get the [combination_id] column value. + * + * @return int + */ + public function getCombinationId() + { + + return $this->combination_id; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at !== null ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at !== null ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[] = CartItemTableMap::ID; + } + + + return $this; + } // setId() + + /** + * Set the value of [cart_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setCartId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->cart_id !== $v) { + $this->cart_id = $v; + $this->modifiedColumns[] = CartItemTableMap::CART_ID; + } + + if ($this->aCart !== null && $this->aCart->getId() !== $v) { + $this->aCart = null; + } + + + return $this; + } // setCartId() + + /** + * Set the value of [product_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setProductId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->product_id !== $v) { + $this->product_id = $v; + $this->modifiedColumns[] = CartItemTableMap::PRODUCT_ID; + } + + if ($this->aProduct !== null && $this->aProduct->getId() !== $v) { + $this->aProduct = null; + } + + + return $this; + } // setProductId() + + /** + * Set the value of [quantity] column. + * + * @param double $v new value + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setQuantity($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->quantity !== $v) { + $this->quantity = $v; + $this->modifiedColumns[] = CartItemTableMap::QUANTITY; + } + + + return $this; + } // setQuantity() + + /** + * Set the value of [combination_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setCombinationId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->combination_id !== $v) { + $this->combination_id = $v; + $this->modifiedColumns[] = CartItemTableMap::COMBINATION_ID; + } + + if ($this->aCombination !== null && $this->aCombination->getId() !== $v) { + $this->aCombination = null; + } + + + return $this; + } // setCombinationId() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[] = CartItemTableMap::CREATED_AT; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\CartItem The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[] = CartItemTableMap::UPDATED_AT; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->quantity !== 1) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : CartItemTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CartItemTableMap::translateFieldName('CartId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->cart_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CartItemTableMap::translateFieldName('ProductId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->product_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CartItemTableMap::translateFieldName('Quantity', TableMap::TYPE_PHPNAME, $indexType)]; + $this->quantity = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CartItemTableMap::translateFieldName('CombinationId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->combination_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CartItemTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CartItemTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 7; // 7 = CartItemTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\CartItem object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCart !== null && $this->cart_id !== $this->aCart->getId()) { + $this->aCart = null; + } + if ($this->aProduct !== null && $this->product_id !== $this->aProduct->getId()) { + $this->aProduct = null; + } + if ($this->aCombination !== null && $this->combination_id !== $this->aCombination->getId()) { + $this->aCombination = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CartItemTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCartItemQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCart = null; + $this->aProduct = null; + $this->aCombination = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see CartItem::setDeleted() + * @see CartItem::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(CartItemTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildCartItemQuery::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; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CartItemTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(CartItemTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(CartItemTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(CartItemTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + CartItemTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCart !== null) { + if ($this->aCart->isModified() || $this->aCart->isNew()) { + $affectedRows += $this->aCart->save($con); + } + $this->setCart($this->aCart); + } + + if ($this->aProduct !== null) { + if ($this->aProduct->isModified() || $this->aProduct->isNew()) { + $affectedRows += $this->aProduct->save($con); + } + $this->setProduct($this->aProduct); + } + + if ($this->aCombination !== null) { + if ($this->aCombination->isModified() || $this->aCombination->isNew()) { + $affectedRows += $this->aCombination->save($con); + } + $this->setCombination($this->aCombination); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[] = CartItemTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CartItemTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(CartItemTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(CartItemTableMap::CART_ID)) { + $modifiedColumns[':p' . $index++] = 'CART_ID'; + } + if ($this->isColumnModified(CartItemTableMap::PRODUCT_ID)) { + $modifiedColumns[':p' . $index++] = 'PRODUCT_ID'; + } + if ($this->isColumnModified(CartItemTableMap::QUANTITY)) { + $modifiedColumns[':p' . $index++] = 'QUANTITY'; + } + if ($this->isColumnModified(CartItemTableMap::COMBINATION_ID)) { + $modifiedColumns[':p' . $index++] = 'COMBINATION_ID'; + } + if ($this->isColumnModified(CartItemTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(CartItemTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO cart_item (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'CART_ID': + $stmt->bindValue($identifier, $this->cart_id, PDO::PARAM_INT); + break; + case 'PRODUCT_ID': + $stmt->bindValue($identifier, $this->product_id, PDO::PARAM_INT); + break; + case 'QUANTITY': + $stmt->bindValue($identifier, $this->quantity, PDO::PARAM_STR); + break; + case 'COMBINATION_ID': + $stmt->bindValue($identifier, $this->combination_id, PDO::PARAM_INT); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = CartItemTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getCartId(); + break; + case 2: + return $this->getProductId(); + break; + case 3: + return $this->getQuantity(); + break; + case 4: + return $this->getCombinationId(); + break; + case 5: + return $this->getCreatedAt(); + break; + case 6: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['CartItem'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['CartItem'][$this->getPrimaryKey()] = true; + $keys = CartItemTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getCartId(), + $keys[2] => $this->getProductId(), + $keys[3] => $this->getQuantity(), + $keys[4] => $this->getCombinationId(), + $keys[5] => $this->getCreatedAt(), + $keys[6] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCart) { + $result['Cart'] = $this->aCart->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aProduct) { + $result['Product'] = $this->aProduct->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aCombination) { + $result['Combination'] = $this->aCombination->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = CartItemTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setCartId($value); + break; + case 2: + $this->setProductId($value); + break; + case 3: + $this->setQuantity($value); + break; + case 4: + $this->setCombinationId($value); + break; + case 5: + $this->setCreatedAt($value); + break; + case 6: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = CartItemTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCartId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setProductId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setQuantity($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCombinationId($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(CartItemTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CartItemTableMap::ID)) $criteria->add(CartItemTableMap::ID, $this->id); + if ($this->isColumnModified(CartItemTableMap::CART_ID)) $criteria->add(CartItemTableMap::CART_ID, $this->cart_id); + if ($this->isColumnModified(CartItemTableMap::PRODUCT_ID)) $criteria->add(CartItemTableMap::PRODUCT_ID, $this->product_id); + if ($this->isColumnModified(CartItemTableMap::QUANTITY)) $criteria->add(CartItemTableMap::QUANTITY, $this->quantity); + if ($this->isColumnModified(CartItemTableMap::COMBINATION_ID)) $criteria->add(CartItemTableMap::COMBINATION_ID, $this->combination_id); + if ($this->isColumnModified(CartItemTableMap::CREATED_AT)) $criteria->add(CartItemTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(CartItemTableMap::UPDATED_AT)) $criteria->add(CartItemTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(CartItemTableMap::DATABASE_NAME); + $criteria->add(CartItemTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\CartItem (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setCartId($this->getCartId()); + $copyObj->setProductId($this->getProductId()); + $copyObj->setQuantity($this->getQuantity()); + $copyObj->setCombinationId($this->getCombinationId()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\CartItem Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCart object. + * + * @param ChildCart $v + * @return \Thelia\Model\CartItem The current object (for fluent API support) + * @throws PropelException + */ + public function setCart(ChildCart $v = null) + { + if ($v === null) { + $this->setCartId(NULL); + } else { + $this->setCartId($v->getId()); + } + + $this->aCart = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCart object, it will not be re-added. + if ($v !== null) { + $v->addCartItem($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCart object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCart The associated ChildCart object. + * @throws PropelException + */ + public function getCart(ConnectionInterface $con = null) + { + if ($this->aCart === null && ($this->cart_id !== null)) { + $this->aCart = ChildCartQuery::create()->findPk($this->cart_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->aCart->addCartItems($this); + */ + } + + return $this->aCart; + } + + /** + * Declares an association between this object and a ChildProduct object. + * + * @param ChildProduct $v + * @return \Thelia\Model\CartItem The current object (for fluent API support) + * @throws PropelException + */ + public function setProduct(ChildProduct $v = null) + { + if ($v === null) { + $this->setProductId(NULL); + } else { + $this->setProductId($v->getId()); + } + + $this->aProduct = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildProduct object, it will not be re-added. + if ($v !== null) { + $v->addCartItem($this); + } + + + return $this; + } + + + /** + * Get the associated ChildProduct object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildProduct The associated ChildProduct object. + * @throws PropelException + */ + public function getProduct(ConnectionInterface $con = null) + { + if ($this->aProduct === null && ($this->product_id !== null)) { + $this->aProduct = ChildProductQuery::create()->findPk($this->product_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->aProduct->addCartItems($this); + */ + } + + return $this->aProduct; + } + + /** + * Declares an association between this object and a ChildCombination object. + * + * @param ChildCombination $v + * @return \Thelia\Model\CartItem The current object (for fluent API support) + * @throws PropelException + */ + public function setCombination(ChildCombination $v = null) + { + if ($v === null) { + $this->setCombinationId(NULL); + } else { + $this->setCombinationId($v->getId()); + } + + $this->aCombination = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCombination object, it will not be re-added. + if ($v !== null) { + $v->addCartItem($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCombination object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCombination The associated ChildCombination object. + * @throws PropelException + */ + public function getCombination(ConnectionInterface $con = null) + { + if ($this->aCombination === null && ($this->combination_id !== null)) { + $this->aCombination = ChildCombinationQuery::create()->findPk($this->combination_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->aCombination->addCartItems($this); + */ + } + + return $this->aCombination; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->cart_id = null; + $this->product_id = null; + $this->quantity = null; + $this->combination_id = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCart = null; + $this->aProduct = null; + $this->aCombination = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CartItemTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildCartItem The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[] = CartItemTableMap::UPDATED_AT; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/CartItemQuery.php b/core/lib/Thelia/Model/Base/CartItemQuery.php new file mode 100644 index 000000000..8d96f435d --- /dev/null +++ b/core/lib/Thelia/Model/Base/CartItemQuery.php @@ -0,0 +1,930 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCartItem|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = CartItemTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CartItemTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCartItem A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, CART_ID, PRODUCT_ID, QUANTITY, COMBINATION_ID, CREATED_AT, UPDATED_AT FROM cart_item WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildCartItem(); + $obj->hydrate($row); + CartItemTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCartItem|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(CartItemTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(CartItemTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(CartItemTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(CartItemTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the cart_id column + * + * Example usage: + * + * $query->filterByCartId(1234); // WHERE cart_id = 1234 + * $query->filterByCartId(array(12, 34)); // WHERE cart_id IN (12, 34) + * $query->filterByCartId(array('min' => 12)); // WHERE cart_id > 12 + * + * + * @see filterByCart() + * + * @param mixed $cartId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByCartId($cartId = null, $comparison = null) + { + if (is_array($cartId)) { + $useMinMax = false; + if (isset($cartId['min'])) { + $this->addUsingAlias(CartItemTableMap::CART_ID, $cartId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($cartId['max'])) { + $this->addUsingAlias(CartItemTableMap::CART_ID, $cartId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::CART_ID, $cartId, $comparison); + } + + /** + * Filter the query on the product_id column + * + * Example usage: + * + * $query->filterByProductId(1234); // WHERE product_id = 1234 + * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34) + * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12 + * + * + * @see filterByProduct() + * + * @param mixed $productId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByProductId($productId = null, $comparison = null) + { + if (is_array($productId)) { + $useMinMax = false; + if (isset($productId['min'])) { + $this->addUsingAlias(CartItemTableMap::PRODUCT_ID, $productId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($productId['max'])) { + $this->addUsingAlias(CartItemTableMap::PRODUCT_ID, $productId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::PRODUCT_ID, $productId, $comparison); + } + + /** + * Filter the query on the quantity column + * + * Example usage: + * + * $query->filterByQuantity(1234); // WHERE quantity = 1234 + * $query->filterByQuantity(array(12, 34)); // WHERE quantity IN (12, 34) + * $query->filterByQuantity(array('min' => 12)); // WHERE quantity > 12 + * + * + * @param mixed $quantity The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByQuantity($quantity = null, $comparison = null) + { + if (is_array($quantity)) { + $useMinMax = false; + if (isset($quantity['min'])) { + $this->addUsingAlias(CartItemTableMap::QUANTITY, $quantity['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($quantity['max'])) { + $this->addUsingAlias(CartItemTableMap::QUANTITY, $quantity['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::QUANTITY, $quantity, $comparison); + } + + /** + * Filter the query on the combination_id column + * + * Example usage: + * + * $query->filterByCombinationId(1234); // WHERE combination_id = 1234 + * $query->filterByCombinationId(array(12, 34)); // WHERE combination_id IN (12, 34) + * $query->filterByCombinationId(array('min' => 12)); // WHERE combination_id > 12 + * + * + * @see filterByCombination() + * + * @param mixed $combinationId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByCombinationId($combinationId = null, $comparison = null) + { + if (is_array($combinationId)) { + $useMinMax = false; + if (isset($combinationId['min'])) { + $this->addUsingAlias(CartItemTableMap::COMBINATION_ID, $combinationId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($combinationId['max'])) { + $this->addUsingAlias(CartItemTableMap::COMBINATION_ID, $combinationId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::COMBINATION_ID, $combinationId, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(CartItemTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(CartItemTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(CartItemTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(CartItemTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartItemTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByCart($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(CartItemTableMap::CART_ID, $cart->getId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartItemTableMap::CART_ID, $cart->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCart() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Cart relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function joinCart($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Cart'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Cart'); + } + + return $this; + } + + /** + * Use the Cart relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCart($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Cart', '\Thelia\Model\CartQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Product object + * + * @param \Thelia\Model\Product|ObjectCollection $product The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByProduct($product, $comparison = null) + { + if ($product instanceof \Thelia\Model\Product) { + return $this + ->addUsingAlias(CartItemTableMap::PRODUCT_ID, $product->getId(), $comparison); + } elseif ($product instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartItemTableMap::PRODUCT_ID, $product->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByProduct() only accepts arguments of type \Thelia\Model\Product or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Product relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function joinProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Product'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Product'); + } + + return $this; + } + + /** + * Use the Product relation Product object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ProductQuery A secondary query class using the current class as primary query + */ + public function useProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinProduct($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Product', '\Thelia\Model\ProductQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Combination object + * + * @param \Thelia\Model\Combination|ObjectCollection $combination The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function filterByCombination($combination, $comparison = null) + { + if ($combination instanceof \Thelia\Model\Combination) { + return $this + ->addUsingAlias(CartItemTableMap::COMBINATION_ID, $combination->getId(), $comparison); + } elseif ($combination instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartItemTableMap::COMBINATION_ID, $combination->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCombination() only accepts arguments of type \Thelia\Model\Combination or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Combination relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function joinCombination($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Combination'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Combination'); + } + + return $this; + } + + /** + * Use the Combination relation Combination object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CombinationQuery A secondary query class using the current class as primary query + */ + public function useCombinationQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCombination($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Combination', '\Thelia\Model\CombinationQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCartItem $cartItem Object to remove from the list of results + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function prune($cartItem = null) + { + if ($cartItem) { + $this->addUsingAlias(CartItemTableMap::ID, $cartItem->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the cart_item table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartItemTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + CartItemTableMap::clearInstancePool(); + CartItemTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildCartItem or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildCartItem object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartItemTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CartItemTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + CartItemTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CartItemTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(CartItemTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(CartItemTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(CartItemTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(CartItemTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(CartItemTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildCartItemQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(CartItemTableMap::CREATED_AT); + } + +} // CartItemQuery diff --git a/core/lib/Thelia/Model/Base/CartQuery.php b/core/lib/Thelia/Model/Base/CartQuery.php new file mode 100644 index 000000000..24473bd5a --- /dev/null +++ b/core/lib/Thelia/Model/Base/CartQuery.php @@ -0,0 +1,1121 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCart|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = CartTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CartTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCart A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, TOKEN, CUSTOMER_ID, ADDRESS_DELIVERY_ID, ADDRESS_INVOICE_ID, CURRENCY_ID, CREATED_AT, UPDATED_AT FROM cart WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildCart(); + $obj->hydrate($row); + CartTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCart|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(CartTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(CartTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(CartTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(CartTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the token column + * + * Example usage: + * + * $query->filterByToken('fooValue'); // WHERE token = 'fooValue' + * $query->filterByToken('%fooValue%'); // WHERE token LIKE '%fooValue%' + * + * + * @param string $token The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByToken($token = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($token)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $token)) { + $token = str_replace('*', '%', $token); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(CartTableMap::TOKEN, $token, $comparison); + } + + /** + * Filter the query on the customer_id column + * + * Example usage: + * + * $query->filterByCustomerId(1234); // WHERE customer_id = 1234 + * $query->filterByCustomerId(array(12, 34)); // WHERE customer_id IN (12, 34) + * $query->filterByCustomerId(array('min' => 12)); // WHERE customer_id > 12 + * + * + * @see filterByCustomer() + * + * @param mixed $customerId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCustomerId($customerId = null, $comparison = null) + { + if (is_array($customerId)) { + $useMinMax = false; + if (isset($customerId['min'])) { + $this->addUsingAlias(CartTableMap::CUSTOMER_ID, $customerId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($customerId['max'])) { + $this->addUsingAlias(CartTableMap::CUSTOMER_ID, $customerId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::CUSTOMER_ID, $customerId, $comparison); + } + + /** + * Filter the query on the address_delivery_id column + * + * Example usage: + * + * $query->filterByAddressDeliveryId(1234); // WHERE address_delivery_id = 1234 + * $query->filterByAddressDeliveryId(array(12, 34)); // WHERE address_delivery_id IN (12, 34) + * $query->filterByAddressDeliveryId(array('min' => 12)); // WHERE address_delivery_id > 12 + * + * + * @see filterByAddressRelatedByAddressDeliveryId() + * + * @param mixed $addressDeliveryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByAddressDeliveryId($addressDeliveryId = null, $comparison = null) + { + if (is_array($addressDeliveryId)) { + $useMinMax = false; + if (isset($addressDeliveryId['min'])) { + $this->addUsingAlias(CartTableMap::ADDRESS_DELIVERY_ID, $addressDeliveryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($addressDeliveryId['max'])) { + $this->addUsingAlias(CartTableMap::ADDRESS_DELIVERY_ID, $addressDeliveryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::ADDRESS_DELIVERY_ID, $addressDeliveryId, $comparison); + } + + /** + * Filter the query on the address_invoice_id column + * + * Example usage: + * + * $query->filterByAddressInvoiceId(1234); // WHERE address_invoice_id = 1234 + * $query->filterByAddressInvoiceId(array(12, 34)); // WHERE address_invoice_id IN (12, 34) + * $query->filterByAddressInvoiceId(array('min' => 12)); // WHERE address_invoice_id > 12 + * + * + * @see filterByAddressRelatedByAddressInvoiceId() + * + * @param mixed $addressInvoiceId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByAddressInvoiceId($addressInvoiceId = null, $comparison = null) + { + if (is_array($addressInvoiceId)) { + $useMinMax = false; + if (isset($addressInvoiceId['min'])) { + $this->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $addressInvoiceId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($addressInvoiceId['max'])) { + $this->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $addressInvoiceId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $addressInvoiceId, $comparison); + } + + /** + * Filter the query on the currency_id column + * + * Example usage: + * + * $query->filterByCurrencyId(1234); // WHERE currency_id = 1234 + * $query->filterByCurrencyId(array(12, 34)); // WHERE currency_id IN (12, 34) + * $query->filterByCurrencyId(array('min' => 12)); // WHERE currency_id > 12 + * + * + * @see filterByCurrency() + * + * @param mixed $currencyId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCurrencyId($currencyId = null, $comparison = null) + { + if (is_array($currencyId)) { + $useMinMax = false; + if (isset($currencyId['min'])) { + $this->addUsingAlias(CartTableMap::CURRENCY_ID, $currencyId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($currencyId['max'])) { + $this->addUsingAlias(CartTableMap::CURRENCY_ID, $currencyId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::CURRENCY_ID, $currencyId, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(CartTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(CartTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(CartTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(CartTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CartTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Customer object + * + * @param \Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCustomer($customer, $comparison = null) + { + if ($customer instanceof \Thelia\Model\Customer) { + return $this + ->addUsingAlias(CartTableMap::CUSTOMER_ID, $customer->getId(), $comparison); + } elseif ($customer instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartTableMap::CUSTOMER_ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCustomer() only accepts arguments of type \Thelia\Model\Customer or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Customer relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function joinCustomer($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Customer'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Customer'); + } + + return $this; + } + + /** + * Use the Customer relation Customer object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CustomerQuery A secondary query class using the current class as primary query + */ + public function useCustomerQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCustomer($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Customer', '\Thelia\Model\CustomerQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Address object + * + * @param \Thelia\Model\Address|ObjectCollection $address The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByAddressRelatedByAddressDeliveryId($address, $comparison = null) + { + if ($address instanceof \Thelia\Model\Address) { + return $this + ->addUsingAlias(CartTableMap::ADDRESS_DELIVERY_ID, $address->getId(), $comparison); + } elseif ($address instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartTableMap::ADDRESS_DELIVERY_ID, $address->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByAddressRelatedByAddressDeliveryId() only accepts arguments of type \Thelia\Model\Address or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the AddressRelatedByAddressDeliveryId relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function joinAddressRelatedByAddressDeliveryId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('AddressRelatedByAddressDeliveryId'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'AddressRelatedByAddressDeliveryId'); + } + + return $this; + } + + /** + * Use the AddressRelatedByAddressDeliveryId relation Address object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\AddressQuery A secondary query class using the current class as primary query + */ + public function useAddressRelatedByAddressDeliveryIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinAddressRelatedByAddressDeliveryId($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'AddressRelatedByAddressDeliveryId', '\Thelia\Model\AddressQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Address object + * + * @param \Thelia\Model\Address|ObjectCollection $address The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByAddressRelatedByAddressInvoiceId($address, $comparison = null) + { + if ($address instanceof \Thelia\Model\Address) { + return $this + ->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $address->getId(), $comparison); + } elseif ($address instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $address->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByAddressRelatedByAddressInvoiceId() only accepts arguments of type \Thelia\Model\Address or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the AddressRelatedByAddressInvoiceId relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function joinAddressRelatedByAddressInvoiceId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('AddressRelatedByAddressInvoiceId'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'AddressRelatedByAddressInvoiceId'); + } + + return $this; + } + + /** + * Use the AddressRelatedByAddressInvoiceId relation Address object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\AddressQuery A secondary query class using the current class as primary query + */ + public function useAddressRelatedByAddressInvoiceIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinAddressRelatedByAddressInvoiceId($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'AddressRelatedByAddressInvoiceId', '\Thelia\Model\AddressQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Currency object + * + * @param \Thelia\Model\Currency|ObjectCollection $currency The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCurrency($currency, $comparison = null) + { + if ($currency instanceof \Thelia\Model\Currency) { + return $this + ->addUsingAlias(CartTableMap::CURRENCY_ID, $currency->getId(), $comparison); + } elseif ($currency instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CartTableMap::CURRENCY_ID, $currency->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCurrency() only accepts arguments of type \Thelia\Model\Currency or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Currency relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function joinCurrency($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Currency'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Currency'); + } + + return $this; + } + + /** + * Use the Currency relation Currency object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CurrencyQuery A secondary query class using the current class as primary query + */ + public function useCurrencyQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCurrency($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Currency', '\Thelia\Model\CurrencyQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\CartItem object + * + * @param \Thelia\Model\CartItem|ObjectCollection $cartItem the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function filterByCartItem($cartItem, $comparison = null) + { + if ($cartItem instanceof \Thelia\Model\CartItem) { + return $this + ->addUsingAlias(CartTableMap::ID, $cartItem->getCartId(), $comparison); + } elseif ($cartItem instanceof ObjectCollection) { + return $this + ->useCartItemQuery() + ->filterByPrimaryKeys($cartItem->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCartItem() only accepts arguments of type \Thelia\Model\CartItem or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CartItem relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function joinCartItem($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CartItem'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CartItem'); + } + + return $this; + } + + /** + * Use the CartItem relation CartItem object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartItemQuery A secondary query class using the current class as primary query + */ + public function useCartItemQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCartItem($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CartItem', '\Thelia\Model\CartItemQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCart $cart Object to remove from the list of results + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function prune($cart = null) + { + if ($cart) { + $this->addUsingAlias(CartTableMap::ID, $cart->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the cart table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + CartTableMap::clearInstancePool(); + CartTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildCart or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildCart object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CartTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + CartTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CartTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(CartTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(CartTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(CartTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(CartTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(CartTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildCartQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(CartTableMap::CREATED_AT); + } + +} // CartQuery diff --git a/core/lib/Thelia/Model/Base/Combination.php b/core/lib/Thelia/Model/Base/Combination.php index e7cd93da7..e5c42425a 100755 --- a/core/lib/Thelia/Model/Base/Combination.php +++ b/core/lib/Thelia/Model/Base/Combination.php @@ -19,6 +19,8 @@ use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\AttributeCombination as ChildAttributeCombination; use Thelia\Model\AttributeCombinationQuery as ChildAttributeCombinationQuery; +use Thelia\Model\CartItem as ChildCartItem; +use Thelia\Model\CartItemQuery as ChildCartItemQuery; use Thelia\Model\Combination as ChildCombination; use Thelia\Model\CombinationQuery as ChildCombinationQuery; use Thelia\Model\Stock as ChildStock; @@ -95,6 +97,12 @@ abstract class Combination implements ActiveRecordInterface protected $collStocks; protected $collStocksPartial; + /** + * @var ObjectCollection|ChildCartItem[] Collection to store aggregation of ChildCartItem objects. + */ + protected $collCartItems; + protected $collCartItemsPartial; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -115,6 +123,12 @@ abstract class Combination implements ActiveRecordInterface */ protected $stocksScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartItemsScheduledForDeletion = null; + /** * Initializes internal state of Thelia\Model\Base\Combination object. */ @@ -642,6 +656,8 @@ abstract class Combination implements ActiveRecordInterface $this->collStocks = null; + $this->collCartItems = null; + } // if (deep) } @@ -810,6 +826,24 @@ abstract class Combination implements ActiveRecordInterface } } + if ($this->cartItemsScheduledForDeletion !== null) { + if (!$this->cartItemsScheduledForDeletion->isEmpty()) { + foreach ($this->cartItemsScheduledForDeletion as $cartItem) { + // need to save related object because we set the relation to null + $cartItem->save($con); + } + $this->cartItemsScheduledForDeletion = null; + } + } + + if ($this->collCartItems !== null) { + foreach ($this->collCartItems as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + $this->alreadyInSave = false; } @@ -992,6 +1026,9 @@ abstract class Combination implements ActiveRecordInterface if (null !== $this->collStocks) { $result['Stocks'] = $this->collStocks->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCartItems) { + $result['CartItems'] = $this->collCartItems->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } } return $result; @@ -1165,6 +1202,12 @@ abstract class Combination implements ActiveRecordInterface } } + foreach ($this->getCartItems() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCartItem($relObj->copy($deepCopy)); + } + } + } // if ($deepCopy) if ($makeNew) { @@ -1212,6 +1255,9 @@ abstract class Combination implements ActiveRecordInterface if ('Stock' == $relationName) { return $this->initStocks(); } + if ('CartItem' == $relationName) { + return $this->initCartItems(); + } } /** @@ -1728,6 +1774,274 @@ abstract class Combination implements ActiveRecordInterface return $this->getStocks($query, $con); } + /** + * Clears out the collCartItems collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCartItems() + */ + public function clearCartItems() + { + $this->collCartItems = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCartItems collection loaded partially. + */ + public function resetPartialCartItems($v = true) + { + $this->collCartItemsPartial = $v; + } + + /** + * Initializes the collCartItems collection. + * + * By default this just sets the collCartItems collection to an empty array (like clearcollCartItems()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCartItems($overrideExisting = true) + { + if (null !== $this->collCartItems && !$overrideExisting) { + return; + } + $this->collCartItems = new ObjectCollection(); + $this->collCartItems->setModel('\Thelia\Model\CartItem'); + } + + /** + * Gets an array of ChildCartItem objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCombination is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCartItem[] List of ChildCartItem objects + * @throws PropelException + */ + public function getCartItems($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + // return empty collection + $this->initCartItems(); + } else { + $collCartItems = ChildCartItemQuery::create(null, $criteria) + ->filterByCombination($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartItemsPartial && count($collCartItems)) { + $this->initCartItems(false); + + foreach ($collCartItems as $obj) { + if (false == $this->collCartItems->contains($obj)) { + $this->collCartItems->append($obj); + } + } + + $this->collCartItemsPartial = true; + } + + $collCartItems->getInternalIterator()->rewind(); + + return $collCartItems; + } + + if ($partial && $this->collCartItems) { + foreach ($this->collCartItems as $obj) { + if ($obj->isNew()) { + $collCartItems[] = $obj; + } + } + } + + $this->collCartItems = $collCartItems; + $this->collCartItemsPartial = false; + } + } + + return $this->collCartItems; + } + + /** + * Sets a collection of CartItem objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $cartItems A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCombination The current object (for fluent API support) + */ + public function setCartItems(Collection $cartItems, ConnectionInterface $con = null) + { + $cartItemsToDelete = $this->getCartItems(new Criteria(), $con)->diff($cartItems); + + + $this->cartItemsScheduledForDeletion = $cartItemsToDelete; + + foreach ($cartItemsToDelete as $cartItemRemoved) { + $cartItemRemoved->setCombination(null); + } + + $this->collCartItems = null; + foreach ($cartItems as $cartItem) { + $this->addCartItem($cartItem); + } + + $this->collCartItems = $cartItems; + $this->collCartItemsPartial = false; + + return $this; + } + + /** + * Returns the number of related CartItem objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CartItem objects. + * @throws PropelException + */ + public function countCartItems(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCartItems()); + } + + $query = ChildCartItemQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCombination($this) + ->count($con); + } + + return count($this->collCartItems); + } + + /** + * Method called to associate a ChildCartItem object to this object + * through the ChildCartItem foreign key attribute. + * + * @param ChildCartItem $l ChildCartItem + * @return \Thelia\Model\Combination The current object (for fluent API support) + */ + public function addCartItem(ChildCartItem $l) + { + if ($this->collCartItems === null) { + $this->initCartItems(); + $this->collCartItemsPartial = true; + } + + if (!in_array($l, $this->collCartItems->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCartItem($l); + } + + return $this; + } + + /** + * @param CartItem $cartItem The cartItem object to add. + */ + protected function doAddCartItem($cartItem) + { + $this->collCartItems[]= $cartItem; + $cartItem->setCombination($this); + } + + /** + * @param CartItem $cartItem The cartItem object to remove. + * @return ChildCombination The current object (for fluent API support) + */ + public function removeCartItem($cartItem) + { + if ($this->getCartItems()->contains($cartItem)) { + $this->collCartItems->remove($this->collCartItems->search($cartItem)); + if (null === $this->cartItemsScheduledForDeletion) { + $this->cartItemsScheduledForDeletion = clone $this->collCartItems; + $this->cartItemsScheduledForDeletion->clear(); + } + $this->cartItemsScheduledForDeletion[]= $cartItem; + $cartItem->setCombination(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Combination is new, it will return + * an empty collection; or if this Combination has previously + * been saved, it will retrieve related CartItems 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 Combination. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinCart($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Cart', $joinBehavior); + + return $this->getCartItems($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Combination is new, it will return + * an empty collection; or if this Combination has previously + * been saved, it will retrieve related CartItems 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 Combination. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinProduct($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Product', $joinBehavior); + + return $this->getCartItems($query, $con); + } + /** * Clears the current object and sets all attributes to their default values */ @@ -1766,6 +2080,11 @@ abstract class Combination implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCartItems) { + foreach ($this->collCartItems as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) if ($this->collAttributeCombinations instanceof Collection) { @@ -1776,6 +2095,10 @@ abstract class Combination implements ActiveRecordInterface $this->collStocks->clearIterator(); } $this->collStocks = null; + if ($this->collCartItems instanceof Collection) { + $this->collCartItems->clearIterator(); + } + $this->collCartItems = null; } /** diff --git a/core/lib/Thelia/Model/Base/CombinationQuery.php b/core/lib/Thelia/Model/Base/CombinationQuery.php index 7424f03f6..d14358739 100755 --- a/core/lib/Thelia/Model/Base/CombinationQuery.php +++ b/core/lib/Thelia/Model/Base/CombinationQuery.php @@ -43,6 +43,10 @@ use Thelia\Model\Map\CombinationTableMap; * @method ChildCombinationQuery rightJoinStock($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Stock relation * @method ChildCombinationQuery innerJoinStock($relationAlias = null) Adds a INNER JOIN clause to the query using the Stock relation * + * @method ChildCombinationQuery leftJoinCartItem($relationAlias = null) Adds a LEFT JOIN clause to the query using the CartItem relation + * @method ChildCombinationQuery rightJoinCartItem($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CartItem relation + * @method ChildCombinationQuery innerJoinCartItem($relationAlias = null) Adds a INNER JOIN clause to the query using the CartItem relation + * * @method ChildCombination findOne(ConnectionInterface $con = null) Return the first ChildCombination matching the query * @method ChildCombination findOneOrCreate(ConnectionInterface $con = null) Return the first ChildCombination matching the query, or a new ChildCombination object populated from the query conditions when no match is found * @@ -534,6 +538,79 @@ abstract class CombinationQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'Stock', '\Thelia\Model\StockQuery'); } + /** + * Filter the query by a related \Thelia\Model\CartItem object + * + * @param \Thelia\Model\CartItem|ObjectCollection $cartItem the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCombinationQuery The current query, for fluid interface + */ + public function filterByCartItem($cartItem, $comparison = null) + { + if ($cartItem instanceof \Thelia\Model\CartItem) { + return $this + ->addUsingAlias(CombinationTableMap::ID, $cartItem->getCombinationId(), $comparison); + } elseif ($cartItem instanceof ObjectCollection) { + return $this + ->useCartItemQuery() + ->filterByPrimaryKeys($cartItem->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCartItem() only accepts arguments of type \Thelia\Model\CartItem or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CartItem relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCombinationQuery The current query, for fluid interface + */ + public function joinCartItem($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CartItem'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CartItem'); + } + + return $this; + } + + /** + * Use the CartItem relation CartItem object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartItemQuery A secondary query class using the current class as primary query + */ + public function useCartItemQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCartItem($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CartItem', '\Thelia\Model\CartItemQuery'); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Currency.php b/core/lib/Thelia/Model/Base/Currency.php index 5edf0b8e1..077fd972c 100755 --- a/core/lib/Thelia/Model/Base/Currency.php +++ b/core/lib/Thelia/Model/Base/Currency.php @@ -17,6 +17,8 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; +use Thelia\Model\Cart as ChildCart; +use Thelia\Model\CartQuery as ChildCartQuery; use Thelia\Model\Currency as ChildCurrency; use Thelia\Model\CurrencyQuery as ChildCurrencyQuery; use Thelia\Model\Order as ChildOrder; @@ -111,6 +113,12 @@ abstract class Currency implements ActiveRecordInterface protected $collOrders; protected $collOrdersPartial; + /** + * @var ObjectCollection|ChildCart[] Collection to store aggregation of ChildCart objects. + */ + protected $collCarts; + protected $collCartsPartial; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -125,6 +133,12 @@ abstract class Currency implements ActiveRecordInterface */ protected $ordersScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartsScheduledForDeletion = null; + /** * Initializes internal state of Thelia\Model\Base\Currency object. */ @@ -790,6 +804,8 @@ abstract class Currency implements ActiveRecordInterface $this->collOrders = null; + $this->collCarts = null; + } // if (deep) } @@ -941,6 +957,24 @@ abstract class Currency implements ActiveRecordInterface } } + if ($this->cartsScheduledForDeletion !== null) { + if (!$this->cartsScheduledForDeletion->isEmpty()) { + foreach ($this->cartsScheduledForDeletion as $cart) { + // need to save related object because we set the relation to null + $cart->save($con); + } + $this->cartsScheduledForDeletion = null; + } + } + + if ($this->collCarts !== null) { + foreach ($this->collCarts as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + $this->alreadyInSave = false; } @@ -1160,6 +1194,9 @@ abstract class Currency implements ActiveRecordInterface if (null !== $this->collOrders) { $result['Orders'] = $this->collOrders->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCarts) { + $result['Carts'] = $this->collCarts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } } return $result; @@ -1351,6 +1388,12 @@ abstract class Currency implements ActiveRecordInterface } } + foreach ($this->getCarts() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCart($relObj->copy($deepCopy)); + } + } + } // if ($deepCopy) if ($makeNew) { @@ -1395,6 +1438,9 @@ abstract class Currency implements ActiveRecordInterface if ('Order' == $relationName) { return $this->initOrders(); } + if ('Cart' == $relationName) { + return $this->initCarts(); + } } /** @@ -1715,6 +1761,299 @@ abstract class Currency implements ActiveRecordInterface return $this->getOrders($query, $con); } + /** + * Clears out the collCarts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCarts() + */ + public function clearCarts() + { + $this->collCarts = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCarts collection loaded partially. + */ + public function resetPartialCarts($v = true) + { + $this->collCartsPartial = $v; + } + + /** + * Initializes the collCarts collection. + * + * By default this just sets the collCarts collection to an empty array (like clearcollCarts()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCarts($overrideExisting = true) + { + if (null !== $this->collCarts && !$overrideExisting) { + return; + } + $this->collCarts = new ObjectCollection(); + $this->collCarts->setModel('\Thelia\Model\Cart'); + } + + /** + * Gets an array of ChildCart objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCurrency is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCart[] List of ChildCart objects + * @throws PropelException + */ + public function getCarts($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartsPartial && !$this->isNew(); + if (null === $this->collCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCarts) { + // return empty collection + $this->initCarts(); + } else { + $collCarts = ChildCartQuery::create(null, $criteria) + ->filterByCurrency($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartsPartial && count($collCarts)) { + $this->initCarts(false); + + foreach ($collCarts as $obj) { + if (false == $this->collCarts->contains($obj)) { + $this->collCarts->append($obj); + } + } + + $this->collCartsPartial = true; + } + + $collCarts->getInternalIterator()->rewind(); + + return $collCarts; + } + + if ($partial && $this->collCarts) { + foreach ($this->collCarts as $obj) { + if ($obj->isNew()) { + $collCarts[] = $obj; + } + } + } + + $this->collCarts = $collCarts; + $this->collCartsPartial = false; + } + } + + return $this->collCarts; + } + + /** + * Sets a collection of Cart objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $carts A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCurrency The current object (for fluent API support) + */ + public function setCarts(Collection $carts, ConnectionInterface $con = null) + { + $cartsToDelete = $this->getCarts(new Criteria(), $con)->diff($carts); + + + $this->cartsScheduledForDeletion = $cartsToDelete; + + foreach ($cartsToDelete as $cartRemoved) { + $cartRemoved->setCurrency(null); + } + + $this->collCarts = null; + foreach ($carts as $cart) { + $this->addCart($cart); + } + + $this->collCarts = $carts; + $this->collCartsPartial = false; + + return $this; + } + + /** + * Returns the number of related Cart objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Cart objects. + * @throws PropelException + */ + public function countCarts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartsPartial && !$this->isNew(); + if (null === $this->collCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCarts) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCarts()); + } + + $query = ChildCartQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCurrency($this) + ->count($con); + } + + return count($this->collCarts); + } + + /** + * Method called to associate a ChildCart object to this object + * through the ChildCart foreign key attribute. + * + * @param ChildCart $l ChildCart + * @return \Thelia\Model\Currency The current object (for fluent API support) + */ + public function addCart(ChildCart $l) + { + if ($this->collCarts === null) { + $this->initCarts(); + $this->collCartsPartial = true; + } + + if (!in_array($l, $this->collCarts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCart($l); + } + + return $this; + } + + /** + * @param Cart $cart The cart object to add. + */ + protected function doAddCart($cart) + { + $this->collCarts[]= $cart; + $cart->setCurrency($this); + } + + /** + * @param Cart $cart The cart object to remove. + * @return ChildCurrency The current object (for fluent API support) + */ + public function removeCart($cart) + { + if ($this->getCarts()->contains($cart)) { + $this->collCarts->remove($this->collCarts->search($cart)); + if (null === $this->cartsScheduledForDeletion) { + $this->cartsScheduledForDeletion = clone $this->collCarts; + $this->cartsScheduledForDeletion->clear(); + } + $this->cartsScheduledForDeletion[]= $cart; + $cart->setCurrency(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Currency is new, it will return + * an empty collection; or if this Currency has previously + * been saved, it will retrieve related Carts 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 Currency. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinCustomer($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Customer', $joinBehavior); + + return $this->getCarts($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Currency is new, it will return + * an empty collection; or if this Currency has previously + * been saved, it will retrieve related Carts 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 Currency. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinAddressRelatedByAddressDeliveryId($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('AddressRelatedByAddressDeliveryId', $joinBehavior); + + return $this->getCarts($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Currency is new, it will return + * an empty collection; or if this Currency has previously + * been saved, it will retrieve related Carts 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 Currency. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinAddressRelatedByAddressInvoiceId($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('AddressRelatedByAddressInvoiceId', $joinBehavior); + + return $this->getCarts($query, $con); + } + /** * Clears the current object and sets all attributes to their default values */ @@ -1752,12 +2091,21 @@ abstract class Currency implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCarts) { + foreach ($this->collCarts as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) if ($this->collOrders instanceof Collection) { $this->collOrders->clearIterator(); } $this->collOrders = null; + if ($this->collCarts instanceof Collection) { + $this->collCarts->clearIterator(); + } + $this->collCarts = null; } /** diff --git a/core/lib/Thelia/Model/Base/CurrencyQuery.php b/core/lib/Thelia/Model/Base/CurrencyQuery.php index 6bc45c3d7..79c0dc7a1 100755 --- a/core/lib/Thelia/Model/Base/CurrencyQuery.php +++ b/core/lib/Thelia/Model/Base/CurrencyQuery.php @@ -47,6 +47,10 @@ use Thelia\Model\Map\CurrencyTableMap; * @method ChildCurrencyQuery rightJoinOrder($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Order relation * @method ChildCurrencyQuery innerJoinOrder($relationAlias = null) Adds a INNER JOIN clause to the query using the Order relation * + * @method ChildCurrencyQuery leftJoinCart($relationAlias = null) Adds a LEFT JOIN clause to the query using the Cart relation + * @method ChildCurrencyQuery rightJoinCart($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Cart relation + * @method ChildCurrencyQuery innerJoinCart($relationAlias = null) Adds a INNER JOIN clause to the query using the Cart relation + * * @method ChildCurrency findOne(ConnectionInterface $con = null) Return the first ChildCurrency matching the query * @method ChildCurrency findOneOrCreate(ConnectionInterface $con = null) Return the first ChildCurrency matching the query, or a new ChildCurrency object populated from the query conditions when no match is found * @@ -613,6 +617,79 @@ abstract class CurrencyQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'Order', '\Thelia\Model\OrderQuery'); } + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCurrencyQuery The current query, for fluid interface + */ + public function filterByCart($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(CurrencyTableMap::ID, $cart->getCurrencyId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + return $this + ->useCartQuery() + ->filterByPrimaryKeys($cart->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCart() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Cart relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCurrencyQuery The current query, for fluid interface + */ + public function joinCart($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Cart'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Cart'); + } + + return $this; + } + + /** + * Use the Cart relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCart($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Cart', '\Thelia\Model\CartQuery'); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Customer.php b/core/lib/Thelia/Model/Base/Customer.php index 71708ab1b..295d56920 100755 --- a/core/lib/Thelia/Model/Base/Customer.php +++ b/core/lib/Thelia/Model/Base/Customer.php @@ -19,6 +19,8 @@ use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\Address as ChildAddress; use Thelia\Model\AddressQuery as ChildAddressQuery; +use Thelia\Model\Cart as ChildCart; +use Thelia\Model\CartQuery as ChildCartQuery; use Thelia\Model\Customer as ChildCustomer; use Thelia\Model\CustomerQuery as ChildCustomerQuery; use Thelia\Model\CustomerTitle as ChildCustomerTitle; @@ -162,6 +164,12 @@ abstract class Customer implements ActiveRecordInterface protected $collOrders; protected $collOrdersPartial; + /** + * @var ObjectCollection|ChildCart[] Collection to store aggregation of ChildCart objects. + */ + protected $collCarts; + protected $collCartsPartial; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -182,6 +190,12 @@ abstract class Customer implements ActiveRecordInterface */ protected $ordersScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartsScheduledForDeletion = null; + /** * Initializes internal state of Thelia\Model\Base\Customer object. */ @@ -1067,6 +1081,8 @@ abstract class Customer implements ActiveRecordInterface $this->collOrders = null; + $this->collCarts = null; + } // if (deep) } @@ -1246,6 +1262,24 @@ abstract class Customer implements ActiveRecordInterface } } + if ($this->cartsScheduledForDeletion !== null) { + if (!$this->cartsScheduledForDeletion->isEmpty()) { + foreach ($this->cartsScheduledForDeletion as $cart) { + // need to save related object because we set the relation to null + $cart->save($con); + } + $this->cartsScheduledForDeletion = null; + } + } + + if ($this->collCarts !== null) { + foreach ($this->collCarts as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + $this->alreadyInSave = false; } @@ -1531,6 +1565,9 @@ abstract class Customer implements ActiveRecordInterface if (null !== $this->collOrders) { $result['Orders'] = $this->collOrders->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCarts) { + $result['Carts'] = $this->collCarts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } } return $result; @@ -1764,6 +1801,12 @@ abstract class Customer implements ActiveRecordInterface } } + foreach ($this->getCarts() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCart($relObj->copy($deepCopy)); + } + } + } // if ($deepCopy) if ($makeNew) { @@ -1862,6 +1905,9 @@ abstract class Customer implements ActiveRecordInterface if ('Order' == $relationName) { return $this->initOrders(); } + if ('Cart' == $relationName) { + return $this->initCarts(); + } } /** @@ -2425,6 +2471,299 @@ abstract class Customer implements ActiveRecordInterface return $this->getOrders($query, $con); } + /** + * Clears out the collCarts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCarts() + */ + public function clearCarts() + { + $this->collCarts = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCarts collection loaded partially. + */ + public function resetPartialCarts($v = true) + { + $this->collCartsPartial = $v; + } + + /** + * Initializes the collCarts collection. + * + * By default this just sets the collCarts collection to an empty array (like clearcollCarts()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCarts($overrideExisting = true) + { + if (null !== $this->collCarts && !$overrideExisting) { + return; + } + $this->collCarts = new ObjectCollection(); + $this->collCarts->setModel('\Thelia\Model\Cart'); + } + + /** + * Gets an array of ChildCart objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCustomer is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCart[] List of ChildCart objects + * @throws PropelException + */ + public function getCarts($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartsPartial && !$this->isNew(); + if (null === $this->collCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCarts) { + // return empty collection + $this->initCarts(); + } else { + $collCarts = ChildCartQuery::create(null, $criteria) + ->filterByCustomer($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartsPartial && count($collCarts)) { + $this->initCarts(false); + + foreach ($collCarts as $obj) { + if (false == $this->collCarts->contains($obj)) { + $this->collCarts->append($obj); + } + } + + $this->collCartsPartial = true; + } + + $collCarts->getInternalIterator()->rewind(); + + return $collCarts; + } + + if ($partial && $this->collCarts) { + foreach ($this->collCarts as $obj) { + if ($obj->isNew()) { + $collCarts[] = $obj; + } + } + } + + $this->collCarts = $collCarts; + $this->collCartsPartial = false; + } + } + + return $this->collCarts; + } + + /** + * Sets a collection of Cart objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $carts A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCustomer The current object (for fluent API support) + */ + public function setCarts(Collection $carts, ConnectionInterface $con = null) + { + $cartsToDelete = $this->getCarts(new Criteria(), $con)->diff($carts); + + + $this->cartsScheduledForDeletion = $cartsToDelete; + + foreach ($cartsToDelete as $cartRemoved) { + $cartRemoved->setCustomer(null); + } + + $this->collCarts = null; + foreach ($carts as $cart) { + $this->addCart($cart); + } + + $this->collCarts = $carts; + $this->collCartsPartial = false; + + return $this; + } + + /** + * Returns the number of related Cart objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Cart objects. + * @throws PropelException + */ + public function countCarts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartsPartial && !$this->isNew(); + if (null === $this->collCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCarts) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCarts()); + } + + $query = ChildCartQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCustomer($this) + ->count($con); + } + + return count($this->collCarts); + } + + /** + * Method called to associate a ChildCart object to this object + * through the ChildCart foreign key attribute. + * + * @param ChildCart $l ChildCart + * @return \Thelia\Model\Customer The current object (for fluent API support) + */ + public function addCart(ChildCart $l) + { + if ($this->collCarts === null) { + $this->initCarts(); + $this->collCartsPartial = true; + } + + if (!in_array($l, $this->collCarts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCart($l); + } + + return $this; + } + + /** + * @param Cart $cart The cart object to add. + */ + protected function doAddCart($cart) + { + $this->collCarts[]= $cart; + $cart->setCustomer($this); + } + + /** + * @param Cart $cart The cart object to remove. + * @return ChildCustomer The current object (for fluent API support) + */ + public function removeCart($cart) + { + if ($this->getCarts()->contains($cart)) { + $this->collCarts->remove($this->collCarts->search($cart)); + if (null === $this->cartsScheduledForDeletion) { + $this->cartsScheduledForDeletion = clone $this->collCarts; + $this->cartsScheduledForDeletion->clear(); + } + $this->cartsScheduledForDeletion[]= $cart; + $cart->setCustomer(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Customer is new, it will return + * an empty collection; or if this Customer has previously + * been saved, it will retrieve related Carts 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 Customer. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinAddressRelatedByAddressDeliveryId($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('AddressRelatedByAddressDeliveryId', $joinBehavior); + + return $this->getCarts($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Customer is new, it will return + * an empty collection; or if this Customer has previously + * been saved, it will retrieve related Carts 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 Customer. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinAddressRelatedByAddressInvoiceId($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('AddressRelatedByAddressInvoiceId', $joinBehavior); + + return $this->getCarts($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Customer is new, it will return + * an empty collection; or if this Customer has previously + * been saved, it will retrieve related Carts 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 Customer. + * + * @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|ChildCart[] List of ChildCart objects + */ + public function getCartsJoinCurrency($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartQuery::create(null, $criteria); + $query->joinWith('Currency', $joinBehavior); + + return $this->getCarts($query, $con); + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2473,6 +2812,11 @@ abstract class Customer implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCarts) { + foreach ($this->collCarts as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) if ($this->collAddresses instanceof Collection) { @@ -2483,6 +2827,10 @@ abstract class Customer implements ActiveRecordInterface $this->collOrders->clearIterator(); } $this->collOrders = null; + if ($this->collCarts instanceof Collection) { + $this->collCarts->clearIterator(); + } + $this->collCarts = null; $this->aCustomerTitle = null; } diff --git a/core/lib/Thelia/Model/Base/CustomerQuery.php b/core/lib/Thelia/Model/Base/CustomerQuery.php index 16fa65016..f02e76c24 100755 --- a/core/lib/Thelia/Model/Base/CustomerQuery.php +++ b/core/lib/Thelia/Model/Base/CustomerQuery.php @@ -67,6 +67,10 @@ use Thelia\Model\Map\CustomerTableMap; * @method ChildCustomerQuery rightJoinOrder($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Order relation * @method ChildCustomerQuery innerJoinOrder($relationAlias = null) Adds a INNER JOIN clause to the query using the Order relation * + * @method ChildCustomerQuery leftJoinCart($relationAlias = null) Adds a LEFT JOIN clause to the query using the Cart relation + * @method ChildCustomerQuery rightJoinCart($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Cart relation + * @method ChildCustomerQuery innerJoinCart($relationAlias = null) Adds a INNER JOIN clause to the query using the Cart relation + * * @method ChildCustomer findOne(ConnectionInterface $con = null) Return the first ChildCustomer matching the query * @method ChildCustomer findOneOrCreate(ConnectionInterface $con = null) Return the first ChildCustomer matching the query, or a new ChildCustomer object populated from the query conditions when no match is found * @@ -793,7 +797,7 @@ abstract class CustomerQuery extends ModelCriteria * * @return ChildCustomerQuery The current query, for fluid interface */ - public function joinCustomerTitle($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinCustomerTitle($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('CustomerTitle'); @@ -828,7 +832,7 @@ abstract class CustomerQuery extends ModelCriteria * * @return \Thelia\Model\CustomerTitleQuery A secondary query class using the current class as primary query */ - public function useCustomerTitleQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useCustomerTitleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinCustomerTitle($relationAlias, $joinType) @@ -981,6 +985,79 @@ abstract class CustomerQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'Order', '\Thelia\Model\OrderQuery'); } + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCustomerQuery The current query, for fluid interface + */ + public function filterByCart($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(CustomerTableMap::ID, $cart->getCustomerId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + return $this + ->useCartQuery() + ->filterByPrimaryKeys($cart->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCart() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Cart relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCustomerQuery The current query, for fluid interface + */ + public function joinCart($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Cart'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Cart'); + } + + return $this; + } + + /** + * Use the Cart relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCart($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Cart', '\Thelia\Model\CartQuery'); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/CustomerTitle.php b/core/lib/Thelia/Model/Base/CustomerTitle.php index d126839d0..5d34c95e5 100755 --- a/core/lib/Thelia/Model/Base/CustomerTitle.php +++ b/core/lib/Thelia/Model/Base/CustomerTitle.php @@ -866,10 +866,9 @@ abstract class CustomerTitle implements ActiveRecordInterface if ($this->customersScheduledForDeletion !== null) { if (!$this->customersScheduledForDeletion->isEmpty()) { - foreach ($this->customersScheduledForDeletion as $customer) { - // need to save related object because we set the relation to null - $customer->save($con); - } + \Thelia\Model\CustomerQuery::create() + ->filterByPrimaryKeys($this->customersScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); $this->customersScheduledForDeletion = null; } } @@ -1560,7 +1559,7 @@ abstract class CustomerTitle implements ActiveRecordInterface $this->customersScheduledForDeletion = clone $this->collCustomers; $this->customersScheduledForDeletion->clear(); } - $this->customersScheduledForDeletion[]= $customer; + $this->customersScheduledForDeletion[]= clone $customer; $customer->setCustomerTitle(null); } diff --git a/core/lib/Thelia/Model/Base/CustomerTitleQuery.php b/core/lib/Thelia/Model/Base/CustomerTitleQuery.php index 42ba4bd98..f3c372248 100755 --- a/core/lib/Thelia/Model/Base/CustomerTitleQuery.php +++ b/core/lib/Thelia/Model/Base/CustomerTitleQuery.php @@ -469,7 +469,7 @@ abstract class CustomerTitleQuery extends ModelCriteria * * @return ChildCustomerTitleQuery The current query, for fluid interface */ - public function joinCustomer($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinCustomer($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('Customer'); @@ -504,7 +504,7 @@ abstract class CustomerTitleQuery extends ModelCriteria * * @return \Thelia\Model\CustomerQuery A secondary query class using the current class as primary query */ - public function useCustomerQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useCustomerQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinCustomer($relationAlias, $joinType) diff --git a/core/lib/Thelia/Model/Base/Product.php b/core/lib/Thelia/Model/Base/Product.php index a2a918107..96b3f45f0 100755 --- a/core/lib/Thelia/Model/Base/Product.php +++ b/core/lib/Thelia/Model/Base/Product.php @@ -19,6 +19,8 @@ use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\Accessory as ChildAccessory; use Thelia\Model\AccessoryQuery as ChildAccessoryQuery; +use Thelia\Model\CartItem as ChildCartItem; +use Thelia\Model\CartItemQuery as ChildCartItemQuery; use Thelia\Model\Category as ChildCategory; use Thelia\Model\CategoryQuery as ChildCategoryQuery; use Thelia\Model\ContentAssoc as ChildContentAssoc; @@ -246,6 +248,12 @@ abstract class Product implements ActiveRecordInterface protected $collRewritings; protected $collRewritingsPartial; + /** + * @var ObjectCollection|ChildCartItem[] Collection to store aggregation of ChildCartItem objects. + */ + protected $collCartItems; + protected $collCartItemsPartial; + /** * @var ObjectCollection|ChildProductI18n[] Collection to store aggregation of ChildProductI18n objects. */ @@ -375,6 +383,12 @@ abstract class Product implements ActiveRecordInterface */ protected $rewritingsScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $cartItemsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -1440,6 +1454,8 @@ abstract class Product implements ActiveRecordInterface $this->collRewritings = null; + $this->collCartItems = null; + $this->collProductI18ns = null; $this->collProductVersions = null; @@ -1838,6 +1854,23 @@ abstract class Product implements ActiveRecordInterface } } + if ($this->cartItemsScheduledForDeletion !== null) { + if (!$this->cartItemsScheduledForDeletion->isEmpty()) { + \Thelia\Model\CartItemQuery::create() + ->filterByPrimaryKeys($this->cartItemsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->cartItemsScheduledForDeletion = null; + } + } + + if ($this->collCartItems !== null) { + foreach ($this->collCartItems as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + if ($this->productI18nsScheduledForDeletion !== null) { if (!$this->productI18nsScheduledForDeletion->isEmpty()) { \Thelia\Model\ProductI18nQuery::create() @@ -2208,6 +2241,9 @@ abstract class Product implements ActiveRecordInterface if (null !== $this->collRewritings) { $result['Rewritings'] = $this->collRewritings->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCartItems) { + $result['CartItems'] = $this->collCartItems->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } if (null !== $this->collProductI18ns) { $result['ProductI18ns'] = $this->collProductI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -2507,6 +2543,12 @@ abstract class Product implements ActiveRecordInterface } } + foreach ($this->getCartItems() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCartItem($relObj->copy($deepCopy)); + } + } + foreach ($this->getProductI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addProductI18n($relObj->copy($deepCopy)); @@ -2638,6 +2680,9 @@ abstract class Product implements ActiveRecordInterface if ('Rewriting' == $relationName) { return $this->initRewritings(); } + if ('CartItem' == $relationName) { + return $this->initCartItems(); + } if ('ProductI18n' == $relationName) { return $this->initProductI18ns(); } @@ -4986,6 +5031,274 @@ abstract class Product implements ActiveRecordInterface return $this->getRewritings($query, $con); } + /** + * Clears out the collCartItems collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCartItems() + */ + public function clearCartItems() + { + $this->collCartItems = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCartItems collection loaded partially. + */ + public function resetPartialCartItems($v = true) + { + $this->collCartItemsPartial = $v; + } + + /** + * Initializes the collCartItems collection. + * + * By default this just sets the collCartItems collection to an empty array (like clearcollCartItems()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCartItems($overrideExisting = true) + { + if (null !== $this->collCartItems && !$overrideExisting) { + return; + } + $this->collCartItems = new ObjectCollection(); + $this->collCartItems->setModel('\Thelia\Model\CartItem'); + } + + /** + * Gets an array of ChildCartItem objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildProduct is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildCartItem[] List of ChildCartItem objects + * @throws PropelException + */ + public function getCartItems($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + // return empty collection + $this->initCartItems(); + } else { + $collCartItems = ChildCartItemQuery::create(null, $criteria) + ->filterByProduct($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCartItemsPartial && count($collCartItems)) { + $this->initCartItems(false); + + foreach ($collCartItems as $obj) { + if (false == $this->collCartItems->contains($obj)) { + $this->collCartItems->append($obj); + } + } + + $this->collCartItemsPartial = true; + } + + $collCartItems->getInternalIterator()->rewind(); + + return $collCartItems; + } + + if ($partial && $this->collCartItems) { + foreach ($this->collCartItems as $obj) { + if ($obj->isNew()) { + $collCartItems[] = $obj; + } + } + } + + $this->collCartItems = $collCartItems; + $this->collCartItemsPartial = false; + } + } + + return $this->collCartItems; + } + + /** + * Sets a collection of CartItem objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $cartItems A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildProduct The current object (for fluent API support) + */ + public function setCartItems(Collection $cartItems, ConnectionInterface $con = null) + { + $cartItemsToDelete = $this->getCartItems(new Criteria(), $con)->diff($cartItems); + + + $this->cartItemsScheduledForDeletion = $cartItemsToDelete; + + foreach ($cartItemsToDelete as $cartItemRemoved) { + $cartItemRemoved->setProduct(null); + } + + $this->collCartItems = null; + foreach ($cartItems as $cartItem) { + $this->addCartItem($cartItem); + } + + $this->collCartItems = $cartItems; + $this->collCartItemsPartial = false; + + return $this; + } + + /** + * Returns the number of related CartItem objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CartItem objects. + * @throws PropelException + */ + public function countCartItems(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCartItemsPartial && !$this->isNew(); + if (null === $this->collCartItems || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCartItems) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCartItems()); + } + + $query = ChildCartItemQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByProduct($this) + ->count($con); + } + + return count($this->collCartItems); + } + + /** + * Method called to associate a ChildCartItem object to this object + * through the ChildCartItem foreign key attribute. + * + * @param ChildCartItem $l ChildCartItem + * @return \Thelia\Model\Product The current object (for fluent API support) + */ + public function addCartItem(ChildCartItem $l) + { + if ($this->collCartItems === null) { + $this->initCartItems(); + $this->collCartItemsPartial = true; + } + + if (!in_array($l, $this->collCartItems->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCartItem($l); + } + + return $this; + } + + /** + * @param CartItem $cartItem The cartItem object to add. + */ + protected function doAddCartItem($cartItem) + { + $this->collCartItems[]= $cartItem; + $cartItem->setProduct($this); + } + + /** + * @param CartItem $cartItem The cartItem object to remove. + * @return ChildProduct The current object (for fluent API support) + */ + public function removeCartItem($cartItem) + { + if ($this->getCartItems()->contains($cartItem)) { + $this->collCartItems->remove($this->collCartItems->search($cartItem)); + if (null === $this->cartItemsScheduledForDeletion) { + $this->cartItemsScheduledForDeletion = clone $this->collCartItems; + $this->cartItemsScheduledForDeletion->clear(); + } + $this->cartItemsScheduledForDeletion[]= clone $cartItem; + $cartItem->setProduct(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Product is new, it will return + * an empty collection; or if this Product has previously + * been saved, it will retrieve related CartItems 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 Product. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinCart($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Cart', $joinBehavior); + + return $this->getCartItems($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Product is new, it will return + * an empty collection; or if this Product has previously + * been saved, it will retrieve related CartItems 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 Product. + * + * @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|ChildCartItem[] List of ChildCartItem objects + */ + public function getCartItemsJoinCombination($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCartItemQuery::create(null, $criteria); + $query->joinWith('Combination', $joinBehavior); + + return $this->getCartItems($query, $con); + } + /** * Clears out the collProductI18ns collection * @@ -6068,6 +6381,11 @@ abstract class Product implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCartItems) { + foreach ($this->collCartItems as $o) { + $o->clearAllReferences($deep); + } + } if ($this->collProductI18ns) { foreach ($this->collProductI18ns as $o) { $o->clearAllReferences($deep); @@ -6135,6 +6453,10 @@ abstract class Product implements ActiveRecordInterface $this->collRewritings->clearIterator(); } $this->collRewritings = null; + if ($this->collCartItems instanceof Collection) { + $this->collCartItems->clearIterator(); + } + $this->collCartItems = null; if ($this->collProductI18ns instanceof Collection) { $this->collProductI18ns->clearIterator(); } diff --git a/core/lib/Thelia/Model/Base/ProductQuery.php b/core/lib/Thelia/Model/Base/ProductQuery.php index ebe26aa12..8ded7703f 100755 --- a/core/lib/Thelia/Model/Base/ProductQuery.php +++ b/core/lib/Thelia/Model/Base/ProductQuery.php @@ -102,6 +102,10 @@ use Thelia\Model\Map\ProductTableMap; * @method ChildProductQuery rightJoinRewriting($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Rewriting relation * @method ChildProductQuery innerJoinRewriting($relationAlias = null) Adds a INNER JOIN clause to the query using the Rewriting relation * + * @method ChildProductQuery leftJoinCartItem($relationAlias = null) Adds a LEFT JOIN clause to the query using the CartItem relation + * @method ChildProductQuery rightJoinCartItem($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CartItem relation + * @method ChildProductQuery innerJoinCartItem($relationAlias = null) Adds a INNER JOIN clause to the query using the CartItem relation + * * @method ChildProductQuery leftJoinProductI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ProductI18n relation * @method ChildProductQuery rightJoinProductI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProductI18n relation * @method ChildProductQuery innerJoinProductI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ProductI18n relation @@ -1745,6 +1749,79 @@ abstract class ProductQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'Rewriting', '\Thelia\Model\RewritingQuery'); } + /** + * Filter the query by a related \Thelia\Model\CartItem object + * + * @param \Thelia\Model\CartItem|ObjectCollection $cartItem the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildProductQuery The current query, for fluid interface + */ + public function filterByCartItem($cartItem, $comparison = null) + { + if ($cartItem instanceof \Thelia\Model\CartItem) { + return $this + ->addUsingAlias(ProductTableMap::ID, $cartItem->getProductId(), $comparison); + } elseif ($cartItem instanceof ObjectCollection) { + return $this + ->useCartItemQuery() + ->filterByPrimaryKeys($cartItem->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCartItem() only accepts arguments of type \Thelia\Model\CartItem or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CartItem relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildProductQuery The current query, for fluid interface + */ + public function joinCartItem($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CartItem'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CartItem'); + } + + return $this; + } + + /** + * Use the CartItem relation CartItem object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartItemQuery A secondary query class using the current class as primary query + */ + public function useCartItemQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCartItem($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CartItem', '\Thelia\Model\CartItemQuery'); + } + /** * Filter the query by a related \Thelia\Model\ProductI18n object * diff --git a/core/lib/Thelia/Model/Base/Stock.php b/core/lib/Thelia/Model/Base/Stock.php index 6594c845c..73942ce83 100755 --- a/core/lib/Thelia/Model/Base/Stock.php +++ b/core/lib/Thelia/Model/Base/Stock.php @@ -83,10 +83,10 @@ abstract class Stock implements ActiveRecordInterface protected $increase; /** - * The value for the value field. + * The value for the quantity field. * @var double */ - protected $value; + protected $quantity; /** * The value for the created_at field. @@ -417,14 +417,14 @@ abstract class Stock implements ActiveRecordInterface } /** - * Get the [value] column value. + * Get the [quantity] column value. * * @return double */ - public function getValue() + public function getQuantity() { - return $this->value; + return $this->quantity; } /** @@ -560,25 +560,25 @@ abstract class Stock implements ActiveRecordInterface } // setIncrease() /** - * Set the value of [value] column. + * Set the value of [quantity] column. * * @param double $v new value * @return \Thelia\Model\Stock The current object (for fluent API support) */ - public function setValue($v) + public function setQuantity($v) { if ($v !== null) { $v = (double) $v; } - if ($this->value !== $v) { - $this->value = $v; - $this->modifiedColumns[] = StockTableMap::VALUE; + if ($this->quantity !== $v) { + $this->quantity = $v; + $this->modifiedColumns[] = StockTableMap::QUANTITY; } return $this; - } // setValue() + } // setQuantity() /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. @@ -671,8 +671,8 @@ abstract class Stock implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : StockTableMap::translateFieldName('Increase', TableMap::TYPE_PHPNAME, $indexType)]; $this->increase = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : StockTableMap::translateFieldName('Value', TableMap::TYPE_PHPNAME, $indexType)]; - $this->value = (null !== $col) ? (double) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : StockTableMap::translateFieldName('Quantity', TableMap::TYPE_PHPNAME, $indexType)]; + $this->quantity = (null !== $col) ? (double) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : StockTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { @@ -952,8 +952,8 @@ abstract class Stock implements ActiveRecordInterface if ($this->isColumnModified(StockTableMap::INCREASE)) { $modifiedColumns[':p' . $index++] = 'INCREASE'; } - if ($this->isColumnModified(StockTableMap::VALUE)) { - $modifiedColumns[':p' . $index++] = 'VALUE'; + if ($this->isColumnModified(StockTableMap::QUANTITY)) { + $modifiedColumns[':p' . $index++] = 'QUANTITY'; } if ($this->isColumnModified(StockTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; @@ -984,8 +984,8 @@ abstract class Stock implements ActiveRecordInterface case 'INCREASE': $stmt->bindValue($identifier, $this->increase, PDO::PARAM_STR); break; - case 'VALUE': - $stmt->bindValue($identifier, $this->value, PDO::PARAM_STR); + case 'QUANTITY': + $stmt->bindValue($identifier, $this->quantity, PDO::PARAM_STR); break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); @@ -1068,7 +1068,7 @@ abstract class Stock implements ActiveRecordInterface return $this->getIncrease(); break; case 4: - return $this->getValue(); + return $this->getQuantity(); break; case 5: return $this->getCreatedAt(); @@ -1109,7 +1109,7 @@ abstract class Stock implements ActiveRecordInterface $keys[1] => $this->getCombinationId(), $keys[2] => $this->getProductId(), $keys[3] => $this->getIncrease(), - $keys[4] => $this->getValue(), + $keys[4] => $this->getQuantity(), $keys[5] => $this->getCreatedAt(), $keys[6] => $this->getUpdatedAt(), ); @@ -1173,7 +1173,7 @@ abstract class Stock implements ActiveRecordInterface $this->setIncrease($value); break; case 4: - $this->setValue($value); + $this->setQuantity($value); break; case 5: $this->setCreatedAt($value); @@ -1209,7 +1209,7 @@ abstract class Stock implements ActiveRecordInterface if (array_key_exists($keys[1], $arr)) $this->setCombinationId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setProductId($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setIncrease($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setValue($arr[$keys[4]]); + if (array_key_exists($keys[4], $arr)) $this->setQuantity($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); } @@ -1227,7 +1227,7 @@ abstract class Stock implements ActiveRecordInterface if ($this->isColumnModified(StockTableMap::COMBINATION_ID)) $criteria->add(StockTableMap::COMBINATION_ID, $this->combination_id); if ($this->isColumnModified(StockTableMap::PRODUCT_ID)) $criteria->add(StockTableMap::PRODUCT_ID, $this->product_id); if ($this->isColumnModified(StockTableMap::INCREASE)) $criteria->add(StockTableMap::INCREASE, $this->increase); - if ($this->isColumnModified(StockTableMap::VALUE)) $criteria->add(StockTableMap::VALUE, $this->value); + if ($this->isColumnModified(StockTableMap::QUANTITY)) $criteria->add(StockTableMap::QUANTITY, $this->quantity); if ($this->isColumnModified(StockTableMap::CREATED_AT)) $criteria->add(StockTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(StockTableMap::UPDATED_AT)) $criteria->add(StockTableMap::UPDATED_AT, $this->updated_at); @@ -1296,7 +1296,7 @@ abstract class Stock implements ActiveRecordInterface $copyObj->setCombinationId($this->getCombinationId()); $copyObj->setProductId($this->getProductId()); $copyObj->setIncrease($this->getIncrease()); - $copyObj->setValue($this->getValue()); + $copyObj->setQuantity($this->getQuantity()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { @@ -1438,7 +1438,7 @@ abstract class Stock implements ActiveRecordInterface $this->combination_id = null; $this->product_id = null; $this->increase = null; - $this->value = null; + $this->quantity = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/StockQuery.php b/core/lib/Thelia/Model/Base/StockQuery.php index 787543d4b..6a11b591d 100755 --- a/core/lib/Thelia/Model/Base/StockQuery.php +++ b/core/lib/Thelia/Model/Base/StockQuery.php @@ -25,7 +25,7 @@ use Thelia\Model\Map\StockTableMap; * @method ChildStockQuery orderByCombinationId($order = Criteria::ASC) Order by the combination_id column * @method ChildStockQuery orderByProductId($order = Criteria::ASC) Order by the product_id column * @method ChildStockQuery orderByIncrease($order = Criteria::ASC) Order by the increase column - * @method ChildStockQuery orderByValue($order = Criteria::ASC) Order by the value column + * @method ChildStockQuery orderByQuantity($order = Criteria::ASC) Order by the quantity column * @method ChildStockQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildStockQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -33,7 +33,7 @@ use Thelia\Model\Map\StockTableMap; * @method ChildStockQuery groupByCombinationId() Group by the combination_id column * @method ChildStockQuery groupByProductId() Group by the product_id column * @method ChildStockQuery groupByIncrease() Group by the increase column - * @method ChildStockQuery groupByValue() Group by the value column + * @method ChildStockQuery groupByQuantity() Group by the quantity column * @method ChildStockQuery groupByCreatedAt() Group by the created_at column * @method ChildStockQuery groupByUpdatedAt() Group by the updated_at column * @@ -56,7 +56,7 @@ use Thelia\Model\Map\StockTableMap; * @method ChildStock findOneByCombinationId(int $combination_id) Return the first ChildStock filtered by the combination_id column * @method ChildStock findOneByProductId(int $product_id) Return the first ChildStock filtered by the product_id column * @method ChildStock findOneByIncrease(double $increase) Return the first ChildStock filtered by the increase column - * @method ChildStock findOneByValue(double $value) Return the first ChildStock filtered by the value column + * @method ChildStock findOneByQuantity(double $quantity) Return the first ChildStock filtered by the quantity column * @method ChildStock findOneByCreatedAt(string $created_at) Return the first ChildStock filtered by the created_at column * @method ChildStock findOneByUpdatedAt(string $updated_at) Return the first ChildStock filtered by the updated_at column * @@ -64,7 +64,7 @@ use Thelia\Model\Map\StockTableMap; * @method array findByCombinationId(int $combination_id) Return ChildStock objects filtered by the combination_id column * @method array findByProductId(int $product_id) Return ChildStock objects filtered by the product_id column * @method array findByIncrease(double $increase) Return ChildStock objects filtered by the increase column - * @method array findByValue(double $value) Return ChildStock objects filtered by the value column + * @method array findByQuantity(double $quantity) Return ChildStock objects filtered by the quantity column * @method array findByCreatedAt(string $created_at) Return ChildStock objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildStock objects filtered by the updated_at column * @@ -155,7 +155,7 @@ abstract class StockQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, COMBINATION_ID, PRODUCT_ID, INCREASE, VALUE, CREATED_AT, UPDATED_AT FROM stock WHERE ID = :p0'; + $sql = 'SELECT ID, COMBINATION_ID, PRODUCT_ID, INCREASE, QUANTITY, CREATED_AT, UPDATED_AT FROM stock WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -413,16 +413,16 @@ abstract class StockQuery extends ModelCriteria } /** - * Filter the query on the value column + * Filter the query on the quantity column * * Example usage: * - * $query->filterByValue(1234); // WHERE value = 1234 - * $query->filterByValue(array(12, 34)); // WHERE value IN (12, 34) - * $query->filterByValue(array('min' => 12)); // WHERE value > 12 + * $query->filterByQuantity(1234); // WHERE quantity = 1234 + * $query->filterByQuantity(array(12, 34)); // WHERE quantity IN (12, 34) + * $query->filterByQuantity(array('min' => 12)); // WHERE quantity > 12 * * - * @param mixed $value The value to use as filter. + * @param mixed $quantity The value to use as filter. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. @@ -430,16 +430,16 @@ abstract class StockQuery extends ModelCriteria * * @return ChildStockQuery The current query, for fluid interface */ - public function filterByValue($value = null, $comparison = null) + public function filterByQuantity($quantity = null, $comparison = null) { - if (is_array($value)) { + if (is_array($quantity)) { $useMinMax = false; - if (isset($value['min'])) { - $this->addUsingAlias(StockTableMap::VALUE, $value['min'], Criteria::GREATER_EQUAL); + if (isset($quantity['min'])) { + $this->addUsingAlias(StockTableMap::QUANTITY, $quantity['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } - if (isset($value['max'])) { - $this->addUsingAlias(StockTableMap::VALUE, $value['max'], Criteria::LESS_EQUAL); + if (isset($quantity['max'])) { + $this->addUsingAlias(StockTableMap::QUANTITY, $quantity['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -450,7 +450,7 @@ abstract class StockQuery extends ModelCriteria } } - return $this->addUsingAlias(StockTableMap::VALUE, $value, $comparison); + return $this->addUsingAlias(StockTableMap::QUANTITY, $quantity, $comparison); } /** diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php new file mode 100644 index 000000000..32f51484e --- /dev/null +++ b/core/lib/Thelia/Model/Cart.php @@ -0,0 +1,10 @@ + array('Id', 'Title', 'CustomerId', 'CustomerTitleId', 'Company', 'Firstname', 'Lastname', 'Address1', 'Address2', 'Address3', 'Zipcode', 'City', 'CountryId', 'Phone', 'Cellphone', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'title', 'customerId', 'customerTitleId', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'countryId', 'phone', 'cellphone', 'isDefault', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AddressTableMap::ID, AddressTableMap::TITLE, AddressTableMap::CUSTOMER_ID, AddressTableMap::CUSTOMER_TITLE_ID, AddressTableMap::COMPANY, AddressTableMap::FIRSTNAME, AddressTableMap::LASTNAME, AddressTableMap::ADDRESS1, AddressTableMap::ADDRESS2, AddressTableMap::ADDRESS3, AddressTableMap::ZIPCODE, AddressTableMap::CITY, AddressTableMap::COUNTRY_ID, AddressTableMap::PHONE, AddressTableMap::CELLPHONE, AddressTableMap::IS_DEFAULT, AddressTableMap::CREATED_AT, AddressTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CUSTOMER_ID', 'CUSTOMER_TITLE_ID', 'COMPANY', 'FIRSTNAME', 'LASTNAME', 'ADDRESS1', 'ADDRESS2', 'ADDRESS3', 'ZIPCODE', 'CITY', 'COUNTRY_ID', 'PHONE', 'CELLPHONE', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'title', 'customer_id', 'customer_title_id', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country_id', 'phone', 'cellphone', 'is_default', 'created_at', 'updated_at', ), + self::TYPE_PHPNAME => array('Id', 'Title', 'CustomerId', 'CustomerTitleId', 'Company', 'Firstname', 'Lastname', 'Address1', 'Address2', 'Address3', 'Zipcode', 'City', 'CountryId', 'Phone', 'Cellphone', 'Default', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'title', 'customerId', 'customerTitleId', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'countryId', 'phone', 'cellphone', 'default', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AddressTableMap::ID, AddressTableMap::TITLE, AddressTableMap::CUSTOMER_ID, AddressTableMap::CUSTOMER_TITLE_ID, AddressTableMap::COMPANY, AddressTableMap::FIRSTNAME, AddressTableMap::LASTNAME, AddressTableMap::ADDRESS1, AddressTableMap::ADDRESS2, AddressTableMap::ADDRESS3, AddressTableMap::ZIPCODE, AddressTableMap::CITY, AddressTableMap::COUNTRY_ID, AddressTableMap::PHONE, AddressTableMap::CELLPHONE, AddressTableMap::DEFAULT, AddressTableMap::CREATED_AT, AddressTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CUSTOMER_ID', 'CUSTOMER_TITLE_ID', 'COMPANY', 'FIRSTNAME', 'LASTNAME', 'ADDRESS1', 'ADDRESS2', 'ADDRESS3', 'ZIPCODE', 'CITY', 'COUNTRY_ID', 'PHONE', 'CELLPHONE', 'DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'title', 'customer_id', 'customer_title_id', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country_id', 'phone', 'cellphone', 'default', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ) ); @@ -186,11 +186,11 @@ class AddressTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'CustomerId' => 2, 'CustomerTitleId' => 3, 'Company' => 4, 'Firstname' => 5, 'Lastname' => 6, 'Address1' => 7, 'Address2' => 8, 'Address3' => 9, 'Zipcode' => 10, 'City' => 11, 'CountryId' => 12, 'Phone' => 13, 'Cellphone' => 14, 'IsDefault' => 15, 'CreatedAt' => 16, 'UpdatedAt' => 17, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'customerId' => 2, 'customerTitleId' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'countryId' => 12, 'phone' => 13, 'cellphone' => 14, 'isDefault' => 15, 'createdAt' => 16, 'updatedAt' => 17, ), - self::TYPE_COLNAME => array(AddressTableMap::ID => 0, AddressTableMap::TITLE => 1, AddressTableMap::CUSTOMER_ID => 2, AddressTableMap::CUSTOMER_TITLE_ID => 3, AddressTableMap::COMPANY => 4, AddressTableMap::FIRSTNAME => 5, AddressTableMap::LASTNAME => 6, AddressTableMap::ADDRESS1 => 7, AddressTableMap::ADDRESS2 => 8, AddressTableMap::ADDRESS3 => 9, AddressTableMap::ZIPCODE => 10, AddressTableMap::CITY => 11, AddressTableMap::COUNTRY_ID => 12, AddressTableMap::PHONE => 13, AddressTableMap::CELLPHONE => 14, AddressTableMap::IS_DEFAULT => 15, AddressTableMap::CREATED_AT => 16, AddressTableMap::UPDATED_AT => 17, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CUSTOMER_ID' => 2, 'CUSTOMER_TITLE_ID' => 3, 'COMPANY' => 4, 'FIRSTNAME' => 5, 'LASTNAME' => 6, 'ADDRESS1' => 7, 'ADDRESS2' => 8, 'ADDRESS3' => 9, 'ZIPCODE' => 10, 'CITY' => 11, 'COUNTRY_ID' => 12, 'PHONE' => 13, 'CELLPHONE' => 14, 'IS_DEFAULT' => 15, 'CREATED_AT' => 16, 'UPDATED_AT' => 17, ), - self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'customer_id' => 2, 'customer_title_id' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'country_id' => 12, 'phone' => 13, 'cellphone' => 14, 'is_default' => 15, 'created_at' => 16, 'updated_at' => 17, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'CustomerId' => 2, 'CustomerTitleId' => 3, 'Company' => 4, 'Firstname' => 5, 'Lastname' => 6, 'Address1' => 7, 'Address2' => 8, 'Address3' => 9, 'Zipcode' => 10, 'City' => 11, 'CountryId' => 12, 'Phone' => 13, 'Cellphone' => 14, 'Default' => 15, 'CreatedAt' => 16, 'UpdatedAt' => 17, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'customerId' => 2, 'customerTitleId' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'countryId' => 12, 'phone' => 13, 'cellphone' => 14, 'default' => 15, 'createdAt' => 16, 'updatedAt' => 17, ), + self::TYPE_COLNAME => array(AddressTableMap::ID => 0, AddressTableMap::TITLE => 1, AddressTableMap::CUSTOMER_ID => 2, AddressTableMap::CUSTOMER_TITLE_ID => 3, AddressTableMap::COMPANY => 4, AddressTableMap::FIRSTNAME => 5, AddressTableMap::LASTNAME => 6, AddressTableMap::ADDRESS1 => 7, AddressTableMap::ADDRESS2 => 8, AddressTableMap::ADDRESS3 => 9, AddressTableMap::ZIPCODE => 10, AddressTableMap::CITY => 11, AddressTableMap::COUNTRY_ID => 12, AddressTableMap::PHONE => 13, AddressTableMap::CELLPHONE => 14, AddressTableMap::DEFAULT => 15, AddressTableMap::CREATED_AT => 16, AddressTableMap::UPDATED_AT => 17, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CUSTOMER_ID' => 2, 'CUSTOMER_TITLE_ID' => 3, 'COMPANY' => 4, 'FIRSTNAME' => 5, 'LASTNAME' => 6, 'ADDRESS1' => 7, 'ADDRESS2' => 8, 'ADDRESS3' => 9, 'ZIPCODE' => 10, 'CITY' => 11, 'COUNTRY_ID' => 12, 'PHONE' => 13, 'CELLPHONE' => 14, 'DEFAULT' => 15, 'CREATED_AT' => 16, 'UPDATED_AT' => 17, ), + self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'customer_id' => 2, 'customer_title_id' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'country_id' => 12, 'phone' => 13, 'cellphone' => 14, 'default' => 15, 'created_at' => 16, 'updated_at' => 17, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ) ); @@ -225,7 +225,7 @@ class AddressTableMap extends TableMap $this->addColumn('COUNTRY_ID', 'CountryId', 'INTEGER', true, null, null); $this->addColumn('PHONE', 'Phone', 'VARCHAR', false, 20, null); $this->addColumn('CELLPHONE', 'Cellphone', 'VARCHAR', false, 20, null); - $this->addColumn('IS_DEFAULT', 'IsDefault', 'TINYINT', false, null, 0); + $this->addColumn('DEFAULT', 'Default', 'TINYINT', false, null, 0); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -237,6 +237,8 @@ class AddressTableMap extends TableMap { $this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('customer_id' => 'id', ), 'CASCADE', 'RESTRICT'); $this->addRelation('CustomerTitle', '\\Thelia\\Model\\CustomerTitle', RelationMap::MANY_TO_ONE, array('customer_title_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + $this->addRelation('CartRelatedByAddressDeliveryId', '\\Thelia\\Model\\Cart', RelationMap::ONE_TO_MANY, array('id' => 'address_delivery_id', ), null, null, 'CartsRelatedByAddressDeliveryId'); + $this->addRelation('CartRelatedByAddressInvoiceId', '\\Thelia\\Model\\Cart', RelationMap::ONE_TO_MANY, array('id' => 'address_invoice_id', ), null, null, 'CartsRelatedByAddressInvoiceId'); } // buildRelations() /** @@ -405,7 +407,7 @@ class AddressTableMap extends TableMap $criteria->addSelectColumn(AddressTableMap::COUNTRY_ID); $criteria->addSelectColumn(AddressTableMap::PHONE); $criteria->addSelectColumn(AddressTableMap::CELLPHONE); - $criteria->addSelectColumn(AddressTableMap::IS_DEFAULT); + $criteria->addSelectColumn(AddressTableMap::DEFAULT); $criteria->addSelectColumn(AddressTableMap::CREATED_AT); $criteria->addSelectColumn(AddressTableMap::UPDATED_AT); } else { @@ -424,7 +426,7 @@ class AddressTableMap extends TableMap $criteria->addSelectColumn($alias . '.COUNTRY_ID'); $criteria->addSelectColumn($alias . '.PHONE'); $criteria->addSelectColumn($alias . '.CELLPHONE'); - $criteria->addSelectColumn($alias . '.IS_DEFAULT'); + $criteria->addSelectColumn($alias . '.DEFAULT'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/CartItemTableMap.php b/core/lib/Thelia/Model/Map/CartItemTableMap.php new file mode 100644 index 000000000..c496e85c8 --- /dev/null +++ b/core/lib/Thelia/Model/Map/CartItemTableMap.php @@ -0,0 +1,465 @@ + array('Id', 'CartId', 'ProductId', 'Quantity', 'CombinationId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'cartId', 'productId', 'quantity', 'combinationId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(CartItemTableMap::ID, CartItemTableMap::CART_ID, CartItemTableMap::PRODUCT_ID, CartItemTableMap::QUANTITY, CartItemTableMap::COMBINATION_ID, CartItemTableMap::CREATED_AT, CartItemTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'CART_ID', 'PRODUCT_ID', 'QUANTITY', 'COMBINATION_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'cart_id', 'product_id', 'quantity', 'combination_id', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'CartId' => 1, 'ProductId' => 2, 'Quantity' => 3, 'CombinationId' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'cartId' => 1, 'productId' => 2, 'quantity' => 3, 'combinationId' => 4, 'createdAt' => 5, 'updatedAt' => 6, ), + self::TYPE_COLNAME => array(CartItemTableMap::ID => 0, CartItemTableMap::CART_ID => 1, CartItemTableMap::PRODUCT_ID => 2, CartItemTableMap::QUANTITY => 3, CartItemTableMap::COMBINATION_ID => 4, CartItemTableMap::CREATED_AT => 5, CartItemTableMap::UPDATED_AT => 6, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CART_ID' => 1, 'PRODUCT_ID' => 2, 'QUANTITY' => 3, 'COMBINATION_ID' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ), + self::TYPE_FIELDNAME => array('id' => 0, 'cart_id' => 1, 'product_id' => 2, 'quantity' => 3, 'combination_id' => 4, 'created_at' => 5, 'updated_at' => 6, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('cart_item'); + $this->setPhpName('CartItem'); + $this->setClassName('\\Thelia\\Model\\CartItem'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('CART_ID', 'CartId', 'INTEGER', 'cart', 'ID', true, null, null); + $this->addForeignKey('PRODUCT_ID', 'ProductId', 'INTEGER', 'product', 'ID', true, null, null); + $this->addColumn('QUANTITY', 'Quantity', 'FLOAT', false, null, 1); + $this->addForeignKey('COMBINATION_ID', 'CombinationId', 'INTEGER', 'combination', 'ID', false, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Cart', '\\Thelia\\Model\\Cart', RelationMap::MANY_TO_ONE, array('cart_id' => 'id', ), null, null); + $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::MANY_TO_ONE, array('product_id' => 'id', ), null, null); + $this->addRelation('Combination', '\\Thelia\\Model\\Combination', RelationMap::MANY_TO_ONE, array('combination_id' => 'id', ), null, null); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? CartItemTableMap::CLASS_DEFAULT : CartItemTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (CartItem object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CartItemTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CartItemTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + CartItemTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CartItemTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CartItemTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = CartItemTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CartItemTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + CartItemTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(CartItemTableMap::ID); + $criteria->addSelectColumn(CartItemTableMap::CART_ID); + $criteria->addSelectColumn(CartItemTableMap::PRODUCT_ID); + $criteria->addSelectColumn(CartItemTableMap::QUANTITY); + $criteria->addSelectColumn(CartItemTableMap::COMBINATION_ID); + $criteria->addSelectColumn(CartItemTableMap::CREATED_AT); + $criteria->addSelectColumn(CartItemTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.CART_ID'); + $criteria->addSelectColumn($alias . '.PRODUCT_ID'); + $criteria->addSelectColumn($alias . '.QUANTITY'); + $criteria->addSelectColumn($alias . '.COMBINATION_ID'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(CartItemTableMap::DATABASE_NAME)->getTable(CartItemTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CartItemTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CartItemTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CartItemTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a CartItem or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or CartItem object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartItemTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\CartItem) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(CartItemTableMap::DATABASE_NAME); + $criteria->add(CartItemTableMap::ID, (array) $values, Criteria::IN); + } + + $query = CartItemQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { CartItemTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { CartItemTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the cart_item table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return CartItemQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a CartItem or Criteria object. + * + * @param mixed $criteria Criteria or CartItem 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(CartItemTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from CartItem object + } + + if ($criteria->containsKey(CartItemTableMap::ID) && $criteria->keyContainsValue(CartItemTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CartItemTableMap::ID.')'); + } + + + // Set the correct dbName + $query = CartItemQuery::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; + } + +} // CartItemTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CartItemTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/CartTableMap.php b/core/lib/Thelia/Model/Map/CartTableMap.php new file mode 100644 index 000000000..0f0f122e5 --- /dev/null +++ b/core/lib/Thelia/Model/Map/CartTableMap.php @@ -0,0 +1,475 @@ + array('Id', 'Token', 'CustomerId', 'AddressDeliveryId', 'AddressInvoiceId', 'CurrencyId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'token', 'customerId', 'addressDeliveryId', 'addressInvoiceId', 'currencyId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(CartTableMap::ID, CartTableMap::TOKEN, CartTableMap::CUSTOMER_ID, CartTableMap::ADDRESS_DELIVERY_ID, CartTableMap::ADDRESS_INVOICE_ID, CartTableMap::CURRENCY_ID, CartTableMap::CREATED_AT, CartTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'TOKEN', 'CUSTOMER_ID', 'ADDRESS_DELIVERY_ID', 'ADDRESS_INVOICE_ID', 'CURRENCY_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'token', 'customer_id', 'address_delivery_id', 'address_invoice_id', 'currency_id', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Token' => 1, 'CustomerId' => 2, 'AddressDeliveryId' => 3, 'AddressInvoiceId' => 4, 'CurrencyId' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'token' => 1, 'customerId' => 2, 'addressDeliveryId' => 3, 'addressInvoiceId' => 4, 'currencyId' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), + self::TYPE_COLNAME => array(CartTableMap::ID => 0, CartTableMap::TOKEN => 1, CartTableMap::CUSTOMER_ID => 2, CartTableMap::ADDRESS_DELIVERY_ID => 3, CartTableMap::ADDRESS_INVOICE_ID => 4, CartTableMap::CURRENCY_ID => 5, CartTableMap::CREATED_AT => 6, CartTableMap::UPDATED_AT => 7, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'TOKEN' => 1, 'CUSTOMER_ID' => 2, 'ADDRESS_DELIVERY_ID' => 3, 'ADDRESS_INVOICE_ID' => 4, 'CURRENCY_ID' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), + self::TYPE_FIELDNAME => array('id' => 0, 'token' => 1, 'customer_id' => 2, 'address_delivery_id' => 3, 'address_invoice_id' => 4, 'currency_id' => 5, 'created_at' => 6, 'updated_at' => 7, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('cart'); + $this->setPhpName('Cart'); + $this->setClassName('\\Thelia\\Model\\Cart'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('TOKEN', 'Token', 'VARCHAR', true, 255, null); + $this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', false, null, null); + $this->addForeignKey('ADDRESS_DELIVERY_ID', 'AddressDeliveryId', 'INTEGER', 'address', 'ID', false, null, null); + $this->addForeignKey('ADDRESS_INVOICE_ID', 'AddressInvoiceId', 'INTEGER', 'address', 'ID', false, null, null); + $this->addForeignKey('CURRENCY_ID', 'CurrencyId', 'INTEGER', 'currency', 'ID', false, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('customer_id' => 'id', ), null, null); + $this->addRelation('AddressRelatedByAddressDeliveryId', '\\Thelia\\Model\\Address', RelationMap::MANY_TO_ONE, array('address_delivery_id' => 'id', ), null, null); + $this->addRelation('AddressRelatedByAddressInvoiceId', '\\Thelia\\Model\\Address', RelationMap::MANY_TO_ONE, array('address_invoice_id' => 'id', ), null, null); + $this->addRelation('Currency', '\\Thelia\\Model\\Currency', RelationMap::MANY_TO_ONE, array('currency_id' => 'id', ), null, null); + $this->addRelation('CartItem', '\\Thelia\\Model\\CartItem', RelationMap::ONE_TO_MANY, array('id' => 'cart_id', ), null, null, 'CartItems'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? CartTableMap::CLASS_DEFAULT : CartTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Cart object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CartTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CartTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + CartTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CartTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CartTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = CartTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CartTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + CartTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(CartTableMap::ID); + $criteria->addSelectColumn(CartTableMap::TOKEN); + $criteria->addSelectColumn(CartTableMap::CUSTOMER_ID); + $criteria->addSelectColumn(CartTableMap::ADDRESS_DELIVERY_ID); + $criteria->addSelectColumn(CartTableMap::ADDRESS_INVOICE_ID); + $criteria->addSelectColumn(CartTableMap::CURRENCY_ID); + $criteria->addSelectColumn(CartTableMap::CREATED_AT); + $criteria->addSelectColumn(CartTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.TOKEN'); + $criteria->addSelectColumn($alias . '.CUSTOMER_ID'); + $criteria->addSelectColumn($alias . '.ADDRESS_DELIVERY_ID'); + $criteria->addSelectColumn($alias . '.ADDRESS_INVOICE_ID'); + $criteria->addSelectColumn($alias . '.CURRENCY_ID'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(CartTableMap::DATABASE_NAME)->getTable(CartTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CartTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CartTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CartTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Cart or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Cart object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CartTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\Cart) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(CartTableMap::DATABASE_NAME); + $criteria->add(CartTableMap::ID, (array) $values, Criteria::IN); + } + + $query = CartQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { CartTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { CartTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the cart table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return CartQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Cart or Criteria object. + * + * @param mixed $criteria Criteria or Cart 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(CartTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Cart object + } + + if ($criteria->containsKey(CartTableMap::ID) && $criteria->keyContainsValue(CartTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CartTableMap::ID.')'); + } + + + // Set the correct dbName + $query = CartQuery::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; + } + +} // CartTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CartTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/CombinationTableMap.php b/core/lib/Thelia/Model/Map/CombinationTableMap.php index 96ce0507e..7134c5eaf 100755 --- a/core/lib/Thelia/Model/Map/CombinationTableMap.php +++ b/core/lib/Thelia/Model/Map/CombinationTableMap.php @@ -153,6 +153,7 @@ class CombinationTableMap extends TableMap { $this->addRelation('AttributeCombination', '\\Thelia\\Model\\AttributeCombination', RelationMap::ONE_TO_MANY, array('id' => 'combination_id', ), 'CASCADE', 'RESTRICT', 'AttributeCombinations'); $this->addRelation('Stock', '\\Thelia\\Model\\Stock', RelationMap::ONE_TO_MANY, array('id' => 'combination_id', ), 'SET NULL', 'RESTRICT', 'Stocks'); + $this->addRelation('CartItem', '\\Thelia\\Model\\CartItem', RelationMap::ONE_TO_MANY, array('id' => 'combination_id', ), null, null, 'CartItems'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/Map/CurrencyTableMap.php b/core/lib/Thelia/Model/Map/CurrencyTableMap.php index 36ed58310..8d2ca54ec 100755 --- a/core/lib/Thelia/Model/Map/CurrencyTableMap.php +++ b/core/lib/Thelia/Model/Map/CurrencyTableMap.php @@ -176,6 +176,7 @@ class CurrencyTableMap extends TableMap public function buildRelations() { $this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::ONE_TO_MANY, array('id' => 'currency_id', ), 'SET NULL', 'RESTRICT', 'Orders'); + $this->addRelation('Cart', '\\Thelia\\Model\\Cart', RelationMap::ONE_TO_MANY, array('id' => 'currency_id', ), null, null, 'Carts'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/Map/CustomerTableMap.php b/core/lib/Thelia/Model/Map/CustomerTableMap.php index fbd2a9b98..b23f4d6b0 100755 --- a/core/lib/Thelia/Model/Map/CustomerTableMap.php +++ b/core/lib/Thelia/Model/Map/CustomerTableMap.php @@ -192,7 +192,7 @@ class CustomerTableMap extends TableMap // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('REF', 'Ref', 'VARCHAR', true, 50, null); - $this->addForeignKey('TITLE_ID', 'TitleId', 'INTEGER', 'customer_title', 'ID', false, null, null); + $this->addForeignKey('TITLE_ID', 'TitleId', 'INTEGER', 'customer_title', 'ID', true, null, null); $this->addColumn('FIRSTNAME', 'Firstname', 'VARCHAR', true, 255, null); $this->addColumn('LASTNAME', 'Lastname', 'VARCHAR', true, 255, null); $this->addColumn('EMAIL', 'Email', 'VARCHAR', false, 50, null); @@ -214,6 +214,7 @@ class CustomerTableMap extends TableMap $this->addRelation('CustomerTitle', '\\Thelia\\Model\\CustomerTitle', RelationMap::MANY_TO_ONE, array('title_id' => 'id', ), 'RESTRICT', 'RESTRICT'); $this->addRelation('Address', '\\Thelia\\Model\\Address', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'CASCADE', 'RESTRICT', 'Addresses'); $this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), 'CASCADE', 'RESTRICT', 'Orders'); + $this->addRelation('Cart', '\\Thelia\\Model\\Cart', RelationMap::ONE_TO_MANY, array('id' => 'customer_id', ), null, null, 'Carts'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/Map/ProductTableMap.php b/core/lib/Thelia/Model/Map/ProductTableMap.php index 40200ce10..61c56dc8c 100755 --- a/core/lib/Thelia/Model/Map/ProductTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductTableMap.php @@ -248,6 +248,7 @@ class ProductTableMap extends TableMap $this->addRelation('AccessoryRelatedByProductId', '\\Thelia\\Model\\Accessory', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'AccessoriesRelatedByProductId'); $this->addRelation('AccessoryRelatedByAccessory', '\\Thelia\\Model\\Accessory', RelationMap::ONE_TO_MANY, array('id' => 'accessory', ), 'CASCADE', 'RESTRICT', 'AccessoriesRelatedByAccessory'); $this->addRelation('Rewriting', '\\Thelia\\Model\\Rewriting', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'Rewritings'); + $this->addRelation('CartItem', '\\Thelia\\Model\\CartItem', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), null, null, 'CartItems'); $this->addRelation('ProductI18n', '\\Thelia\\Model\\ProductI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ProductI18ns'); $this->addRelation('ProductVersion', '\\Thelia\\Model\\ProductVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ProductVersions'); $this->addRelation('Category', '\\Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categories'); diff --git a/core/lib/Thelia/Model/Map/StockTableMap.php b/core/lib/Thelia/Model/Map/StockTableMap.php index 470f7a0a8..c724c9d09 100755 --- a/core/lib/Thelia/Model/Map/StockTableMap.php +++ b/core/lib/Thelia/Model/Map/StockTableMap.php @@ -90,9 +90,9 @@ class StockTableMap extends TableMap const INCREASE = 'stock.INCREASE'; /** - * the column name for the VALUE field + * the column name for the QUANTITY field */ - const VALUE = 'stock.VALUE'; + const QUANTITY = 'stock.QUANTITY'; /** * the column name for the CREATED_AT field @@ -116,11 +116,11 @@ class StockTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'CombinationId', 'ProductId', 'Increase', 'Value', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'combinationId', 'productId', 'increase', 'value', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(StockTableMap::ID, StockTableMap::COMBINATION_ID, StockTableMap::PRODUCT_ID, StockTableMap::INCREASE, StockTableMap::VALUE, StockTableMap::CREATED_AT, StockTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'COMBINATION_ID', 'PRODUCT_ID', 'INCREASE', 'VALUE', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'combination_id', 'product_id', 'increase', 'value', 'created_at', 'updated_at', ), + self::TYPE_PHPNAME => array('Id', 'CombinationId', 'ProductId', 'Increase', 'Quantity', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'combinationId', 'productId', 'increase', 'quantity', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(StockTableMap::ID, StockTableMap::COMBINATION_ID, StockTableMap::PRODUCT_ID, StockTableMap::INCREASE, StockTableMap::QUANTITY, StockTableMap::CREATED_AT, StockTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'COMBINATION_ID', 'PRODUCT_ID', 'INCREASE', 'QUANTITY', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'combination_id', 'product_id', 'increase', 'quantity', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) ); @@ -131,11 +131,11 @@ class StockTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'CombinationId' => 1, 'ProductId' => 2, 'Increase' => 3, 'Value' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'combinationId' => 1, 'productId' => 2, 'increase' => 3, 'value' => 4, 'createdAt' => 5, 'updatedAt' => 6, ), - self::TYPE_COLNAME => array(StockTableMap::ID => 0, StockTableMap::COMBINATION_ID => 1, StockTableMap::PRODUCT_ID => 2, StockTableMap::INCREASE => 3, StockTableMap::VALUE => 4, StockTableMap::CREATED_AT => 5, StockTableMap::UPDATED_AT => 6, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'COMBINATION_ID' => 1, 'PRODUCT_ID' => 2, 'INCREASE' => 3, 'VALUE' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ), - self::TYPE_FIELDNAME => array('id' => 0, 'combination_id' => 1, 'product_id' => 2, 'increase' => 3, 'value' => 4, 'created_at' => 5, 'updated_at' => 6, ), + self::TYPE_PHPNAME => array('Id' => 0, 'CombinationId' => 1, 'ProductId' => 2, 'Increase' => 3, 'Quantity' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'combinationId' => 1, 'productId' => 2, 'increase' => 3, 'quantity' => 4, 'createdAt' => 5, 'updatedAt' => 6, ), + self::TYPE_COLNAME => array(StockTableMap::ID => 0, StockTableMap::COMBINATION_ID => 1, StockTableMap::PRODUCT_ID => 2, StockTableMap::INCREASE => 3, StockTableMap::QUANTITY => 4, StockTableMap::CREATED_AT => 5, StockTableMap::UPDATED_AT => 6, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'COMBINATION_ID' => 1, 'PRODUCT_ID' => 2, 'INCREASE' => 3, 'QUANTITY' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ), + self::TYPE_FIELDNAME => array('id' => 0, 'combination_id' => 1, 'product_id' => 2, 'increase' => 3, 'quantity' => 4, 'created_at' => 5, 'updated_at' => 6, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) ); @@ -159,7 +159,7 @@ class StockTableMap extends TableMap $this->addForeignKey('COMBINATION_ID', 'CombinationId', 'INTEGER', 'combination', 'ID', false, null, null); $this->addForeignKey('PRODUCT_ID', 'ProductId', 'INTEGER', 'product', 'ID', true, null, null); $this->addColumn('INCREASE', 'Increase', 'FLOAT', false, null, null); - $this->addColumn('VALUE', 'Value', 'FLOAT', true, null, null); + $this->addColumn('QUANTITY', 'Quantity', 'FLOAT', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -328,7 +328,7 @@ class StockTableMap extends TableMap $criteria->addSelectColumn(StockTableMap::COMBINATION_ID); $criteria->addSelectColumn(StockTableMap::PRODUCT_ID); $criteria->addSelectColumn(StockTableMap::INCREASE); - $criteria->addSelectColumn(StockTableMap::VALUE); + $criteria->addSelectColumn(StockTableMap::QUANTITY); $criteria->addSelectColumn(StockTableMap::CREATED_AT); $criteria->addSelectColumn(StockTableMap::UPDATED_AT); } else { @@ -336,7 +336,7 @@ class StockTableMap extends TableMap $criteria->addSelectColumn($alias . '.COMBINATION_ID'); $criteria->addSelectColumn($alias . '.PRODUCT_ID'); $criteria->addSelectColumn($alias . '.INCREASE'); - $criteria->addSelectColumn($alias . '.VALUE'); + $criteria->addSelectColumn($alias . '.QUANTITY'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/install/thelia.sql b/install/thelia.sql index 859b776bb..97aa11a7e 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -379,7 +379,7 @@ CREATE TABLE `stock` `combination_id` INTEGER, `product_id` INTEGER NOT NULL, `increase` FLOAT, - `value` FLOAT NOT NULL, + `quantity` FLOAT NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), @@ -1288,6 +1288,72 @@ CREATE TABLE `content_folder` ON DELETE CASCADE ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- cart +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `cart`; + +CREATE TABLE `cart` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `token` VARCHAR(255) NOT NULL, + `customer_id` INTEGER, + `address_delivery_id` INTEGER, + `address_invoice_id` INTEGER, + `currency_id` INTEGER, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + UNIQUE INDEX `token_UNIQUE` (`token`), + INDEX `idx_cart_customer_id` (`customer_id`), + INDEX `idx_cart_address_delivery_id` (`address_delivery_id`), + INDEX `idx_cart_address_invoice_id` (`address_invoice_id`), + INDEX `idx_cart_currency_id` (`currency_id`), + CONSTRAINT `fk_cart_customer_id` + FOREIGN KEY (`customer_id`) + REFERENCES `customer` (`id`), + CONSTRAINT `fk_cart_address_delivery_id` + FOREIGN KEY (`address_delivery_id`) + REFERENCES `address` (`id`), + CONSTRAINT `fk_cart_address_invoice_id` + FOREIGN KEY (`address_invoice_id`) + REFERENCES `address` (`id`), + CONSTRAINT `fk_cart_currency_id` + FOREIGN KEY (`currency_id`) + REFERENCES `currency` (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- cart_item +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `cart_item`; + +CREATE TABLE `cart_item` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `cart_id` INTEGER NOT NULL, + `product_id` INTEGER NOT NULL, + `quantity` FLOAT DEFAULT 1, + `combination_id` INTEGER, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `idx_cart_item_cart_id` (`cart_id`), + INDEX `idx_cart_item_product_id` (`product_id`), + INDEX `idx_cart_item_combination_id` (`combination_id`), + CONSTRAINT `fk_cart_item_cart_id` + FOREIGN KEY (`cart_id`) + REFERENCES `cart` (`id`), + CONSTRAINT `fk_cart_item_product_id` + FOREIGN KEY (`product_id`) + REFERENCES `product` (`id`), + CONSTRAINT `fk_cart_item_combination_id` + FOREIGN KEY (`combination_id`) + REFERENCES `combination` (`id`) +) ENGINE=InnoDB; + -- --------------------------------------------------------------------- -- category_i18n -- --------------------------------------------------------------------- diff --git a/local/config/schema.xml b/local/config/schema.xml index 315f70c2b..34974898f 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -278,7 +278,7 @@ - + @@ -931,4 +931,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +