# File core/lib/Thelia/Model/om/BaseProduct.php | thelia

       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BaseObject;
       6: use \BasePeer;
       7: use \Criteria;
       8: use \DateTime;
       9: use \Exception;
      10: use \PDO;
      11: use \Persistent;
      12: use \Propel;
      13: use \PropelCollection;
      14: use \PropelDateTime;
      15: use \PropelException;
      16: use \PropelObjectCollection;
      17: use \PropelPDO;
      18: use Thelia\Model\Accessory;
      19: use Thelia\Model\AccessoryQuery;
      20: use Thelia\Model\ContentAssoc;
      21: use Thelia\Model\ContentAssocQuery;
      22: use Thelia\Model\Document;
      23: use Thelia\Model\DocumentQuery;
      24: use Thelia\Model\FeatureProd;
      25: use Thelia\Model\FeatureProdQuery;
      26: use Thelia\Model\Image;
      27: use Thelia\Model\ImageQuery;
      28: use Thelia\Model\Product;
      29: use Thelia\Model\ProductCategory;
      30: use Thelia\Model\ProductCategoryQuery;
      31: use Thelia\Model\ProductI18n;
      32: use Thelia\Model\ProductI18nQuery;
      33: use Thelia\Model\ProductPeer;
      34: use Thelia\Model\ProductQuery;
      35: use Thelia\Model\ProductVersion;
      36: use Thelia\Model\ProductVersionPeer;
      37: use Thelia\Model\ProductVersionQuery;
      38: use Thelia\Model\Rewriting;
      39: use Thelia\Model\RewritingQuery;
      40: use Thelia\Model\Stock;
      41: use Thelia\Model\StockQuery;
      42: use Thelia\Model\TaxRule;
      43: use Thelia\Model\TaxRuleQuery;
      44:
      45: /**
      46:  * Base class that represents a row from the 'product' table.
      47:  *
      48:  *
      49:  *
      50:  * @package    propel.generator.Thelia.Model.om
      51:  */
      52: abstract class BaseProduct extends BaseObject implements Persistent
      53: {
      54:     /**
      55:      * Peer class name
      56:      */
      57:     const PEER = 'Thelia\\Model\\ProductPeer';
      58:
      59:     /**
      60:      * The Peer class.
      61:      * Instance provides a convenient way of calling static methods on a class
      62:      * that calling code may not be able to identify.
      63:      * @var        ProductPeer
      64:      */
      65:     protected static $peer;
      66:
      67:     /**
      68:      * The flag var to prevent infinit loop in deep copy
      69:      * @var       boolean
      70:      */
      71:     protected $startCopy = false;
      72:
      73:     /**
      74:      * The value for the id field.
      75:      * @var        int
      76:      */
      77:     protected $id;
      78:
      79:     /**
      80:      * The value for the tax_rule_id field.
      81:      * @var        int
      82:      */
      83:     protected $tax_rule_id;
      84:
      85:     /**
      86:      * The value for the ref field.
      87:      * @var        string
      88:      */
      89:     protected $ref;
      90:
      91:     /**
      92:      * The value for the price field.
      93:      * @var        double
      94:      */
      95:     protected $price;
      96:
      97:     /**
      98:      * The value for the price2 field.
      99:      * @var        double
     100:      */
     101:     protected $price2;
     102:
     103:     /**
     104:      * The value for the ecotax field.
     105:      * @var        double
     106:      */
     107:     protected $ecotax;
     108:
     109:     /**
     110:      * The value for the newness field.
     111:      * Note: this column has a database default value of: 0
     112:      * @var        int
     113:      */
     114:     protected $newness;
     115:
     116:     /**
     117:      * The value for the promo field.
     118:      * Note: this column has a database default value of: 0
     119:      * @var        int
     120:      */
     121:     protected $promo;
     122:
     123:     /**
     124:      * The value for the stock field.
     125:      * Note: this column has a database default value of: 0
     126:      * @var        int
     127:      */
     128:     protected $stock;
     129:
     130:     /**
     131:      * The value for the visible field.
     132:      * Note: this column has a database default value of: 0
     133:      * @var        int
     134:      */
     135:     protected $visible;
     136:
     137:     /**
     138:      * The value for the weight field.
     139:      * @var        double
     140:      */
     141:     protected $weight;
     142:
     143:     /**
     144:      * The value for the position field.
     145:      * @var        int
     146:      */
     147:     protected $position;
     148:
     149:     /**
     150:      * The value for the created_at field.
     151:      * @var        string
     152:      */
     153:     protected $created_at;
     154:
     155:     /**
     156:      * The value for the updated_at field.
     157:      * @var        string
     158:      */
     159:     protected $updated_at;
     160:
     161:     /**
     162:      * The value for the version field.
     163:      * Note: this column has a database default value of: 0
     164:      * @var        int
     165:      */
     166:     protected $version;
     167:
     168:     /**
     169:      * The value for the version_created_at field.
     170:      * @var        string
     171:      */
     172:     protected $version_created_at;
     173:
     174:     /**
     175:      * The value for the version_created_by field.
     176:      * @var        string
     177:      */
     178:     protected $version_created_by;
     179:
     180:     /**
     181:      * @var        TaxRule
     182:      */
     183:     protected $aTaxRule;
     184:
     185:     /**
     186:      * @var        PropelObjectCollection|ProductCategory[] Collection to store aggregation of ProductCategory objects.
     187:      */
     188:     protected $collProductCategorys;
     189:     protected $collProductCategorysPartial;
     190:
     191:     /**
     192:      * @var        PropelObjectCollection|FeatureProd[] Collection to store aggregation of FeatureProd objects.
     193:      */
     194:     protected $collFeatureProds;
     195:     protected $collFeatureProdsPartial;
     196:
     197:     /**
     198:      * @var        PropelObjectCollection|Stock[] Collection to store aggregation of Stock objects.
     199:      */
     200:     protected $collStocks;
     201:     protected $collStocksPartial;
     202:
     203:     /**
     204:      * @var        PropelObjectCollection|ContentAssoc[] Collection to store aggregation of ContentAssoc objects.
     205:      */
     206:     protected $collContentAssocs;
     207:     protected $collContentAssocsPartial;
     208:
     209:     /**
     210:      * @var        PropelObjectCollection|Image[] Collection to store aggregation of Image objects.
     211:      */
     212:     protected $collImages;
     213:     protected $collImagesPartial;
     214:
     215:     /**
     216:      * @var        PropelObjectCollection|Document[] Collection to store aggregation of Document objects.
     217:      */
     218:     protected $collDocuments;
     219:     protected $collDocumentsPartial;
     220:
     221:     /**
     222:      * @var        PropelObjectCollection|Accessory[] Collection to store aggregation of Accessory objects.
     223:      */
     224:     protected $collAccessorysRelatedByProductId;
     225:     protected $collAccessorysRelatedByProductIdPartial;
     226:
     227:     /**
     228:      * @var        PropelObjectCollection|Accessory[] Collection to store aggregation of Accessory objects.
     229:      */
     230:     protected $collAccessorysRelatedByAccessory;
     231:     protected $collAccessorysRelatedByAccessoryPartial;
     232:
     233:     /**
     234:      * @var        PropelObjectCollection|Rewriting[] Collection to store aggregation of Rewriting objects.
     235:      */
     236:     protected $collRewritings;
     237:     protected $collRewritingsPartial;
     238:
     239:     /**
     240:      * @var        PropelObjectCollection|ProductI18n[] Collection to store aggregation of ProductI18n objects.
     241:      */
     242:     protected $collProductI18ns;
     243:     protected $collProductI18nsPartial;
     244:
     245:     /**
     246:      * @var        PropelObjectCollection|ProductVersion[] Collection to store aggregation of ProductVersion objects.
     247:      */
     248:     protected $collProductVersions;
     249:     protected $collProductVersionsPartial;
     250:
     251:     /**
     252:      * Flag to prevent endless save loop, if this object is referenced
     253:      * by another object which falls in this transaction.
     254:      * @var        boolean
     255:      */
     256:     protected $alreadyInSave = false;
     257:
     258:     /**
     259:      * Flag to prevent endless validation loop, if this object is referenced
     260:      * by another object which falls in this transaction.
     261:      * @var        boolean
     262:      */
     263:     protected $alreadyInValidation = false;
     264:
     265:     // i18n behavior
     266:
     267:     /**
     268:      * Current locale
     269:      * @var        string
     270:      */
     271:     protected $currentLocale = 'en_EN';
     272:
     273:     /**
     274:      * Current translation objects
     275:      * @var        array[ProductI18n]
     276:      */
     277:     protected $currentTranslations;
     278:
     279:     // versionable behavior
     280:
     281:
     282:     /**
     283:      * @var bool
     284:      */
     285:     protected $enforceVersion = false;
     286:
     287:     /**
     288:      * An array of objects scheduled for deletion.
     289:      * @var     PropelObjectCollection
     290:      */
     291:     protected $productCategorysScheduledForDeletion = null;
     292:
     293:     /**
     294:      * An array of objects scheduled for deletion.
     295:      * @var     PropelObjectCollection
     296:      */
     297:     protected $featureProdsScheduledForDeletion = null;
     298:
     299:     /**
     300:      * An array of objects scheduled for deletion.
     301:      * @var     PropelObjectCollection
     302:      */
     303:     protected $stocksScheduledForDeletion = null;
     304:
     305:     /**
     306:      * An array of objects scheduled for deletion.
     307:      * @var     PropelObjectCollection
     308:      */
     309:     protected $contentAssocsScheduledForDeletion = null;
     310:
     311:     /**
     312:      * An array of objects scheduled for deletion.
     313:      * @var     PropelObjectCollection
     314:      */
     315:     protected $imagesScheduledForDeletion = null;
     316:
     317:     /**
     318:      * An array of objects scheduled for deletion.
     319:      * @var     PropelObjectCollection
     320:      */
     321:     protected $documentsScheduledForDeletion = null;
     322:
     323:     /**
     324:      * An array of objects scheduled for deletion.
     325:      * @var     PropelObjectCollection
     326:      */
     327:     protected $accessorysRelatedByProductIdScheduledForDeletion = null;
     328:
     329:     /**
     330:      * An array of objects scheduled for deletion.
     331:      * @var     PropelObjectCollection
     332:      */
     333:     protected $accessorysRelatedByAccessoryScheduledForDeletion = null;
     334:
     335:     /**
     336:      * An array of objects scheduled for deletion.
     337:      * @var     PropelObjectCollection
     338:      */
     339:     protected $rewritingsScheduledForDeletion = null;
     340:
     341:     /**
     342:      * An array of objects scheduled for deletion.
     343:      * @var     PropelObjectCollection
     344:      */
     345:     protected $productI18nsScheduledForDeletion = null;
     346:
     347:     /**
     348:      * An array of objects scheduled for deletion.
     349:      * @var     PropelObjectCollection
     350:      */
     351:     protected $productVersionsScheduledForDeletion = null;
     352:
     353:     /**
     354:      * Applies default values to this object.
     355:      * This method should be called from the object's constructor (or
     356:      * equivalent initialization method).
     357:      * @see        __construct()
     358:      */
     359:     public function applyDefaultValues()
     360:     {
     361:         $this->newness = 0;
     362:         $this->promo = 0;
     363:         $this->stock = 0;
     364:         $this->visible = 0;
     365:         $this->version = 0;
     366:     }
     367:
     368:     /**
     369:      * Initializes internal state of BaseProduct object.
     370:      * @see        applyDefaults()
     371:      */
     372:     public function __construct()
     373:     {
     374:         parent::__construct();
     375:         $this->applyDefaultValues();
     376:     }
     377:
     378:     /**
     379:      * Get the [id] column value.
     380:      *
     381:      * @return int
     382:      */
     383:     public function getId()
     384:     {
     385:         return $this->id;
     386:     }
     387:
     388:     /**
     389:      * Get the [tax_rule_id] column value.
     390:      *
     391:      * @return int
     392:      */
     393:     public function getTaxRuleId()
     394:     {
     395:         return $this->tax_rule_id;
     396:     }
     397:
     398:     /**
     399:      * Get the [ref] column value.
     400:      *
     401:      * @return string
     402:      */
     403:     public function getRef()
     404:     {
     405:         return $this->ref;
     406:     }
     407:
     408:     /**
     409:      * Get the [price] column value.
     410:      *
     411:      * @return double
     412:      */
     413:     public function getPrice()
     414:     {
     415:         return $this->price;
     416:     }
     417:
     418:     /**
     419:      * Get the [price2] column value.
     420:      *
     421:      * @return double
     422:      */
     423:     public function getPrice2()
     424:     {
     425:         return $this->price2;
     426:     }
     427:
     428:     /**
     429:      * Get the [ecotax] column value.
     430:      *
     431:      * @return double
     432:      */
     433:     public function getEcotax()
     434:     {
     435:         return $this->ecotax;
     436:     }
     437:
     438:     /**
     439:      * Get the [newness] column value.
     440:      *
     441:      * @return int
     442:      */
     443:     public function getNewness()
     444:     {
     445:         return $this->newness;
     446:     }
     447:
     448:     /**
     449:      * Get the [promo] column value.
     450:      *
     451:      * @return int
     452:      */
     453:     public function getPromo()
     454:     {
     455:         return $this->promo;
     456:     }
     457:
     458:     /**
     459:      * Get the [stock] column value.
     460:      *
     461:      * @return int
     462:      */
     463:     public function getStock()
     464:     {
     465:         return $this->stock;
     466:     }
     467:
     468:     /**
     469:      * Get the [visible] column value.
     470:      *
     471:      * @return int
     472:      */
     473:     public function getVisible()
     474:     {
     475:         return $this->visible;
     476:     }
     477:
     478:     /**
     479:      * Get the [weight] column value.
     480:      *
     481:      * @return double
     482:      */
     483:     public function getWeight()
     484:     {
     485:         return $this->weight;
     486:     }
     487:
     488:     /**
     489:      * Get the [position] column value.
     490:      *
     491:      * @return int
     492:      */
     493:     public function getPosition()
     494:     {
     495:         return $this->position;
     496:     }
     497:
     498:     /**
     499:      * Get the [optionally formatted] temporal [created_at] column value.
     500:      *
     501:      *
     502:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     503:      *               If format is null, then the raw DateTime object will be returned.
     504:      * @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
     505:      * @throws PropelException - if unable to parse/validate the date/time value.
     506:      */
     507:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     508:     {
     509:         if ($this->created_at === null) {
     510:             return null;
     511:         }
     512:
     513:         if ($this->created_at === '0000-00-00 00:00:00') {
     514:             // while technically this is not a default value of null,
     515:             // this seems to be closest in meaning.
     516:             return null;
     517:         } else {
     518:             try {
     519:                 $dt = new DateTime($this->created_at);
     520:             } catch (Exception $x) {
     521:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     522:             }
     523:         }
     524:
     525:         if ($format === null) {
     526:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     527:             return $dt;
     528:         } elseif (strpos($format, '%') !== false) {
     529:             return strftime($format, $dt->format('U'));
     530:         } else {
     531:             return $dt->format($format);
     532:         }
     533:     }
     534:
     535:     /**
     536:      * Get the [optionally formatted] temporal [updated_at] column value.
     537:      *
     538:      *
     539:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     540:      *               If format is null, then the raw DateTime object will be returned.
     541:      * @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
     542:      * @throws PropelException - if unable to parse/validate the date/time value.
     543:      */
     544:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     545:     {
     546:         if ($this->updated_at === null) {
     547:             return null;
     548:         }
     549:
     550:         if ($this->updated_at === '0000-00-00 00:00:00') {
     551:             // while technically this is not a default value of null,
     552:             // this seems to be closest in meaning.
     553:             return null;
     554:         } else {
     555:             try {
     556:                 $dt = new DateTime($this->updated_at);
     557:             } catch (Exception $x) {
     558:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     559:             }
     560:         }
     561:
     562:         if ($format === null) {
     563:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     564:             return $dt;
     565:         } elseif (strpos($format, '%') !== false) {
     566:             return strftime($format, $dt->format('U'));
     567:         } else {
     568:             return $dt->format($format);
     569:         }
     570:     }
     571:
     572:     /**
     573:      * Get the [version] column value.
     574:      *
     575:      * @return int
     576:      */
     577:     public function getVersion()
     578:     {
     579:         return $this->version;
     580:     }
     581:
     582:     /**
     583:      * Get the [optionally formatted] temporal [version_created_at] column value.
     584:      *
     585:      *
     586:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     587:      *               If format is null, then the raw DateTime object will be returned.
     588:      * @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
     589:      * @throws PropelException - if unable to parse/validate the date/time value.
     590:      */
     591:     public function getVersionCreatedAt($format = 'Y-m-d H:i:s')
     592:     {
     593:         if ($this->version_created_at === null) {
     594:             return null;
     595:         }
     596:
     597:         if ($this->version_created_at === '0000-00-00 00:00:00') {
     598:             // while technically this is not a default value of null,
     599:             // this seems to be closest in meaning.
     600:             return null;
     601:         } else {
     602:             try {
     603:                 $dt = new DateTime($this->version_created_at);
     604:             } catch (Exception $x) {
     605:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->version_created_at, true), $x);
     606:             }
     607:         }
     608:
     609:         if ($format === null) {
     610:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     611:             return $dt;
     612:         } elseif (strpos($format, '%') !== false) {
     613:             return strftime($format, $dt->format('U'));
     614:         } else {
     615:             return $dt->format($format);
     616:         }
     617:     }
     618:
     619:     /**
     620:      * Get the [version_created_by] column value.
     621:      *
     622:      * @return string
     623:      */
     624:     public function getVersionCreatedBy()
     625:     {
     626:         return $this->version_created_by;
     627:     }
     628:
     629:     /**
     630:      * Set the value of [id] column.
     631:      *
     632:      * @param int $v new value
     633:      * @return Product The current object (for fluent API support)
     634:      */
     635:     public function setId($v)
     636:     {
     637:         if ($v !== null) {
     638:             $v = (int) $v;
     639:         }
     640:
     641:         if ($this->id !== $v) {
     642:             $this->id = $v;
     643:             $this->modifiedColumns[] = ProductPeer::ID;
     644:         }
     645:
     646:
     647:         return $this;
     648:     } // setId()
     649:
     650:     /**
     651:      * Set the value of [tax_rule_id] column.
     652:      *
     653:      * @param int $v new value
     654:      * @return Product The current object (for fluent API support)
     655:      */
     656:     public function setTaxRuleId($v)
     657:     {
     658:         if ($v !== null) {
     659:             $v = (int) $v;
     660:         }
     661:
     662:         if ($this->tax_rule_id !== $v) {
     663:             $this->tax_rule_id = $v;
     664:             $this->modifiedColumns[] = ProductPeer::TAX_RULE_ID;
     665:         }
     666:
     667:         if ($this->aTaxRule !== null && $this->aTaxRule->getId() !== $v) {
     668:             $this->aTaxRule = null;
     669:         }
     670:
     671:
     672:         return $this;
     673:     } // setTaxRuleId()
     674:
     675:     /**
     676:      * Set the value of [ref] column.
     677:      *
     678:      * @param string $v new value
     679:      * @return Product The current object (for fluent API support)
     680:      */
     681:     public function setRef($v)
     682:     {
     683:         if ($v !== null) {
     684:             $v = (string) $v;
     685:         }
     686:
     687:         if ($this->ref !== $v) {
     688:             $this->ref = $v;
     689:             $this->modifiedColumns[] = ProductPeer::REF;
     690:         }
     691:
     692:
     693:         return $this;
     694:     } // setRef()
     695:
     696:     /**
     697:      * Set the value of [price] column.
     698:      *
     699:      * @param double $v new value
     700:      * @return Product The current object (for fluent API support)
     701:      */
     702:     public function setPrice($v)
     703:     {
     704:         if ($v !== null) {
     705:             $v = (double) $v;
     706:         }
     707:
     708:         if ($this->price !== $v) {
     709:             $this->price = $v;
     710:             $this->modifiedColumns[] = ProductPeer::PRICE;
     711:         }
     712:
     713:
     714:         return $this;
     715:     } // setPrice()
     716:
     717:     /**
     718:      * Set the value of [price2] column.
     719:      *
     720:      * @param double $v new value
     721:      * @return Product The current object (for fluent API support)
     722:      */
     723:     public function setPrice2($v)
     724:     {
     725:         if ($v !== null) {
     726:             $v = (double) $v;
     727:         }
     728:
     729:         if ($this->price2 !== $v) {
     730:             $this->price2 = $v;
     731:             $this->modifiedColumns[] = ProductPeer::PRICE2;
     732:         }
     733:
     734:
     735:         return $this;
     736:     } // setPrice2()
     737:
     738:     /**
     739:      * Set the value of [ecotax] column.
     740:      *
     741:      * @param double $v new value
     742:      * @return Product The current object (for fluent API support)
     743:      */
     744:     public function setEcotax($v)
     745:     {
     746:         if ($v !== null) {
     747:             $v = (double) $v;
     748:         }
     749:
     750:         if ($this->ecotax !== $v) {
     751:             $this->ecotax = $v;
     752:             $this->modifiedColumns[] = ProductPeer::ECOTAX;
     753:         }
     754:
     755:
     756:         return $this;
     757:     } // setEcotax()
     758:
     759:     /**
     760:      * Set the value of [newness] column.
     761:      *
     762:      * @param int $v new value
     763:      * @return Product The current object (for fluent API support)
     764:      */
     765:     public function setNewness($v)
     766:     {
     767:         if ($v !== null) {
     768:             $v = (int) $v;
     769:         }
     770:
     771:         if ($this->newness !== $v) {
     772:             $this->newness = $v;
     773:             $this->modifiedColumns[] = ProductPeer::NEWNESS;
     774:         }
     775:
     776:
     777:         return $this;
     778:     } // setNewness()
     779:
     780:     /**
     781:      * Set the value of [promo] column.
     782:      *
     783:      * @param int $v new value
     784:      * @return Product The current object (for fluent API support)
     785:      */
     786:     public function setPromo($v)
     787:     {
     788:         if ($v !== null) {
     789:             $v = (int) $v;
     790:         }
     791:
     792:         if ($this->promo !== $v) {
     793:             $this->promo = $v;
     794:             $this->modifiedColumns[] = ProductPeer::PROMO;
     795:         }
     796:
     797:
     798:         return $this;
     799:     } // setPromo()
     800:
     801:     /**
     802:      * Set the value of [stock] column.
     803:      *
     804:      * @param int $v new value
     805:      * @return Product The current object (for fluent API support)
     806:      */
     807:     public function setStock($v)
     808:     {
     809:         if ($v !== null) {
     810:             $v = (int) $v;
     811:         }
     812:
     813:         if ($this->stock !== $v) {
     814:             $this->stock = $v;
     815:             $this->modifiedColumns[] = ProductPeer::STOCK;
     816:         }
     817:
     818:
     819:         return $this;
     820:     } // setStock()
     821:
     822:     /**
     823:      * Set the value of [visible] column.
     824:      *
     825:      * @param int $v new value
     826:      * @return Product The current object (for fluent API support)
     827:      */
     828:     public function setVisible($v)
     829:     {
     830:         if ($v !== null) {
     831:             $v = (int) $v;
     832:         }
     833:
     834:         if ($this->visible !== $v) {
     835:             $this->visible = $v;
     836:             $this->modifiedColumns[] = ProductPeer::VISIBLE;
     837:         }
     838:
     839:
     840:         return $this;
     841:     } // setVisible()
     842:
     843:     /**
     844:      * Set the value of [weight] column.
     845:      *
     846:      * @param double $v new value
     847:      * @return Product The current object (for fluent API support)
     848:      */
     849:     public function setWeight($v)
     850:     {
     851:         if ($v !== null) {
     852:             $v = (double) $v;
     853:         }
     854:
     855:         if ($this->weight !== $v) {
     856:             $this->weight = $v;
     857:             $this->modifiedColumns[] = ProductPeer::WEIGHT;
     858:         }
     859:
     860:
     861:         return $this;
     862:     } // setWeight()
     863:
     864:     /**
     865:      * Set the value of [position] column.
     866:      *
     867:      * @param int $v new value
     868:      * @return Product The current object (for fluent API support)
     869:      */
     870:     public function setPosition($v)
     871:     {
     872:         if ($v !== null) {
     873:             $v = (int) $v;
     874:         }
     875:
     876:         if ($this->position !== $v) {
     877:             $this->position = $v;
     878:             $this->modifiedColumns[] = ProductPeer::POSITION;
     879:         }
     880:
     881:
     882:         return $this;
     883:     } // setPosition()
     884:
     885:     /**
     886:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     887:      *
     888:      * @param mixed $v string, integer (timestamp), or DateTime value.
     889:      *               Empty strings are treated as null.
     890:      * @return Product The current object (for fluent API support)
     891:      */
     892:     public function setCreatedAt($v)
     893:     {
     894:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     895:         if ($this->created_at !== null || $dt !== null) {
     896:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     897:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     898:             if ($currentDateAsString !== $newDateAsString) {
     899:                 $this->created_at = $newDateAsString;
     900:                 $this->modifiedColumns[] = ProductPeer::CREATED_AT;
     901:             }
     902:         } // if either are not null
     903:
     904:
     905:         return $this;
     906:     } // setCreatedAt()
     907:
     908:     /**
     909:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     910:      *
     911:      * @param mixed $v string, integer (timestamp), or DateTime value.
     912:      *               Empty strings are treated as null.
     913:      * @return Product The current object (for fluent API support)
     914:      */
     915:     public function setUpdatedAt($v)
     916:     {
     917:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     918:         if ($this->updated_at !== null || $dt !== null) {
     919:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     920:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     921:             if ($currentDateAsString !== $newDateAsString) {
     922:                 $this->updated_at = $newDateAsString;
     923:                 $this->modifiedColumns[] = ProductPeer::UPDATED_AT;
     924:             }
     925:         } // if either are not null
     926:
     927:
     928:         return $this;
     929:     } // setUpdatedAt()
     930:
     931:     /**
     932:      * Set the value of [version] column.
     933:      *
     934:      * @param int $v new value
     935:      * @return Product The current object (for fluent API support)
     936:      */
     937:     public function setVersion($v)
     938:     {
     939:         if ($v !== null) {
     940:             $v = (int) $v;
     941:         }
     942:
     943:         if ($this->version !== $v) {
     944:             $this->version = $v;
     945:             $this->modifiedColumns[] = ProductPeer::VERSION;
     946:         }
     947:
     948:
     949:         return $this;
     950:     } // setVersion()
     951:
     952:     /**
     953:      * Sets the value of [version_created_at] column to a normalized version of the date/time value specified.
     954:      *
     955:      * @param mixed $v string, integer (timestamp), or DateTime value.
     956:      *               Empty strings are treated as null.
     957:      * @return Product The current object (for fluent API support)
     958:      */
     959:     public function setVersionCreatedAt($v)
     960:     {
     961:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     962:         if ($this->version_created_at !== null || $dt !== null) {
     963:             $currentDateAsString = ($this->version_created_at !== null && $tmpDt = new DateTime($this->version_created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     964:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     965:             if ($currentDateAsString !== $newDateAsString) {
     966:                 $this->version_created_at = $newDateAsString;
     967:                 $this->modifiedColumns[] = ProductPeer::VERSION_CREATED_AT;
     968:             }
     969:         } // if either are not null
     970:
     971:
     972:         return $this;
     973:     } // setVersionCreatedAt()
     974:
     975:     /**
     976:      * Set the value of [version_created_by] column.
     977:      *
     978:      * @param string $v new value
     979:      * @return Product The current object (for fluent API support)
     980:      */
     981:     public function setVersionCreatedBy($v)
     982:     {
     983:         if ($v !== null) {
     984:             $v = (string) $v;
     985:         }
     986:
     987:         if ($this->version_created_by !== $v) {
     988:             $this->version_created_by = $v;
     989:             $this->modifiedColumns[] = ProductPeer::VERSION_CREATED_BY;
     990:         }
     991:
     992:
     993:         return $this;
     994:     } // setVersionCreatedBy()
     995:
     996:     /**
     997:      * Indicates whether the columns in this object are only set to default values.
     998:      *
     999:      * This method can be used in conjunction with isModified() to indicate whether an object is both
    1000:      * modified _and_ has some values set which are non-default.
    1001:      *
    1002:      * @return boolean Whether the columns in this object are only been set with default values.
    1003:      */
    1004:     public function hasOnlyDefaultValues()
    1005:     {
    1006:             if ($this->newness !== 0) {
    1007:                 return false;
    1008:             }
    1009:
    1010:             if ($this->promo !== 0) {
    1011:                 return false;
    1012:             }
    1013:
    1014:             if ($this->stock !== 0) {
    1015:                 return false;
    1016:             }
    1017:
    1018:             if ($this->visible !== 0) {
    1019:                 return false;
    1020:             }
    1021:
    1022:             if ($this->version !== 0) {
    1023:                 return false;
    1024:             }
    1025:
    1026:         // otherwise, everything was equal, so return true
    1027:         return true;
    1028:     } // hasOnlyDefaultValues()
    1029:
    1030:     /**
    1031:      * Hydrates (populates) the object variables with values from the database resultset.
    1032:      *
    1033:      * An offset (0-based "start column") is specified so that objects can be hydrated
    1034:      * with a subset of the columns in the resultset rows.  This is needed, for example,
    1035:      * for results of JOIN queries where the resultset row includes columns from two or
    1036:      * more tables.
    1037:      *
    1038:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
    1039:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
    1040:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
    1041:      * @return int             next starting column
    1042:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
    1043:      */
    1044:     public function hydrate($row, $startcol = 0, $rehydrate = false)
    1045:     {
    1046:         try {
    1047:
    1048:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
    1049:             $this->tax_rule_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
    1050:             $this->ref = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
    1051:             $this->price = ($row[$startcol + 3] !== null) ? (double) $row[$startcol + 3] : null;
    1052:             $this->price2 = ($row[$startcol + 4] !== null) ? (double) $row[$startcol + 4] : null;
    1053:             $this->ecotax = ($row[$startcol + 5] !== null) ? (double) $row[$startcol + 5] : null;
    1054:             $this->newness = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
    1055:             $this->promo = ($row[$startcol + 7] !== null) ? (int) $row[$startcol + 7] : null;
    1056:             $this->stock = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
    1057:             $this->visible = ($row[$startcol + 9] !== null) ? (int) $row[$startcol + 9] : null;
    1058:             $this->weight = ($row[$startcol + 10] !== null) ? (double) $row[$startcol + 10] : null;
    1059:             $this->position = ($row[$startcol + 11] !== null) ? (int) $row[$startcol + 11] : null;
    1060:             $this->created_at = ($row[$startcol + 12] !== null) ? (string) $row[$startcol + 12] : null;
    1061:             $this->updated_at = ($row[$startcol + 13] !== null) ? (string) $row[$startcol + 13] : null;
    1062:             $this->version = ($row[$startcol + 14] !== null) ? (int) $row[$startcol + 14] : null;
    1063:             $this->version_created_at = ($row[$startcol + 15] !== null) ? (string) $row[$startcol + 15] : null;
    1064:             $this->version_created_by = ($row[$startcol + 16] !== null) ? (string) $row[$startcol + 16] : null;
    1065:             $this->resetModified();
    1066:
    1067:             $this->setNew(false);
    1068:
    1069:             if ($rehydrate) {
    1070:                 $this->ensureConsistency();
    1071:             }
    1072:
    1073:             return $startcol + 17; // 17 = ProductPeer::NUM_HYDRATE_COLUMNS.
    1074:
    1075:         } catch (Exception $e) {
    1076:             throw new PropelException("Error populating Product object", $e);
    1077:         }
    1078:     }
    1079:
    1080:     /**
    1081:      * Checks and repairs the internal consistency of the object.
    1082:      *
    1083:      * This method is executed after an already-instantiated object is re-hydrated
    1084:      * from the database.  It exists to check any foreign keys to make sure that
    1085:      * the objects related to the current object are correct based on foreign key.
    1086:      *
    1087:      * You can override this method in the stub class, but you should always invoke
    1088:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
    1089:      * in case your model changes.
    1090:      *
    1091:      * @throws PropelException
    1092:      */
    1093:     public function ensureConsistency()
    1094:     {
    1095:
    1096:         if ($this->aTaxRule !== null && $this->tax_rule_id !== $this->aTaxRule->getId()) {
    1097:             $this->aTaxRule = null;
    1098:         }
    1099:     } // ensureConsistency
    1100:
    1101:     /**
    1102:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
    1103:      *
    1104:      * This will only work if the object has been saved and has a valid primary key set.
    1105:      *
    1106:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
    1107:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
    1108:      * @return void
    1109:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
    1110:      */
    1111:     public function reload($deep = false, PropelPDO $con = null)
    1112:     {
    1113:         if ($this->isDeleted()) {
    1114:             throw new PropelException("Cannot reload a deleted object.");
    1115:         }
    1116:
    1117:         if ($this->isNew()) {
    1118:             throw new PropelException("Cannot reload an unsaved object.");
    1119:         }
    1120:
    1121:         if ($con === null) {
    1122:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1123:         }
    1124:
    1125:         // We don't need to alter the object instance pool; we're just modifying this instance
    1126:         // already in the pool.
    1127:
    1128:         $stmt = ProductPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
    1129:         $row = $stmt->fetch(PDO::FETCH_NUM);
    1130:         $stmt->closeCursor();
    1131:         if (!$row) {
    1132:             throw new PropelException('Cannot find matching row in the database to reload object values.');
    1133:         }
    1134:         $this->hydrate($row, 0, true); // rehydrate
    1135:
    1136:         if ($deep) {  // also de-associate any related objects?
    1137:
    1138:             $this->aTaxRule = null;
    1139:             $this->collProductCategorys = null;
    1140:
    1141:             $this->collFeatureProds = null;
    1142:
    1143:             $this->collStocks = null;
    1144:
    1145:             $this->collContentAssocs = null;
    1146:
    1147:             $this->collImages = null;
    1148:
    1149:             $this->collDocuments = null;
    1150:
    1151:             $this->collAccessorysRelatedByProductId = null;
    1152:
    1153:             $this->collAccessorysRelatedByAccessory = null;
    1154:
    1155:             $this->collRewritings = null;
    1156:
    1157:             $this->collProductI18ns = null;
    1158:
    1159:             $this->collProductVersions = null;
    1160:
    1161:         } // if (deep)
    1162:     }
    1163:
    1164:     /**
    1165:      * Removes this object from datastore and sets delete attribute.
    1166:      *
    1167:      * @param PropelPDO $con
    1168:      * @return void
    1169:      * @throws PropelException
    1170:      * @throws Exception
    1171:      * @see        BaseObject::setDeleted()
    1172:      * @see        BaseObject::isDeleted()
    1173:      */
    1174:     public function delete(PropelPDO $con = null)
    1175:     {
    1176:         if ($this->isDeleted()) {
    1177:             throw new PropelException("This object has already been deleted.");
    1178:         }
    1179:
    1180:         if ($con === null) {
    1181:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1182:         }
    1183:
    1184:         $con->beginTransaction();
    1185:         try {
    1186:             $deleteQuery = ProductQuery::create()
    1187:                 ->filterByPrimaryKey($this->getPrimaryKey());
    1188:             $ret = $this->preDelete($con);
    1189:             if ($ret) {
    1190:                 $deleteQuery->delete($con);
    1191:                 $this->postDelete($con);
    1192:                 $con->commit();
    1193:                 $this->setDeleted(true);
    1194:             } else {
    1195:                 $con->commit();
    1196:             }
    1197:         } catch (Exception $e) {
    1198:             $con->rollBack();
    1199:             throw $e;
    1200:         }
    1201:     }
    1202:
    1203:     /**
    1204:      * Persists this object to the database.
    1205:      *
    1206:      * If the object is new, it inserts it; otherwise an update is performed.
    1207:      * All modified related objects will also be persisted in the doSave()
    1208:      * method.  This method wraps all precipitate database operations in a
    1209:      * single transaction.
    1210:      *
    1211:      * @param PropelPDO $con
    1212:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
    1213:      * @throws PropelException
    1214:      * @throws Exception
    1215:      * @see        doSave()
    1216:      */
    1217:     public function save(PropelPDO $con = null)
    1218:     {
    1219:         if ($this->isDeleted()) {
    1220:             throw new PropelException("You cannot save an object that has been deleted.");
    1221:         }
    1222:
    1223:         if ($con === null) {
    1224:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1225:         }
    1226:
    1227:         $con->beginTransaction();
    1228:         $isInsert = $this->isNew();
    1229:         try {
    1230:             $ret = $this->preSave($con);
    1231:             // versionable behavior
    1232:             if ($this->isVersioningNecessary()) {
    1233:                 $this->setVersion($this->isNew() ? 1 : $this->getLastVersionNumber($con) + 1);
    1234:                 if (!$this->isColumnModified(ProductPeer::VERSION_CREATED_AT)) {
    1235:                     $this->setVersionCreatedAt(time());
    1236:                 }
    1237:                 $createVersion = true; // for postSave hook
    1238:             }
    1239:             if ($isInsert) {
    1240:                 $ret = $ret && $this->preInsert($con);
    1241:                 // timestampable behavior
    1242:                 if (!$this->isColumnModified(ProductPeer::CREATED_AT)) {
    1243:                     $this->setCreatedAt(time());
    1244:                 }
    1245:                 if (!$this->isColumnModified(ProductPeer::UPDATED_AT)) {
    1246:                     $this->setUpdatedAt(time());
    1247:                 }
    1248:             } else {
    1249:                 $ret = $ret && $this->preUpdate($con);
    1250:                 // timestampable behavior
    1251:                 if ($this->isModified() && !$this->isColumnModified(ProductPeer::UPDATED_AT)) {
    1252:                     $this->setUpdatedAt(time());
    1253:                 }
    1254:             }
    1255:             if ($ret) {
    1256:                 $affectedRows = $this->doSave($con);
    1257:                 if ($isInsert) {
    1258:                     $this->postInsert($con);
    1259:                 } else {
    1260:                     $this->postUpdate($con);
    1261:                 }
    1262:                 $this->postSave($con);
    1263:                 // versionable behavior
    1264:                 if (isset($createVersion)) {
    1265:                     $this->addVersion($con);
    1266:                 }
    1267:                 ProductPeer::addInstanceToPool($this);
    1268:             } else {
    1269:                 $affectedRows = 0;
    1270:             }
    1271:             $con->commit();
    1272:
    1273:             return $affectedRows;
    1274:         } catch (Exception $e) {
    1275:             $con->rollBack();
    1276:             throw $e;
    1277:         }
    1278:     }
    1279:
    1280:     /**
    1281:      * Performs the work of inserting or updating the row in the database.
    1282:      *
    1283:      * If the object is new, it inserts it; otherwise an update is performed.
    1284:      * All related objects are also updated in this method.
    1285:      *
    1286:      * @param PropelPDO $con
    1287:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
    1288:      * @throws PropelException
    1289:      * @see        save()
    1290:      */
    1291:     protected function doSave(PropelPDO $con)
    1292:     {
    1293:         $affectedRows = 0; // initialize var to track total num of affected rows
    1294:         if (!$this->alreadyInSave) {
    1295:             $this->alreadyInSave = true;
    1296:
    1297:             // We call the save method on the following object(s) if they
    1298:             // were passed to this object by their coresponding set
    1299:             // method.  This object relates to these object(s) by a
    1300:             // foreign key reference.
    1301:
    1302:             if ($this->aTaxRule !== null) {
    1303:                 if ($this->aTaxRule->isModified() || $this->aTaxRule->isNew()) {
    1304:                     $affectedRows += $this->aTaxRule->save($con);
    1305:                 }
    1306:                 $this->setTaxRule($this->aTaxRule);
    1307:             }
    1308:
    1309:             if ($this->isNew() || $this->isModified()) {
    1310:                 // persist changes
    1311:                 if ($this->isNew()) {
    1312:                     $this->doInsert($con);
    1313:                 } else {
    1314:                     $this->doUpdate($con);
    1315:                 }
    1316:                 $affectedRows += 1;
    1317:                 $this->resetModified();
    1318:             }
    1319:
    1320:             if ($this->productCategorysScheduledForDeletion !== null) {
    1321:                 if (!$this->productCategorysScheduledForDeletion->isEmpty()) {
    1322:                     ProductCategoryQuery::create()
    1323:                         ->filterByPrimaryKeys($this->productCategorysScheduledForDeletion->getPrimaryKeys(false))
    1324:                         ->delete($con);
    1325:                     $this->productCategorysScheduledForDeletion = null;
    1326:                 }
    1327:             }
    1328:
    1329:             if ($this->collProductCategorys !== null) {
    1330:                 foreach ($this->collProductCategorys as $referrerFK) {
    1331:                     if (!$referrerFK->isDeleted()) {
    1332:                         $affectedRows += $referrerFK->save($con);
    1333:                     }
    1334:                 }
    1335:             }
    1336:
    1337:             if ($this->featureProdsScheduledForDeletion !== null) {
    1338:                 if (!$this->featureProdsScheduledForDeletion->isEmpty()) {
    1339:                     FeatureProdQuery::create()
    1340:                         ->filterByPrimaryKeys($this->featureProdsScheduledForDeletion->getPrimaryKeys(false))
    1341:                         ->delete($con);
    1342:                     $this->featureProdsScheduledForDeletion = null;
    1343:                 }
    1344:             }
    1345:
    1346:             if ($this->collFeatureProds !== null) {
    1347:                 foreach ($this->collFeatureProds as $referrerFK) {
    1348:                     if (!$referrerFK->isDeleted()) {
    1349:                         $affectedRows += $referrerFK->save($con);
    1350:                     }
    1351:                 }
    1352:             }
    1353:
    1354:             if ($this->stocksScheduledForDeletion !== null) {
    1355:                 if (!$this->stocksScheduledForDeletion->isEmpty()) {
    1356:                     StockQuery::create()
    1357:                         ->filterByPrimaryKeys($this->stocksScheduledForDeletion->getPrimaryKeys(false))
    1358:                         ->delete($con);
    1359:                     $this->stocksScheduledForDeletion = null;
    1360:                 }
    1361:             }
    1362:
    1363:             if ($this->collStocks !== null) {
    1364:                 foreach ($this->collStocks as $referrerFK) {
    1365:                     if (!$referrerFK->isDeleted()) {
    1366:                         $affectedRows += $referrerFK->save($con);
    1367:                     }
    1368:                 }
    1369:             }
    1370:
    1371:             if ($this->contentAssocsScheduledForDeletion !== null) {
    1372:                 if (!$this->contentAssocsScheduledForDeletion->isEmpty()) {
    1373:                     foreach ($this->contentAssocsScheduledForDeletion as $contentAssoc) {
    1374:                         // need to save related object because we set the relation to null
    1375:                         $contentAssoc->save($con);
    1376:                     }
    1377:                     $this->contentAssocsScheduledForDeletion = null;
    1378:                 }
    1379:             }
    1380:
    1381:             if ($this->collContentAssocs !== null) {
    1382:                 foreach ($this->collContentAssocs as $referrerFK) {
    1383:                     if (!$referrerFK->isDeleted()) {
    1384:                         $affectedRows += $referrerFK->save($con);
    1385:                     }
    1386:                 }
    1387:             }
    1388:
    1389:             if ($this->imagesScheduledForDeletion !== null) {
    1390:                 if (!$this->imagesScheduledForDeletion->isEmpty()) {
    1391:                     foreach ($this->imagesScheduledForDeletion as $image) {
    1392:                         // need to save related object because we set the relation to null
    1393:                         $image->save($con);
    1394:                     }
    1395:                     $this->imagesScheduledForDeletion = null;
    1396:                 }
    1397:             }
    1398:
    1399:             if ($this->collImages !== null) {
    1400:                 foreach ($this->collImages as $referrerFK) {
    1401:                     if (!$referrerFK->isDeleted()) {
    1402:                         $affectedRows += $referrerFK->save($con);
    1403:                     }
    1404:                 }
    1405:             }
    1406:
    1407:             if ($this->documentsScheduledForDeletion !== null) {
    1408:                 if (!$this->documentsScheduledForDeletion->isEmpty()) {
    1409:                     foreach ($this->documentsScheduledForDeletion as $document) {
    1410:                         // need to save related object because we set the relation to null
    1411:                         $document->save($con);
    1412:                     }
    1413:                     $this->documentsScheduledForDeletion = null;
    1414:                 }
    1415:             }
    1416:
    1417:             if ($this->collDocuments !== null) {
    1418:                 foreach ($this->collDocuments as $referrerFK) {
    1419:                     if (!$referrerFK->isDeleted()) {
    1420:                         $affectedRows += $referrerFK->save($con);
    1421:                     }
    1422:                 }
    1423:             }
    1424:
    1425:             if ($this->accessorysRelatedByProductIdScheduledForDeletion !== null) {
    1426:                 if (!$this->accessorysRelatedByProductIdScheduledForDeletion->isEmpty()) {
    1427:                     AccessoryQuery::create()
    1428:                         ->filterByPrimaryKeys($this->accessorysRelatedByProductIdScheduledForDeletion->getPrimaryKeys(false))
    1429:                         ->delete($con);
    1430:                     $this->accessorysRelatedByProductIdScheduledForDeletion = null;
    1431:                 }
    1432:             }
    1433:
    1434:             if ($this->collAccessorysRelatedByProductId !== null) {
    1435:                 foreach ($this->collAccessorysRelatedByProductId as $referrerFK) {
    1436:                     if (!$referrerFK->isDeleted()) {
    1437:                         $affectedRows += $referrerFK->save($con);
    1438:                     }
    1439:                 }
    1440:             }
    1441:
    1442:             if ($this->accessorysRelatedByAccessoryScheduledForDeletion !== null) {
    1443:                 if (!$this->accessorysRelatedByAccessoryScheduledForDeletion->isEmpty()) {
    1444:                     AccessoryQuery::create()
    1445:                         ->filterByPrimaryKeys($this->accessorysRelatedByAccessoryScheduledForDeletion->getPrimaryKeys(false))
    1446:                         ->delete($con);
    1447:                     $this->accessorysRelatedByAccessoryScheduledForDeletion = null;
    1448:                 }
    1449:             }
    1450:
    1451:             if ($this->collAccessorysRelatedByAccessory !== null) {
    1452:                 foreach ($this->collAccessorysRelatedByAccessory as $referrerFK) {
    1453:                     if (!$referrerFK->isDeleted()) {
    1454:                         $affectedRows += $referrerFK->save($con);
    1455:                     }
    1456:                 }
    1457:             }
    1458:
    1459:             if ($this->rewritingsScheduledForDeletion !== null) {
    1460:                 if (!$this->rewritingsScheduledForDeletion->isEmpty()) {
    1461:                     foreach ($this->rewritingsScheduledForDeletion as $rewriting) {
    1462:                         // need to save related object because we set the relation to null
    1463:                         $rewriting->save($con);
    1464:                     }
    1465:                     $this->rewritingsScheduledForDeletion = null;
    1466:                 }
    1467:             }
    1468:
    1469:             if ($this->collRewritings !== null) {
    1470:                 foreach ($this->collRewritings as $referrerFK) {
    1471:                     if (!$referrerFK->isDeleted()) {
    1472:                         $affectedRows += $referrerFK->save($con);
    1473:                     }
    1474:                 }
    1475:             }
    1476:
    1477:             if ($this->productI18nsScheduledForDeletion !== null) {
    1478:                 if (!$this->productI18nsScheduledForDeletion->isEmpty()) {
    1479:                     ProductI18nQuery::create()
    1480:                         ->filterByPrimaryKeys($this->productI18nsScheduledForDeletion->getPrimaryKeys(false))
    1481:                         ->delete($con);
    1482:                     $this->productI18nsScheduledForDeletion = null;
    1483:                 }
    1484:             }
    1485:
    1486:             if ($this->collProductI18ns !== null) {
    1487:                 foreach ($this->collProductI18ns as $referrerFK) {
    1488:                     if (!$referrerFK->isDeleted()) {
    1489:                         $affectedRows += $referrerFK->save($con);
    1490:                     }
    1491:                 }
    1492:             }
    1493:
    1494:             if ($this->productVersionsScheduledForDeletion !== null) {
    1495:                 if (!$this->productVersionsScheduledForDeletion->isEmpty()) {
    1496:                     ProductVersionQuery::create()
    1497:                         ->filterByPrimaryKeys($this->productVersionsScheduledForDeletion->getPrimaryKeys(false))
    1498:                         ->delete($con);
    1499:                     $this->productVersionsScheduledForDeletion = null;
    1500:                 }
    1501:             }
    1502:
    1503:             if ($this->collProductVersions !== null) {
    1504:                 foreach ($this->collProductVersions as $referrerFK) {
    1505:                     if (!$referrerFK->isDeleted()) {
    1506:                         $affectedRows += $referrerFK->save($con);
    1507:                     }
    1508:                 }
    1509:             }
    1510:
    1511:             $this->alreadyInSave = false;
    1512:
    1513:         }
    1514:
    1515:         return $affectedRows;
    1516:     } // doSave()
    1517:
    1518:     /**
    1519:      * Insert the row in the database.
    1520:      *
    1521:      * @param PropelPDO $con
    1522:      *
    1523:      * @throws PropelException
    1524:      * @see        doSave()
    1525:      */
    1526:     protected function doInsert(PropelPDO $con)
    1527:     {
    1528:         $modifiedColumns = array();
    1529:         $index = 0;
    1530:
    1531:         $this->modifiedColumns[] = ProductPeer::ID;
    1532:         if (null !== $this->id) {
    1533:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductPeer::ID . ')');
    1534:         }
    1535:
    1536:          // check the columns in natural order for more readable SQL queries
    1537:         if ($this->isColumnModified(ProductPeer::ID)) {
    1538:             $modifiedColumns[':p' . $index++]  = '`ID`';
    1539:         }
    1540:         if ($this->isColumnModified(ProductPeer::TAX_RULE_ID)) {
    1541:             $modifiedColumns[':p' . $index++]  = '`TAX_RULE_ID`';
    1542:         }
    1543:         if ($this->isColumnModified(ProductPeer::REF)) {
    1544:             $modifiedColumns[':p' . $index++]  = '`REF`';
    1545:         }
    1546:         if ($this->isColumnModified(ProductPeer::PRICE)) {
    1547:             $modifiedColumns[':p' . $index++]  = '`PRICE`';
    1548:         }
    1549:         if ($this->isColumnModified(ProductPeer::PRICE2)) {
    1550:             $modifiedColumns[':p' . $index++]  = '`PRICE2`';
    1551:         }
    1552:         if ($this->isColumnModified(ProductPeer::ECOTAX)) {
    1553:             $modifiedColumns[':p' . $index++]  = '`ECOTAX`';
    1554:         }
    1555:         if ($this->isColumnModified(ProductPeer::NEWNESS)) {
    1556:             $modifiedColumns[':p' . $index++]  = '`NEWNESS`';
    1557:         }
    1558:         if ($this->isColumnModified(ProductPeer::PROMO)) {
    1559:             $modifiedColumns[':p' . $index++]  = '`PROMO`';
    1560:         }
    1561:         if ($this->isColumnModified(ProductPeer::STOCK)) {
    1562:             $modifiedColumns[':p' . $index++]  = '`STOCK`';
    1563:         }
    1564:         if ($this->isColumnModified(ProductPeer::VISIBLE)) {
    1565:             $modifiedColumns[':p' . $index++]  = '`VISIBLE`';
    1566:         }
    1567:         if ($this->isColumnModified(ProductPeer::WEIGHT)) {
    1568:             $modifiedColumns[':p' . $index++]  = '`WEIGHT`';
    1569:         }
    1570:         if ($this->isColumnModified(ProductPeer::POSITION)) {
    1571:             $modifiedColumns[':p' . $index++]  = '`POSITION`';
    1572:         }
    1573:         if ($this->isColumnModified(ProductPeer::CREATED_AT)) {
    1574:             $modifiedColumns[':p' . $index++]  = '`CREATED_AT`';
    1575:         }
    1576:         if ($this->isColumnModified(ProductPeer::UPDATED_AT)) {
    1577:             $modifiedColumns[':p' . $index++]  = '`UPDATED_AT`';
    1578:         }
    1579:         if ($this->isColumnModified(ProductPeer::VERSION)) {
    1580:             $modifiedColumns[':p' . $index++]  = '`VERSION`';
    1581:         }
    1582:         if ($this->isColumnModified(ProductPeer::VERSION_CREATED_AT)) {
    1583:             $modifiedColumns[':p' . $index++]  = '`VERSION_CREATED_AT`';
    1584:         }
    1585:         if ($this->isColumnModified(ProductPeer::VERSION_CREATED_BY)) {
    1586:             $modifiedColumns[':p' . $index++]  = '`VERSION_CREATED_BY`';
    1587:         }
    1588:
    1589:         $sql = sprintf(
    1590:             'INSERT INTO `product` (%s) VALUES (%s)',
    1591:             implode(', ', $modifiedColumns),
    1592:             implode(', ', array_keys($modifiedColumns))
    1593:         );
    1594:
    1595:         try {
    1596:             $stmt = $con->prepare($sql);
    1597:             foreach ($modifiedColumns as $identifier => $columnName) {
    1598:                 switch ($columnName) {
    1599:                     case '`ID`':
    1600:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
    1601:                         break;
    1602:                     case '`TAX_RULE_ID`':
    1603:                         $stmt->bindValue($identifier, $this->tax_rule_id, PDO::PARAM_INT);
    1604:                         break;
    1605:                     case '`REF`':
    1606:                         $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR);
    1607:                         break;
    1608:                     case '`PRICE`':
    1609:                         $stmt->bindValue($identifier, $this->price, PDO::PARAM_STR);
    1610:                         break;
    1611:                     case '`PRICE2`':
    1612:                         $stmt->bindValue($identifier, $this->price2, PDO::PARAM_STR);
    1613:                         break;
    1614:                     case '`ECOTAX`':
    1615:                         $stmt->bindValue($identifier, $this->ecotax, PDO::PARAM_STR);
    1616:                         break;
    1617:                     case '`NEWNESS`':
    1618:                         $stmt->bindValue($identifier, $this->newness, PDO::PARAM_INT);
    1619:                         break;
    1620:                     case '`PROMO`':
    1621:                         $stmt->bindValue($identifier, $this->promo, PDO::PARAM_INT);
    1622:                         break;
    1623:                     case '`STOCK`':
    1624:                         $stmt->bindValue($identifier, $this->stock, PDO::PARAM_INT);
    1625:                         break;
    1626:                     case '`VISIBLE`':
    1627:                         $stmt->bindValue($identifier, $this->visible, PDO::PARAM_INT);
    1628:                         break;
    1629:                     case '`WEIGHT`':
    1630:                         $stmt->bindValue($identifier, $this->weight, PDO::PARAM_STR);
    1631:                         break;
    1632:                     case '`POSITION`':
    1633:                         $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
    1634:                         break;
    1635:                     case '`CREATED_AT`':
    1636:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
    1637:                         break;
    1638:                     case '`UPDATED_AT`':
    1639:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
    1640:                         break;
    1641:                     case '`VERSION`':
    1642:                         $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
    1643:                         break;
    1644:                     case '`VERSION_CREATED_AT`':
    1645:                         $stmt->bindValue($identifier, $this->version_created_at, PDO::PARAM_STR);
    1646:                         break;
    1647:                     case '`VERSION_CREATED_BY`':
    1648:                         $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR);
    1649:                         break;
    1650:                 }
    1651:             }
    1652:             $stmt->execute();
    1653:         } catch (Exception $e) {
    1654:             Propel::log($e->getMessage(), Propel::LOG_ERR);
    1655:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
    1656:         }
    1657:
    1658:         try {
    1659:             $pk = $con->lastInsertId();
    1660:         } catch (Exception $e) {
    1661:             throw new PropelException('Unable to get autoincrement id.', $e);
    1662:         }
    1663:         $this->setId($pk);
    1664:
    1665:         $this->setNew(false);
    1666:     }
    1667:
    1668:     /**
    1669:      * Update the row in the database.
    1670:      *
    1671:      * @param PropelPDO $con
    1672:      *
    1673:      * @see        doSave()
    1674:      */
    1675:     protected function doUpdate(PropelPDO $con)
    1676:     {
    1677:         $selectCriteria = $this->buildPkeyCriteria();
    1678:         $valuesCriteria = $this->buildCriteria();
    1679:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
    1680:     }
    1681:
    1682:     /**
    1683:      * Array of ValidationFailed objects.
    1684:      * @var        array ValidationFailed[]
    1685:      */
    1686:     protected $validationFailures = array();
    1687:
    1688:     /**
    1689:      * Gets any ValidationFailed objects that resulted from last call to validate().
    1690:      *
    1691:      *
    1692:      * @return array ValidationFailed[]
    1693:      * @see        validate()
    1694:      */
    1695:     public function getValidationFailures()
    1696:     {
    1697:         return $this->validationFailures;
    1698:     }
    1699:
    1700:     /**
    1701:      * Validates the objects modified field values and all objects related to this table.
    1702:      *
    1703:      * If $columns is either a column name or an array of column names
    1704:      * only those columns are validated.
    1705:      *
    1706:      * @param mixed $columns Column name or an array of column names.
    1707:      * @return boolean Whether all columns pass validation.
    1708:      * @see        doValidate()
    1709:      * @see        getValidationFailures()
    1710:      */
    1711:     public function validate($columns = null)
    1712:     {
    1713:         $res = $this->doValidate($columns);
    1714:         if ($res === true) {
    1715:             $this->validationFailures = array();
    1716:
    1717:             return true;
    1718:         } else {
    1719:             $this->validationFailures = $res;
    1720:
    1721:             return false;
    1722:         }
    1723:     }
    1724:
    1725:     /**
    1726:      * This function performs the validation work for complex object models.
    1727:      *
    1728:      * In addition to checking the current object, all related objects will
    1729:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
    1730:      * an aggreagated array of ValidationFailed objects will be returned.
    1731:      *
    1732:      * @param array $columns Array of column names to validate.
    1733:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
    1734:      */
    1735:     protected function doValidate($columns = null)
    1736:     {
    1737:         if (!$this->alreadyInValidation) {
    1738:             $this->alreadyInValidation = true;
    1739:             $retval = null;
    1740:
    1741:             $failureMap = array();
    1742:
    1743:
    1744:             // We call the validate method on the following object(s) if they
    1745:             // were passed to this object by their coresponding set
    1746:             // method.  This object relates to these object(s) by a
    1747:             // foreign key reference.
    1748:
    1749:             if ($this->aTaxRule !== null) {
    1750:                 if (!$this->aTaxRule->validate($columns)) {
    1751:                     $failureMap = array_merge($failureMap, $this->aTaxRule->getValidationFailures());
    1752:                 }
    1753:             }
    1754:
    1755:
    1756:             if (($retval = ProductPeer::doValidate($this, $columns)) !== true) {
    1757:                 $failureMap = array_merge($failureMap, $retval);
    1758:             }
    1759:
    1760:
    1761:                 if ($this->collProductCategorys !== null) {
    1762:                     foreach ($this->collProductCategorys as $referrerFK) {
    1763:                         if (!$referrerFK->validate($columns)) {
    1764:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1765:                         }
    1766:                     }
    1767:                 }
    1768:
    1769:                 if ($this->collFeatureProds !== null) {
    1770:                     foreach ($this->collFeatureProds as $referrerFK) {
    1771:                         if (!$referrerFK->validate($columns)) {
    1772:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1773:                         }
    1774:                     }
    1775:                 }
    1776:
    1777:                 if ($this->collStocks !== null) {
    1778:                     foreach ($this->collStocks as $referrerFK) {
    1779:                         if (!$referrerFK->validate($columns)) {
    1780:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1781:                         }
    1782:                     }
    1783:                 }
    1784:
    1785:                 if ($this->collContentAssocs !== null) {
    1786:                     foreach ($this->collContentAssocs as $referrerFK) {
    1787:                         if (!$referrerFK->validate($columns)) {
    1788:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1789:                         }
    1790:                     }
    1791:                 }
    1792:
    1793:                 if ($this->collImages !== null) {
    1794:                     foreach ($this->collImages as $referrerFK) {
    1795:                         if (!$referrerFK->validate($columns)) {
    1796:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1797:                         }
    1798:                     }
    1799:                 }
    1800:
    1801:                 if ($this->collDocuments !== null) {
    1802:                     foreach ($this->collDocuments as $referrerFK) {
    1803:                         if (!$referrerFK->validate($columns)) {
    1804:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1805:                         }
    1806:                     }
    1807:                 }
    1808:
    1809:                 if ($this->collAccessorysRelatedByProductId !== null) {
    1810:                     foreach ($this->collAccessorysRelatedByProductId as $referrerFK) {
    1811:                         if (!$referrerFK->validate($columns)) {
    1812:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1813:                         }
    1814:                     }
    1815:                 }
    1816:
    1817:                 if ($this->collAccessorysRelatedByAccessory !== null) {
    1818:                     foreach ($this->collAccessorysRelatedByAccessory as $referrerFK) {
    1819:                         if (!$referrerFK->validate($columns)) {
    1820:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1821:                         }
    1822:                     }
    1823:                 }
    1824:
    1825:                 if ($this->collRewritings !== null) {
    1826:                     foreach ($this->collRewritings as $referrerFK) {
    1827:                         if (!$referrerFK->validate($columns)) {
    1828:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1829:                         }
    1830:                     }
    1831:                 }
    1832:
    1833:                 if ($this->collProductI18ns !== null) {
    1834:                     foreach ($this->collProductI18ns as $referrerFK) {
    1835:                         if (!$referrerFK->validate($columns)) {
    1836:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1837:                         }
    1838:                     }
    1839:                 }
    1840:
    1841:                 if ($this->collProductVersions !== null) {
    1842:                     foreach ($this->collProductVersions as $referrerFK) {
    1843:                         if (!$referrerFK->validate($columns)) {
    1844:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1845:                         }
    1846:                     }
    1847:                 }
    1848:
    1849:
    1850:             $this->alreadyInValidation = false;
    1851:         }
    1852:
    1853:         return (!empty($failureMap) ? $failureMap : true);
    1854:     }
    1855:
    1856:     /**
    1857:      * Retrieves a field from the object by name passed in as a string.
    1858:      *
    1859:      * @param string $name name
    1860:      * @param string $type The type of fieldname the $name is of:
    1861:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    1862:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1863:      *               Defaults to BasePeer::TYPE_PHPNAME
    1864:      * @return mixed Value of field.
    1865:      */
    1866:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
    1867:     {
    1868:         $pos = ProductPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    1869:         $field = $this->getByPosition($pos);
    1870:
    1871:         return $field;
    1872:     }
    1873:
    1874:     /**
    1875:      * Retrieves a field from the object by Position as specified in the xml schema.
    1876:      * Zero-based.
    1877:      *
    1878:      * @param int $pos position in xml schema
    1879:      * @return mixed Value of field at $pos
    1880:      */
    1881:     public function getByPosition($pos)
    1882:     {
    1883:         switch ($pos) {
    1884:             case 0:
    1885:                 return $this->getId();
    1886:                 break;
    1887:             case 1:
    1888:                 return $this->getTaxRuleId();
    1889:                 break;
    1890:             case 2:
    1891:                 return $this->getRef();
    1892:                 break;
    1893:             case 3:
    1894:                 return $this->getPrice();
    1895:                 break;
    1896:             case 4:
    1897:                 return $this->getPrice2();
    1898:                 break;
    1899:             case 5:
    1900:                 return $this->getEcotax();
    1901:                 break;
    1902:             case 6:
    1903:                 return $this->getNewness();
    1904:                 break;
    1905:             case 7:
    1906:                 return $this->getPromo();
    1907:                 break;
    1908:             case 8:
    1909:                 return $this->getStock();
    1910:                 break;
    1911:             case 9:
    1912:                 return $this->getVisible();
    1913:                 break;
    1914:             case 10:
    1915:                 return $this->getWeight();
    1916:                 break;
    1917:             case 11:
    1918:                 return $this->getPosition();
    1919:                 break;
    1920:             case 12:
    1921:                 return $this->getCreatedAt();
    1922:                 break;
    1923:             case 13:
    1924:                 return $this->getUpdatedAt();
    1925:                 break;
    1926:             case 14:
    1927:                 return $this->getVersion();
    1928:                 break;
    1929:             case 15:
    1930:                 return $this->getVersionCreatedAt();
    1931:                 break;
    1932:             case 16:
    1933:                 return $this->getVersionCreatedBy();
    1934:                 break;
    1935:             default:
    1936:                 return null;
    1937:                 break;
    1938:         } // switch()
    1939:     }
    1940:
    1941:     /**
    1942:      * Exports the object as an array.
    1943:      *
    1944:      * You can specify the key type of the array by passing one of the class
    1945:      * type constants.
    1946:      *
    1947:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1948:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1949:      *                    Defaults to BasePeer::TYPE_PHPNAME.
    1950:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
    1951:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
    1952:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
    1953:      *
    1954:      * @return array an associative array containing the field names (as keys) and field values
    1955:      */
    1956:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    1957:     {
    1958:         if (isset($alreadyDumpedObjects['Product'][$this->getPrimaryKey()])) {
    1959:             return '*RECURSION*';
    1960:         }
    1961:         $alreadyDumpedObjects['Product'][$this->getPrimaryKey()] = true;
    1962:         $keys = ProductPeer::getFieldNames($keyType);
    1963:         $result = array(
    1964:             $keys[0] => $this->getId(),
    1965:             $keys[1] => $this->getTaxRuleId(),
    1966:             $keys[2] => $this->getRef(),
    1967:             $keys[3] => $this->getPrice(),
    1968:             $keys[4] => $this->getPrice2(),
    1969:             $keys[5] => $this->getEcotax(),
    1970:             $keys[6] => $this->getNewness(),
    1971:             $keys[7] => $this->getPromo(),
    1972:             $keys[8] => $this->getStock(),
    1973:             $keys[9] => $this->getVisible(),
    1974:             $keys[10] => $this->getWeight(),
    1975:             $keys[11] => $this->getPosition(),
    1976:             $keys[12] => $this->getCreatedAt(),
    1977:             $keys[13] => $this->getUpdatedAt(),
    1978:             $keys[14] => $this->getVersion(),
    1979:             $keys[15] => $this->getVersionCreatedAt(),
    1980:             $keys[16] => $this->getVersionCreatedBy(),
    1981:         );
    1982:         if ($includeForeignObjects) {
    1983:             if (null !== $this->aTaxRule) {
    1984:                 $result['TaxRule'] = $this->aTaxRule->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1985:             }
    1986:             if (null !== $this->collProductCategorys) {
    1987:                 $result['ProductCategorys'] = $this->collProductCategorys->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1988:             }
    1989:             if (null !== $this->collFeatureProds) {
    1990:                 $result['FeatureProds'] = $this->collFeatureProds->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1991:             }
    1992:             if (null !== $this->collStocks) {
    1993:                 $result['Stocks'] = $this->collStocks->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1994:             }
    1995:             if (null !== $this->collContentAssocs) {
    1996:                 $result['ContentAssocs'] = $this->collContentAssocs->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1997:             }
    1998:             if (null !== $this->collImages) {
    1999:                 $result['Images'] = $this->collImages->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2000:             }
    2001:             if (null !== $this->collDocuments) {
    2002:                 $result['Documents'] = $this->collDocuments->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2003:             }
    2004:             if (null !== $this->collAccessorysRelatedByProductId) {
    2005:                 $result['AccessorysRelatedByProductId'] = $this->collAccessorysRelatedByProductId->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2006:             }
    2007:             if (null !== $this->collAccessorysRelatedByAccessory) {
    2008:                 $result['AccessorysRelatedByAccessory'] = $this->collAccessorysRelatedByAccessory->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2009:             }
    2010:             if (null !== $this->collRewritings) {
    2011:                 $result['Rewritings'] = $this->collRewritings->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2012:             }
    2013:             if (null !== $this->collProductI18ns) {
    2014:                 $result['ProductI18ns'] = $this->collProductI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2015:             }
    2016:             if (null !== $this->collProductVersions) {
    2017:                 $result['ProductVersions'] = $this->collProductVersions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    2018:             }
    2019:         }
    2020:
    2021:         return $result;
    2022:     }
    2023:
    2024:     /**
    2025:      * Sets a field from the object by name passed in as a string.
    2026:      *
    2027:      * @param string $name peer name
    2028:      * @param mixed $value field value
    2029:      * @param string $type The type of fieldname the $name is of:
    2030:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    2031:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    2032:      *                     Defaults to BasePeer::TYPE_PHPNAME
    2033:      * @return void
    2034:      */
    2035:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    2036:     {
    2037:         $pos = ProductPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    2038:
    2039:         $this->setByPosition($pos, $value);
    2040:     }
    2041:
    2042:     /**
    2043:      * Sets a field from the object by Position as specified in the xml schema.
    2044:      * Zero-based.
    2045:      *
    2046:      * @param int $pos position in xml schema
    2047:      * @param mixed $value field value
    2048:      * @return void
    2049:      */
    2050:     public function setByPosition($pos, $value)
    2051:     {
    2052:         switch ($pos) {
    2053:             case 0:
    2054:                 $this->setId($value);
    2055:                 break;
    2056:             case 1:
    2057:                 $this->setTaxRuleId($value);
    2058:                 break;
    2059:             case 2:
    2060:                 $this->setRef($value);
    2061:                 break;
    2062:             case 3:
    2063:                 $this->setPrice($value);
    2064:                 break;
    2065:             case 4:
    2066:                 $this->setPrice2($value);
    2067:                 break;
    2068:             case 5:
    2069:                 $this->setEcotax($value);
    2070:                 break;
    2071:             case 6:
    2072:                 $this->setNewness($value);
    2073:                 break;
    2074:             case 7:
    2075:                 $this->setPromo($value);
    2076:                 break;
    2077:             case 8:
    2078:                 $this->setStock($value);
    2079:                 break;
    2080:             case 9:
    2081:                 $this->setVisible($value);
    2082:                 break;
    2083:             case 10:
    2084:                 $this->setWeight($value);
    2085:                 break;
    2086:             case 11:
    2087:                 $this->setPosition($value);
    2088:                 break;
    2089:             case 12:
    2090:                 $this->setCreatedAt($value);
    2091:                 break;
    2092:             case 13:
    2093:                 $this->setUpdatedAt($value);
    2094:                 break;
    2095:             case 14:
    2096:                 $this->setVersion($value);
    2097:                 break;
    2098:             case 15:
    2099:                 $this->setVersionCreatedAt($value);
    2100:                 break;
    2101:             case 16:
    2102:                 $this->setVersionCreatedBy($value);
    2103:                 break;
    2104:         } // switch()
    2105:     }
    2106:
    2107:     /**
    2108:      * Populates the object using an array.
    2109:      *
    2110:      * This is particularly useful when populating an object from one of the
    2111:      * request arrays (e.g. $_POST).  This method goes through the column
    2112:      * names, checking to see whether a matching key exists in populated
    2113:      * array. If so the setByName() method is called for that column.
    2114:      *
    2115:      * You can specify the key type of the array by additionally passing one
    2116:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    2117:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    2118:      * The default key type is the column's BasePeer::TYPE_PHPNAME
    2119:      *
    2120:      * @param array  $arr     An array to populate the object from.
    2121:      * @param string $keyType The type of keys the array uses.
    2122:      * @return void
    2123:      */
    2124:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    2125:     {
    2126:         $keys = ProductPeer::getFieldNames($keyType);
    2127:
    2128:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
    2129:         if (array_key_exists($keys[1], $arr)) $this->setTaxRuleId($arr[$keys[1]]);
    2130:         if (array_key_exists($keys[2], $arr)) $this->setRef($arr[$keys[2]]);
    2131:         if (array_key_exists($keys[3], $arr)) $this->setPrice($arr[$keys[3]]);
    2132:         if (array_key_exists($keys[4], $arr)) $this->setPrice2($arr[$keys[4]]);
    2133:         if (array_key_exists($keys[5], $arr)) $this->setEcotax($arr[$keys[5]]);
    2134:         if (array_key_exists($keys[6], $arr)) $this->setNewness($arr[$keys[6]]);
    2135:         if (array_key_exists($keys[7], $arr)) $this->setPromo($arr[$keys[7]]);
    2136:         if (array_key_exists($keys[8], $arr)) $this->setStock($arr[$keys[8]]);
    2137:         if (array_key_exists($keys[9], $arr)) $this->setVisible($arr[$keys[9]]);
    2138:         if (array_key_exists($keys[10], $arr)) $this->setWeight($arr[$keys[10]]);
    2139:         if (array_key_exists($keys[11], $arr)) $this->setPosition($arr[$keys[11]]);
    2140:         if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]);
    2141:         if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]);
    2142:         if (array_key_exists($keys[14], $arr)) $this->setVersion($arr[$keys[14]]);
    2143:         if (array_key_exists($keys[15], $arr)) $this->setVersionCreatedAt($arr[$keys[15]]);
    2144:         if (array_key_exists($keys[16], $arr)) $this->setVersionCreatedBy($arr[$keys[16]]);
    2145:     }
    2146:
    2147:     /**
    2148:      * Build a Criteria object containing the values of all modified columns in this object.
    2149:      *
    2150:      * @return Criteria The Criteria object containing all modified values.
    2151:      */
    2152:     public function buildCriteria()
    2153:     {
    2154:         $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    2155:
    2156:         if ($this->isColumnModified(ProductPeer::ID)) $criteria->add(ProductPeer::ID, $this->id);
    2157:         if ($this->isColumnModified(ProductPeer::TAX_RULE_ID)) $criteria->add(ProductPeer::TAX_RULE_ID, $this->tax_rule_id);
    2158:         if ($this->isColumnModified(ProductPeer::REF)) $criteria->add(ProductPeer::REF, $this->ref);
    2159:         if ($this->isColumnModified(ProductPeer::PRICE)) $criteria->add(ProductPeer::PRICE, $this->price);
    2160:         if ($this->isColumnModified(ProductPeer::PRICE2)) $criteria->add(ProductPeer::PRICE2, $this->price2);
    2161:         if ($this->isColumnModified(ProductPeer::ECOTAX)) $criteria->add(ProductPeer::ECOTAX, $this->ecotax);
    2162:         if ($this->isColumnModified(ProductPeer::NEWNESS)) $criteria->add(ProductPeer::NEWNESS, $this->newness);
    2163:         if ($this->isColumnModified(ProductPeer::PROMO)) $criteria->add(ProductPeer::PROMO, $this->promo);
    2164:         if ($this->isColumnModified(ProductPeer::STOCK)) $criteria->add(ProductPeer::STOCK, $this->stock);
    2165:         if ($this->isColumnModified(ProductPeer::VISIBLE)) $criteria->add(ProductPeer::VISIBLE, $this->visible);
    2166:         if ($this->isColumnModified(ProductPeer::WEIGHT)) $criteria->add(ProductPeer::WEIGHT, $this->weight);
    2167:         if ($this->isColumnModified(ProductPeer::POSITION)) $criteria->add(ProductPeer::POSITION, $this->position);
    2168:         if ($this->isColumnModified(ProductPeer::CREATED_AT)) $criteria->add(ProductPeer::CREATED_AT, $this->created_at);
    2169:         if ($this->isColumnModified(ProductPeer::UPDATED_AT)) $criteria->add(ProductPeer::UPDATED_AT, $this->updated_at);
    2170:         if ($this->isColumnModified(ProductPeer::VERSION)) $criteria->add(ProductPeer::VERSION, $this->version);
    2171:         if ($this->isColumnModified(ProductPeer::VERSION_CREATED_AT)) $criteria->add(ProductPeer::VERSION_CREATED_AT, $this->version_created_at);
    2172:         if ($this->isColumnModified(ProductPeer::VERSION_CREATED_BY)) $criteria->add(ProductPeer::VERSION_CREATED_BY, $this->version_created_by);
    2173:
    2174:         return $criteria;
    2175:     }
    2176:
    2177:     /**
    2178:      * Builds a Criteria object containing the primary key for this object.
    2179:      *
    2180:      * Unlike buildCriteria() this method includes the primary key values regardless
    2181:      * of whether or not they have been modified.
    2182:      *
    2183:      * @return Criteria The Criteria object containing value(s) for primary key(s).
    2184:      */
    2185:     public function buildPkeyCriteria()
    2186:     {
    2187:         $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    2188:         $criteria->add(ProductPeer::ID, $this->id);
    2189:
    2190:         return $criteria;
    2191:     }
    2192:
    2193:     /**
    2194:      * Returns the primary key for this object (row).
    2195:      * @return int
    2196:      */
    2197:     public function getPrimaryKey()
    2198:     {
    2199:         return $this->getId();
    2200:     }
    2201:
    2202:     /**
    2203:      * Generic method to set the primary key (id column).
    2204:      *
    2205:      * @param  int $key Primary key.
    2206:      * @return void
    2207:      */
    2208:     public function setPrimaryKey($key)
    2209:     {
    2210:         $this->setId($key);
    2211:     }
    2212:
    2213:     /**
    2214:      * Returns true if the primary key for this object is null.
    2215:      * @return boolean
    2216:      */
    2217:     public function isPrimaryKeyNull()
    2218:     {
    2219:
    2220:         return null === $this->getId();
    2221:     }
    2222:
    2223:     /**
    2224:      * Sets contents of passed object to values from current object.
    2225:      *
    2226:      * If desired, this method can also make copies of all associated (fkey referrers)
    2227:      * objects.
    2228:      *
    2229:      * @param object $copyObj An object of Product (or compatible) type.
    2230:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    2231:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
    2232:      * @throws PropelException
    2233:      */
    2234:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    2235:     {
    2236:         $copyObj->setTaxRuleId($this->getTaxRuleId());
    2237:         $copyObj->setRef($this->getRef());
    2238:         $copyObj->setPrice($this->getPrice());
    2239:         $copyObj->setPrice2($this->getPrice2());
    2240:         $copyObj->setEcotax($this->getEcotax());
    2241:         $copyObj->setNewness($this->getNewness());
    2242:         $copyObj->setPromo($this->getPromo());
    2243:         $copyObj->setStock($this->getStock());
    2244:         $copyObj->setVisible($this->getVisible());
    2245:         $copyObj->setWeight($this->getWeight());
    2246:         $copyObj->setPosition($this->getPosition());
    2247:         $copyObj->setCreatedAt($this->getCreatedAt());
    2248:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    2249:         $copyObj->setVersion($this->getVersion());
    2250:         $copyObj->setVersionCreatedAt($this->getVersionCreatedAt());
    2251:         $copyObj->setVersionCreatedBy($this->getVersionCreatedBy());
    2252:
    2253:         if ($deepCopy && !$this->startCopy) {
    2254:             // important: temporarily setNew(false) because this affects the behavior of
    2255:             // the getter/setter methods for fkey referrer objects.
    2256:             $copyObj->setNew(false);
    2257:             // store object hash to prevent cycle
    2258:             $this->startCopy = true;
    2259:
    2260:             foreach ($this->getProductCategorys() as $relObj) {
    2261:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2262:                     $copyObj->addProductCategory($relObj->copy($deepCopy));
    2263:                 }
    2264:             }
    2265:
    2266:             foreach ($this->getFeatureProds() as $relObj) {
    2267:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2268:                     $copyObj->addFeatureProd($relObj->copy($deepCopy));
    2269:                 }
    2270:             }
    2271:
    2272:             foreach ($this->getStocks() as $relObj) {
    2273:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2274:                     $copyObj->addStock($relObj->copy($deepCopy));
    2275:                 }
    2276:             }
    2277:
    2278:             foreach ($this->getContentAssocs() as $relObj) {
    2279:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2280:                     $copyObj->addContentAssoc($relObj->copy($deepCopy));
    2281:                 }
    2282:             }
    2283:
    2284:             foreach ($this->getImages() as $relObj) {
    2285:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2286:                     $copyObj->addImage($relObj->copy($deepCopy));
    2287:                 }
    2288:             }
    2289:
    2290:             foreach ($this->getDocuments() as $relObj) {
    2291:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2292:                     $copyObj->addDocument($relObj->copy($deepCopy));
    2293:                 }
    2294:             }
    2295:
    2296:             foreach ($this->getAccessorysRelatedByProductId() as $relObj) {
    2297:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2298:                     $copyObj->addAccessoryRelatedByProductId($relObj->copy($deepCopy));
    2299:                 }
    2300:             }
    2301:
    2302:             foreach ($this->getAccessorysRelatedByAccessory() as $relObj) {
    2303:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2304:                     $copyObj->addAccessoryRelatedByAccessory($relObj->copy($deepCopy));
    2305:                 }
    2306:             }
    2307:
    2308:             foreach ($this->getRewritings() as $relObj) {
    2309:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2310:                     $copyObj->addRewriting($relObj->copy($deepCopy));
    2311:                 }
    2312:             }
    2313:
    2314:             foreach ($this->getProductI18ns() as $relObj) {
    2315:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2316:                     $copyObj->addProductI18n($relObj->copy($deepCopy));
    2317:                 }
    2318:             }
    2319:
    2320:             foreach ($this->getProductVersions() as $relObj) {
    2321:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    2322:                     $copyObj->addProductVersion($relObj->copy($deepCopy));
    2323:                 }
    2324:             }
    2325:
    2326:             //unflag object copy
    2327:             $this->startCopy = false;
    2328:         } // if ($deepCopy)
    2329:
    2330:         if ($makeNew) {
    2331:             $copyObj->setNew(true);
    2332:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
    2333:         }
    2334:     }
    2335:
    2336:     /**
    2337:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    2338:      * It creates a new object filling in the simple attributes, but skipping any primary
    2339:      * keys that are defined for the table.
    2340:      *
    2341:      * If desired, this method can also make copies of all associated (fkey referrers)
    2342:      * objects.
    2343:      *
    2344:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    2345:      * @return Product Clone of current object.
    2346:      * @throws PropelException
    2347:      */
    2348:     public function copy($deepCopy = false)
    2349:     {
    2350:         // we use get_class(), because this might be a subclass
    2351:         $clazz = get_class($this);
    2352:         $copyObj = new $clazz();
    2353:         $this->copyInto($copyObj, $deepCopy);
    2354:
    2355:         return $copyObj;
    2356:     }
    2357:
    2358:     /**
    2359:      * Returns a peer instance associated with this om.
    2360:      *
    2361:      * Since Peer classes are not to have any instance attributes, this method returns the
    2362:      * same instance for all member of this class. The method could therefore
    2363:      * be static, but this would prevent one from overriding the behavior.
    2364:      *
    2365:      * @return ProductPeer
    2366:      */
    2367:     public function getPeer()
    2368:     {
    2369:         if (self::$peer === null) {
    2370:             self::$peer = new ProductPeer();
    2371:         }
    2372:
    2373:         return self::$peer;
    2374:     }
    2375:
    2376:     /**
    2377:      * Declares an association between this object and a TaxRule object.
    2378:      *
    2379:      * @param             TaxRule $v
    2380:      * @return Product The current object (for fluent API support)
    2381:      * @throws PropelException
    2382:      */
    2383:     public function setTaxRule(TaxRule $v = null)
    2384:     {
    2385:         if ($v === null) {
    2386:             $this->setTaxRuleId(NULL);
    2387:         } else {
    2388:             $this->setTaxRuleId($v->getId());
    2389:         }
    2390:
    2391:         $this->aTaxRule = $v;
    2392:
    2393:         // Add binding for other direction of this n:n relationship.
    2394:         // If this object has already been added to the TaxRule object, it will not be re-added.
    2395:         if ($v !== null) {
    2396:             $v->addProduct($this);
    2397:         }
    2398:
    2399:
    2400:         return $this;
    2401:     }
    2402:
    2403:
    2404:     /**
    2405:      * Get the associated TaxRule object
    2406:      *
    2407:      * @param PropelPDO $con Optional Connection object.
    2408:      * @return TaxRule The associated TaxRule object.
    2409:      * @throws PropelException
    2410:      */
    2411:     public function getTaxRule(PropelPDO $con = null)
    2412:     {
    2413:         if ($this->aTaxRule === null && ($this->tax_rule_id !== null)) {
    2414:             $this->aTaxRule = TaxRuleQuery::create()->findPk($this->tax_rule_id, $con);
    2415:             /* The following can be used additionally to
    2416:                 guarantee the related object contains a reference
    2417:                 to this object.  This level of coupling may, however, be
    2418:                 undesirable since it could result in an only partially populated collection
    2419:                 in the referenced object.
    2420:                 $this->aTaxRule->addProducts($this);
    2421:              */
    2422:         }
    2423:
    2424:         return $this->aTaxRule;
    2425:     }
    2426:
    2427:
    2428:     /**
    2429:      * Initializes a collection based on the name of a relation.
    2430:      * Avoids crafting an 'init[$relationName]s' method name
    2431:      * that wouldn't work when StandardEnglishPluralizer is used.
    2432:      *
    2433:      * @param string $relationName The name of the relation to initialize
    2434:      * @return void
    2435:      */
    2436:     public function initRelation($relationName)
    2437:     {
    2438:         if ('ProductCategory' == $relationName) {
    2439:             $this->initProductCategorys();
    2440:         }
    2441:         if ('FeatureProd' == $relationName) {
    2442:             $this->initFeatureProds();
    2443:         }
    2444:         if ('Stock' == $relationName) {
    2445:             $this->initStocks();
    2446:         }
    2447:         if ('ContentAssoc' == $relationName) {
    2448:             $this->initContentAssocs();
    2449:         }
    2450:         if ('Image' == $relationName) {
    2451:             $this->initImages();
    2452:         }
    2453:         if ('Document' == $relationName) {
    2454:             $this->initDocuments();
    2455:         }
    2456:         if ('AccessoryRelatedByProductId' == $relationName) {
    2457:             $this->initAccessorysRelatedByProductId();
    2458:         }
    2459:         if ('AccessoryRelatedByAccessory' == $relationName) {
    2460:             $this->initAccessorysRelatedByAccessory();
    2461:         }
    2462:         if ('Rewriting' == $relationName) {
    2463:             $this->initRewritings();
    2464:         }
    2465:         if ('ProductI18n' == $relationName) {
    2466:             $this->initProductI18ns();
    2467:         }
    2468:         if ('ProductVersion' == $relationName) {
    2469:             $this->initProductVersions();
    2470:         }
    2471:     }
    2472:
    2473:     /**
    2474:      * Clears out the collProductCategorys collection
    2475:      *
    2476:      * This does not modify the database; however, it will remove any associated objects, causing
    2477:      * them to be refetched by subsequent calls to accessor method.
    2478:      *
    2479:      * @return void
    2480:      * @see        addProductCategorys()
    2481:      */
    2482:     public function clearProductCategorys()
    2483:     {
    2484:         $this->collProductCategorys = null; // important to set this to null since that means it is uninitialized
    2485:         $this->collProductCategorysPartial = null;
    2486:     }
    2487:
    2488:     /**
    2489:      * reset is the collProductCategorys collection loaded partially
    2490:      *
    2491:      * @return void
    2492:      */
    2493:     public function resetPartialProductCategorys($v = true)
    2494:     {
    2495:         $this->collProductCategorysPartial = $v;
    2496:     }
    2497:
    2498:     /**
    2499:      * Initializes the collProductCategorys collection.
    2500:      *
    2501:      * By default this just sets the collProductCategorys collection to an empty array (like clearcollProductCategorys());
    2502:      * however, you may wish to override this method in your stub class to provide setting appropriate
    2503:      * to your application -- for example, setting the initial array to the values stored in database.
    2504:      *
    2505:      * @param boolean $overrideExisting If set to true, the method call initializes
    2506:      *                                        the collection even if it is not empty
    2507:      *
    2508:      * @return void
    2509:      */
    2510:     public function initProductCategorys($overrideExisting = true)
    2511:     {
    2512:         if (null !== $this->collProductCategorys && !$overrideExisting) {
    2513:             return;
    2514:         }
    2515:         $this->collProductCategorys = new PropelObjectCollection();
    2516:         $this->collProductCategorys->setModel('ProductCategory');
    2517:     }
    2518:
    2519:     /**
    2520:      * Gets an array of ProductCategory objects which contain a foreign key that references this object.
    2521:      *
    2522:      * If the $criteria is not null, it is used to always fetch the results from the database.
    2523:      * Otherwise the results are fetched from the database the first time, then cached.
    2524:      * Next time the same method is called without $criteria, the cached collection is returned.
    2525:      * If this Product is new, it will return
    2526:      * an empty collection or the current collection; the criteria is ignored on a new object.
    2527:      *
    2528:      * @param Criteria $criteria optional Criteria object to narrow the query
    2529:      * @param PropelPDO $con optional connection object
    2530:      * @return PropelObjectCollection|ProductCategory[] List of ProductCategory objects
    2531:      * @throws PropelException
    2532:      */
    2533:     public function getProductCategorys($criteria = null, PropelPDO $con = null)
    2534:     {
    2535:         $partial = $this->collProductCategorysPartial && !$this->isNew();
    2536:         if (null === $this->collProductCategorys || null !== $criteria  || $partial) {
    2537:             if ($this->isNew() && null === $this->collProductCategorys) {
    2538:                 // return empty collection
    2539:                 $this->initProductCategorys();
    2540:             } else {
    2541:                 $collProductCategorys = ProductCategoryQuery::create(null, $criteria)
    2542:                     ->filterByProduct($this)
    2543:                     ->find($con);
    2544:                 if (null !== $criteria) {
    2545:                     if (false !== $this->collProductCategorysPartial && count($collProductCategorys)) {
    2546:                       $this->initProductCategorys(false);
    2547:
    2548:                       foreach($collProductCategorys as $obj) {
    2549:                         if (false == $this->collProductCategorys->contains($obj)) {
    2550:                           $this->collProductCategorys->append($obj);
    2551:                         }
    2552:                       }
    2553:
    2554:                       $this->collProductCategorysPartial = true;
    2555:                     }
    2556:
    2557:                     return $collProductCategorys;
    2558:                 }
    2559:
    2560:                 if($partial && $this->collProductCategorys) {
    2561:                     foreach($this->collProductCategorys as $obj) {
    2562:                         if($obj->isNew()) {
    2563:                             $collProductCategorys[] = $obj;
    2564:                         }
    2565:                     }
    2566:                 }
    2567:
    2568:                 $this->collProductCategorys = $collProductCategorys;
    2569:                 $this->collProductCategorysPartial = false;
    2570:             }
    2571:         }
    2572:
    2573:         return $this->collProductCategorys;
    2574:     }
    2575:
    2576:     /**
    2577:      * Sets a collection of ProductCategory objects related by a one-to-many relationship
    2578:      * to the current object.
    2579:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    2580:      * and new objects from the given Propel collection.
    2581:      *
    2582:      * @param PropelCollection $productCategorys A Propel collection.
    2583:      * @param PropelPDO $con Optional connection object
    2584:      */
    2585:     public function setProductCategorys(PropelCollection $productCategorys, PropelPDO $con = null)
    2586:     {
    2587:         $this->productCategorysScheduledForDeletion = $this->getProductCategorys(new Criteria(), $con)->diff($productCategorys);
    2588:
    2589:         foreach ($this->productCategorysScheduledForDeletion as $productCategoryRemoved) {
    2590:             $productCategoryRemoved->setProduct(null);
    2591:         }
    2592:
    2593:         $this->collProductCategorys = null;
    2594:         foreach ($productCategorys as $productCategory) {
    2595:             $this->addProductCategory($productCategory);
    2596:         }
    2597:
    2598:         $this->collProductCategorys = $productCategorys;
    2599:         $this->collProductCategorysPartial = false;
    2600:     }
    2601:
    2602:     /**
    2603:      * Returns the number of related ProductCategory objects.
    2604:      *
    2605:      * @param Criteria $criteria
    2606:      * @param boolean $distinct
    2607:      * @param PropelPDO $con
    2608:      * @return int             Count of related ProductCategory objects.
    2609:      * @throws PropelException
    2610:      */
    2611:     public function countProductCategorys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    2612:     {
    2613:         $partial = $this->collProductCategorysPartial && !$this->isNew();
    2614:         if (null === $this->collProductCategorys || null !== $criteria || $partial) {
    2615:             if ($this->isNew() && null === $this->collProductCategorys) {
    2616:                 return 0;
    2617:             } else {
    2618:                 if($partial && !$criteria) {
    2619:                     return count($this->getProductCategorys());
    2620:                 }
    2621:                 $query = ProductCategoryQuery::create(null, $criteria);
    2622:                 if ($distinct) {
    2623:                     $query->distinct();
    2624:                 }
    2625:
    2626:                 return $query
    2627:                     ->filterByProduct($this)
    2628:                     ->count($con);
    2629:             }
    2630:         } else {
    2631:             return count($this->collProductCategorys);
    2632:         }
    2633:     }
    2634:
    2635:     /**
    2636:      * Method called to associate a ProductCategory object to this object
    2637:      * through the ProductCategory foreign key attribute.
    2638:      *
    2639:      * @param    ProductCategory $l ProductCategory
    2640:      * @return Product The current object (for fluent API support)
    2641:      */
    2642:     public function addProductCategory(ProductCategory $l)
    2643:     {
    2644:         if ($this->collProductCategorys === null) {
    2645:             $this->initProductCategorys();
    2646:             $this->collProductCategorysPartial = true;
    2647:         }
    2648:         if (!$this->collProductCategorys->contains($l)) { // only add it if the **same** object is not already associated
    2649:             $this->doAddProductCategory($l);
    2650:         }
    2651:
    2652:         return $this;
    2653:     }
    2654:
    2655:     /**
    2656:      * @param   ProductCategory $productCategory The productCategory object to add.
    2657:      */
    2658:     protected function doAddProductCategory($productCategory)
    2659:     {
    2660:         $this->collProductCategorys[]= $productCategory;
    2661:         $productCategory->setProduct($this);
    2662:     }
    2663:
    2664:     /**
    2665:      * @param   ProductCategory $productCategory The productCategory object to remove.
    2666:      */
    2667:     public function removeProductCategory($productCategory)
    2668:     {
    2669:         if ($this->getProductCategorys()->contains($productCategory)) {
    2670:             $this->collProductCategorys->remove($this->collProductCategorys->search($productCategory));
    2671:             if (null === $this->productCategorysScheduledForDeletion) {
    2672:                 $this->productCategorysScheduledForDeletion = clone $this->collProductCategorys;
    2673:                 $this->productCategorysScheduledForDeletion->clear();
    2674:             }
    2675:             $this->productCategorysScheduledForDeletion[]= $productCategory;
    2676:             $productCategory->setProduct(null);
    2677:         }
    2678:     }
    2679:
    2680:
    2681:     /**
    2682:      * If this collection has already been initialized with
    2683:      * an identical criteria, it returns the collection.
    2684:      * Otherwise if this Product is new, it will return
    2685:      * an empty collection; or if this Product has previously
    2686:      * been saved, it will retrieve related ProductCategorys from storage.
    2687:      *
    2688:      * This method is protected by default in order to keep the public
    2689:      * api reasonable.  You can provide public methods for those you
    2690:      * actually need in Product.
    2691:      *
    2692:      * @param Criteria $criteria optional Criteria object to narrow the query
    2693:      * @param PropelPDO $con optional connection object
    2694:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    2695:      * @return PropelObjectCollection|ProductCategory[] List of ProductCategory objects
    2696:      */
    2697:     public function getProductCategorysJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    2698:     {
    2699:         $query = ProductCategoryQuery::create(null, $criteria);
    2700:         $query->joinWith('Category', $join_behavior);
    2701:
    2702:         return $this->getProductCategorys($query, $con);
    2703:     }
    2704:
    2705:     /**
    2706:      * Clears out the collFeatureProds collection
    2707:      *
    2708:      * This does not modify the database; however, it will remove any associated objects, causing
    2709:      * them to be refetched by subsequent calls to accessor method.
    2710:      *
    2711:      * @return void
    2712:      * @see        addFeatureProds()
    2713:      */
    2714:     public function clearFeatureProds()
    2715:     {
    2716:         $this->collFeatureProds = null; // important to set this to null since that means it is uninitialized
    2717:         $this->collFeatureProdsPartial = null;
    2718:     }
    2719:
    2720:     /**
    2721:      * reset is the collFeatureProds collection loaded partially
    2722:      *
    2723:      * @return void
    2724:      */
    2725:     public function resetPartialFeatureProds($v = true)
    2726:     {
    2727:         $this->collFeatureProdsPartial = $v;
    2728:     }
    2729:
    2730:     /**
    2731:      * Initializes the collFeatureProds collection.
    2732:      *
    2733:      * By default this just sets the collFeatureProds collection to an empty array (like clearcollFeatureProds());
    2734:      * however, you may wish to override this method in your stub class to provide setting appropriate
    2735:      * to your application -- for example, setting the initial array to the values stored in database.
    2736:      *
    2737:      * @param boolean $overrideExisting If set to true, the method call initializes
    2738:      *                                        the collection even if it is not empty
    2739:      *
    2740:      * @return void
    2741:      */
    2742:     public function initFeatureProds($overrideExisting = true)
    2743:     {
    2744:         if (null !== $this->collFeatureProds && !$overrideExisting) {
    2745:             return;
    2746:         }
    2747:         $this->collFeatureProds = new PropelObjectCollection();
    2748:         $this->collFeatureProds->setModel('FeatureProd');
    2749:     }
    2750:
    2751:     /**
    2752:      * Gets an array of FeatureProd objects which contain a foreign key that references this object.
    2753:      *
    2754:      * If the $criteria is not null, it is used to always fetch the results from the database.
    2755:      * Otherwise the results are fetched from the database the first time, then cached.
    2756:      * Next time the same method is called without $criteria, the cached collection is returned.
    2757:      * If this Product is new, it will return
    2758:      * an empty collection or the current collection; the criteria is ignored on a new object.
    2759:      *
    2760:      * @param Criteria $criteria optional Criteria object to narrow the query
    2761:      * @param PropelPDO $con optional connection object
    2762:      * @return PropelObjectCollection|FeatureProd[] List of FeatureProd objects
    2763:      * @throws PropelException
    2764:      */
    2765:     public function getFeatureProds($criteria = null, PropelPDO $con = null)
    2766:     {
    2767:         $partial = $this->collFeatureProdsPartial && !$this->isNew();
    2768:         if (null === $this->collFeatureProds || null !== $criteria  || $partial) {
    2769:             if ($this->isNew() && null === $this->collFeatureProds) {
    2770:                 // return empty collection
    2771:                 $this->initFeatureProds();
    2772:             } else {
    2773:                 $collFeatureProds = FeatureProdQuery::create(null, $criteria)
    2774:                     ->filterByProduct($this)
    2775:                     ->find($con);
    2776:                 if (null !== $criteria) {
    2777:                     if (false !== $this->collFeatureProdsPartial && count($collFeatureProds)) {
    2778:                       $this->initFeatureProds(false);
    2779:
    2780:                       foreach($collFeatureProds as $obj) {
    2781:                         if (false == $this->collFeatureProds->contains($obj)) {
    2782:                           $this->collFeatureProds->append($obj);
    2783:                         }
    2784:                       }
    2785:
    2786:                       $this->collFeatureProdsPartial = true;
    2787:                     }
    2788:
    2789:                     return $collFeatureProds;
    2790:                 }
    2791:
    2792:                 if($partial && $this->collFeatureProds) {
    2793:                     foreach($this->collFeatureProds as $obj) {
    2794:                         if($obj->isNew()) {
    2795:                             $collFeatureProds[] = $obj;
    2796:                         }
    2797:                     }
    2798:                 }
    2799:
    2800:                 $this->collFeatureProds = $collFeatureProds;
    2801:                 $this->collFeatureProdsPartial = false;
    2802:             }
    2803:         }
    2804:
    2805:         return $this->collFeatureProds;
    2806:     }
    2807:
    2808:     /**
    2809:      * Sets a collection of FeatureProd objects related by a one-to-many relationship
    2810:      * to the current object.
    2811:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    2812:      * and new objects from the given Propel collection.
    2813:      *
    2814:      * @param PropelCollection $featureProds A Propel collection.
    2815:      * @param PropelPDO $con Optional connection object
    2816:      */
    2817:     public function setFeatureProds(PropelCollection $featureProds, PropelPDO $con = null)
    2818:     {
    2819:         $this->featureProdsScheduledForDeletion = $this->getFeatureProds(new Criteria(), $con)->diff($featureProds);
    2820:
    2821:         foreach ($this->featureProdsScheduledForDeletion as $featureProdRemoved) {
    2822:             $featureProdRemoved->setProduct(null);
    2823:         }
    2824:
    2825:         $this->collFeatureProds = null;
    2826:         foreach ($featureProds as $featureProd) {
    2827:             $this->addFeatureProd($featureProd);
    2828:         }
    2829:
    2830:         $this->collFeatureProds = $featureProds;
    2831:         $this->collFeatureProdsPartial = false;
    2832:     }
    2833:
    2834:     /**
    2835:      * Returns the number of related FeatureProd objects.
    2836:      *
    2837:      * @param Criteria $criteria
    2838:      * @param boolean $distinct
    2839:      * @param PropelPDO $con
    2840:      * @return int             Count of related FeatureProd objects.
    2841:      * @throws PropelException
    2842:      */
    2843:     public function countFeatureProds(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    2844:     {
    2845:         $partial = $this->collFeatureProdsPartial && !$this->isNew();
    2846:         if (null === $this->collFeatureProds || null !== $criteria || $partial) {
    2847:             if ($this->isNew() && null === $this->collFeatureProds) {
    2848:                 return 0;
    2849:             } else {
    2850:                 if($partial && !$criteria) {
    2851:                     return count($this->getFeatureProds());
    2852:                 }
    2853:                 $query = FeatureProdQuery::create(null, $criteria);
    2854:                 if ($distinct) {
    2855:                     $query->distinct();
    2856:                 }
    2857:
    2858:                 return $query
    2859:                     ->filterByProduct($this)
    2860:                     ->count($con);
    2861:             }
    2862:         } else {
    2863:             return count($this->collFeatureProds);
    2864:         }
    2865:     }
    2866:
    2867:     /**
    2868:      * Method called to associate a FeatureProd object to this object
    2869:      * through the FeatureProd foreign key attribute.
    2870:      *
    2871:      * @param    FeatureProd $l FeatureProd
    2872:      * @return Product The current object (for fluent API support)
    2873:      */
    2874:     public function addFeatureProd(FeatureProd $l)
    2875:     {
    2876:         if ($this->collFeatureProds === null) {
    2877:             $this->initFeatureProds();
    2878:             $this->collFeatureProdsPartial = true;
    2879:         }
    2880:         if (!$this->collFeatureProds->contains($l)) { // only add it if the **same** object is not already associated
    2881:             $this->doAddFeatureProd($l);
    2882:         }
    2883:
    2884:         return $this;
    2885:     }
    2886:
    2887:     /**
    2888:      * @param   FeatureProd $featureProd The featureProd object to add.
    2889:      */
    2890:     protected function doAddFeatureProd($featureProd)
    2891:     {
    2892:         $this->collFeatureProds[]= $featureProd;
    2893:         $featureProd->setProduct($this);
    2894:     }
    2895:
    2896:     /**
    2897:      * @param   FeatureProd $featureProd The featureProd object to remove.
    2898:      */
    2899:     public function removeFeatureProd($featureProd)
    2900:     {
    2901:         if ($this->getFeatureProds()->contains($featureProd)) {
    2902:             $this->collFeatureProds->remove($this->collFeatureProds->search($featureProd));
    2903:             if (null === $this->featureProdsScheduledForDeletion) {
    2904:                 $this->featureProdsScheduledForDeletion = clone $this->collFeatureProds;
    2905:                 $this->featureProdsScheduledForDeletion->clear();
    2906:             }
    2907:             $this->featureProdsScheduledForDeletion[]= $featureProd;
    2908:             $featureProd->setProduct(null);
    2909:         }
    2910:     }
    2911:
    2912:
    2913:     /**
    2914:      * If this collection has already been initialized with
    2915:      * an identical criteria, it returns the collection.
    2916:      * Otherwise if this Product is new, it will return
    2917:      * an empty collection; or if this Product has previously
    2918:      * been saved, it will retrieve related FeatureProds from storage.
    2919:      *
    2920:      * This method is protected by default in order to keep the public
    2921:      * api reasonable.  You can provide public methods for those you
    2922:      * actually need in Product.
    2923:      *
    2924:      * @param Criteria $criteria optional Criteria object to narrow the query
    2925:      * @param PropelPDO $con optional connection object
    2926:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    2927:      * @return PropelObjectCollection|FeatureProd[] List of FeatureProd objects
    2928:      */
    2929:     public function getFeatureProdsJoinFeature($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    2930:     {
    2931:         $query = FeatureProdQuery::create(null, $criteria);
    2932:         $query->joinWith('Feature', $join_behavior);
    2933:
    2934:         return $this->getFeatureProds($query, $con);
    2935:     }
    2936:
    2937:
    2938:     /**
    2939:      * If this collection has already been initialized with
    2940:      * an identical criteria, it returns the collection.
    2941:      * Otherwise if this Product is new, it will return
    2942:      * an empty collection; or if this Product has previously
    2943:      * been saved, it will retrieve related FeatureProds from storage.
    2944:      *
    2945:      * This method is protected by default in order to keep the public
    2946:      * api reasonable.  You can provide public methods for those you
    2947:      * actually need in Product.
    2948:      *
    2949:      * @param Criteria $criteria optional Criteria object to narrow the query
    2950:      * @param PropelPDO $con optional connection object
    2951:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    2952:      * @return PropelObjectCollection|FeatureProd[] List of FeatureProd objects
    2953:      */
    2954:     public function getFeatureProdsJoinFeatureAv($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    2955:     {
    2956:         $query = FeatureProdQuery::create(null, $criteria);
    2957:         $query->joinWith('FeatureAv', $join_behavior);
    2958:
    2959:         return $this->getFeatureProds($query, $con);
    2960:     }
    2961:
    2962:     /**
    2963:      * Clears out the collStocks collection
    2964:      *
    2965:      * This does not modify the database; however, it will remove any associated objects, causing
    2966:      * them to be refetched by subsequent calls to accessor method.
    2967:      *
    2968:      * @return void
    2969:      * @see        addStocks()
    2970:      */
    2971:     public function clearStocks()
    2972:     {
    2973:         $this->collStocks = null; // important to set this to null since that means it is uninitialized
    2974:         $this->collStocksPartial = null;
    2975:     }
    2976:
    2977:     /**
    2978:      * reset is the collStocks collection loaded partially
    2979:      *
    2980:      * @return void
    2981:      */
    2982:     public function resetPartialStocks($v = true)
    2983:     {
    2984:         $this->collStocksPartial = $v;
    2985:     }
    2986:
    2987:     /**
    2988:      * Initializes the collStocks collection.
    2989:      *
    2990:      * By default this just sets the collStocks collection to an empty array (like clearcollStocks());
    2991:      * however, you may wish to override this method in your stub class to provide setting appropriate
    2992:      * to your application -- for example, setting the initial array to the values stored in database.
    2993:      *
    2994:      * @param boolean $overrideExisting If set to true, the method call initializes
    2995:      *                                        the collection even if it is not empty
    2996:      *
    2997:      * @return void
    2998:      */
    2999:     public function initStocks($overrideExisting = true)
    3000:     {
    3001:         if (null !== $this->collStocks && !$overrideExisting) {
    3002:             return;
    3003:         }
    3004:         $this->collStocks = new PropelObjectCollection();
    3005:         $this->collStocks->setModel('Stock');
    3006:     }
    3007:
    3008:     /**
    3009:      * Gets an array of Stock objects which contain a foreign key that references this object.
    3010:      *
    3011:      * If the $criteria is not null, it is used to always fetch the results from the database.
    3012:      * Otherwise the results are fetched from the database the first time, then cached.
    3013:      * Next time the same method is called without $criteria, the cached collection is returned.
    3014:      * If this Product is new, it will return
    3015:      * an empty collection or the current collection; the criteria is ignored on a new object.
    3016:      *
    3017:      * @param Criteria $criteria optional Criteria object to narrow the query
    3018:      * @param PropelPDO $con optional connection object
    3019:      * @return PropelObjectCollection|Stock[] List of Stock objects
    3020:      * @throws PropelException
    3021:      */
    3022:     public function getStocks($criteria = null, PropelPDO $con = null)
    3023:     {
    3024:         $partial = $this->collStocksPartial && !$this->isNew();
    3025:         if (null === $this->collStocks || null !== $criteria  || $partial) {
    3026:             if ($this->isNew() && null === $this->collStocks) {
    3027:                 // return empty collection
    3028:                 $this->initStocks();
    3029:             } else {
    3030:                 $collStocks = StockQuery::create(null, $criteria)
    3031:                     ->filterByProduct($this)
    3032:                     ->find($con);
    3033:                 if (null !== $criteria) {
    3034:                     if (false !== $this->collStocksPartial && count($collStocks)) {
    3035:                       $this->initStocks(false);
    3036:
    3037:                       foreach($collStocks as $obj) {
    3038:                         if (false == $this->collStocks->contains($obj)) {
    3039:                           $this->collStocks->append($obj);
    3040:                         }
    3041:                       }
    3042:
    3043:                       $this->collStocksPartial = true;
    3044:                     }
    3045:
    3046:                     return $collStocks;
    3047:                 }
    3048:
    3049:                 if($partial && $this->collStocks) {
    3050:                     foreach($this->collStocks as $obj) {
    3051:                         if($obj->isNew()) {
    3052:                             $collStocks[] = $obj;
    3053:                         }
    3054:                     }
    3055:                 }
    3056:
    3057:                 $this->collStocks = $collStocks;
    3058:                 $this->collStocksPartial = false;
    3059:             }
    3060:         }
    3061:
    3062:         return $this->collStocks;
    3063:     }
    3064:
    3065:     /**
    3066:      * Sets a collection of Stock objects related by a one-to-many relationship
    3067:      * to the current object.
    3068:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    3069:      * and new objects from the given Propel collection.
    3070:      *
    3071:      * @param PropelCollection $stocks A Propel collection.
    3072:      * @param PropelPDO $con Optional connection object
    3073:      */
    3074:     public function setStocks(PropelCollection $stocks, PropelPDO $con = null)
    3075:     {
    3076:         $this->stocksScheduledForDeletion = $this->getStocks(new Criteria(), $con)->diff($stocks);
    3077:
    3078:         foreach ($this->stocksScheduledForDeletion as $stockRemoved) {
    3079:             $stockRemoved->setProduct(null);
    3080:         }
    3081:
    3082:         $this->collStocks = null;
    3083:         foreach ($stocks as $stock) {
    3084:             $this->addStock($stock);
    3085:         }
    3086:
    3087:         $this->collStocks = $stocks;
    3088:         $this->collStocksPartial = false;
    3089:     }
    3090:
    3091:     /**
    3092:      * Returns the number of related Stock objects.
    3093:      *
    3094:      * @param Criteria $criteria
    3095:      * @param boolean $distinct
    3096:      * @param PropelPDO $con
    3097:      * @return int             Count of related Stock objects.
    3098:      * @throws PropelException
    3099:      */
    3100:     public function countStocks(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    3101:     {
    3102:         $partial = $this->collStocksPartial && !$this->isNew();
    3103:         if (null === $this->collStocks || null !== $criteria || $partial) {
    3104:             if ($this->isNew() && null === $this->collStocks) {
    3105:                 return 0;
    3106:             } else {
    3107:                 if($partial && !$criteria) {
    3108:                     return count($this->getStocks());
    3109:                 }
    3110:                 $query = StockQuery::create(null, $criteria);
    3111:                 if ($distinct) {
    3112:                     $query->distinct();
    3113:                 }
    3114:
    3115:                 return $query
    3116:                     ->filterByProduct($this)
    3117:                     ->count($con);
    3118:             }
    3119:         } else {
    3120:             return count($this->collStocks);
    3121:         }
    3122:     }
    3123:
    3124:     /**
    3125:      * Method called to associate a Stock object to this object
    3126:      * through the Stock foreign key attribute.
    3127:      *
    3128:      * @param    Stock $l Stock
    3129:      * @return Product The current object (for fluent API support)
    3130:      */
    3131:     public function addStock(Stock $l)
    3132:     {
    3133:         if ($this->collStocks === null) {
    3134:             $this->initStocks();
    3135:             $this->collStocksPartial = true;
    3136:         }
    3137:         if (!$this->collStocks->contains($l)) { // only add it if the **same** object is not already associated
    3138:             $this->doAddStock($l);
    3139:         }
    3140:
    3141:         return $this;
    3142:     }
    3143:
    3144:     /**
    3145:      * @param   Stock $stock The stock object to add.
    3146:      */
    3147:     protected function doAddStock($stock)
    3148:     {
    3149:         $this->collStocks[]= $stock;
    3150:         $stock->setProduct($this);
    3151:     }
    3152:
    3153:     /**
    3154:      * @param   Stock $stock The stock object to remove.
    3155:      */
    3156:     public function removeStock($stock)
    3157:     {
    3158:         if ($this->getStocks()->contains($stock)) {
    3159:             $this->collStocks->remove($this->collStocks->search($stock));
    3160:             if (null === $this->stocksScheduledForDeletion) {
    3161:                 $this->stocksScheduledForDeletion = clone $this->collStocks;
    3162:                 $this->stocksScheduledForDeletion->clear();
    3163:             }
    3164:             $this->stocksScheduledForDeletion[]= $stock;
    3165:             $stock->setProduct(null);
    3166:         }
    3167:     }
    3168:
    3169:
    3170:     /**
    3171:      * If this collection has already been initialized with
    3172:      * an identical criteria, it returns the collection.
    3173:      * Otherwise if this Product is new, it will return
    3174:      * an empty collection; or if this Product has previously
    3175:      * been saved, it will retrieve related Stocks from storage.
    3176:      *
    3177:      * This method is protected by default in order to keep the public
    3178:      * api reasonable.  You can provide public methods for those you
    3179:      * actually need in Product.
    3180:      *
    3181:      * @param Criteria $criteria optional Criteria object to narrow the query
    3182:      * @param PropelPDO $con optional connection object
    3183:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3184:      * @return PropelObjectCollection|Stock[] List of Stock objects
    3185:      */
    3186:     public function getStocksJoinCombination($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3187:     {
    3188:         $query = StockQuery::create(null, $criteria);
    3189:         $query->joinWith('Combination', $join_behavior);
    3190:
    3191:         return $this->getStocks($query, $con);
    3192:     }
    3193:
    3194:     /**
    3195:      * Clears out the collContentAssocs collection
    3196:      *
    3197:      * This does not modify the database; however, it will remove any associated objects, causing
    3198:      * them to be refetched by subsequent calls to accessor method.
    3199:      *
    3200:      * @return void
    3201:      * @see        addContentAssocs()
    3202:      */
    3203:     public function clearContentAssocs()
    3204:     {
    3205:         $this->collContentAssocs = null; // important to set this to null since that means it is uninitialized
    3206:         $this->collContentAssocsPartial = null;
    3207:     }
    3208:
    3209:     /**
    3210:      * reset is the collContentAssocs collection loaded partially
    3211:      *
    3212:      * @return void
    3213:      */
    3214:     public function resetPartialContentAssocs($v = true)
    3215:     {
    3216:         $this->collContentAssocsPartial = $v;
    3217:     }
    3218:
    3219:     /**
    3220:      * Initializes the collContentAssocs collection.
    3221:      *
    3222:      * By default this just sets the collContentAssocs collection to an empty array (like clearcollContentAssocs());
    3223:      * however, you may wish to override this method in your stub class to provide setting appropriate
    3224:      * to your application -- for example, setting the initial array to the values stored in database.
    3225:      *
    3226:      * @param boolean $overrideExisting If set to true, the method call initializes
    3227:      *                                        the collection even if it is not empty
    3228:      *
    3229:      * @return void
    3230:      */
    3231:     public function initContentAssocs($overrideExisting = true)
    3232:     {
    3233:         if (null !== $this->collContentAssocs && !$overrideExisting) {
    3234:             return;
    3235:         }
    3236:         $this->collContentAssocs = new PropelObjectCollection();
    3237:         $this->collContentAssocs->setModel('ContentAssoc');
    3238:     }
    3239:
    3240:     /**
    3241:      * Gets an array of ContentAssoc objects which contain a foreign key that references this object.
    3242:      *
    3243:      * If the $criteria is not null, it is used to always fetch the results from the database.
    3244:      * Otherwise the results are fetched from the database the first time, then cached.
    3245:      * Next time the same method is called without $criteria, the cached collection is returned.
    3246:      * If this Product is new, it will return
    3247:      * an empty collection or the current collection; the criteria is ignored on a new object.
    3248:      *
    3249:      * @param Criteria $criteria optional Criteria object to narrow the query
    3250:      * @param PropelPDO $con optional connection object
    3251:      * @return PropelObjectCollection|ContentAssoc[] List of ContentAssoc objects
    3252:      * @throws PropelException
    3253:      */
    3254:     public function getContentAssocs($criteria = null, PropelPDO $con = null)
    3255:     {
    3256:         $partial = $this->collContentAssocsPartial && !$this->isNew();
    3257:         if (null === $this->collContentAssocs || null !== $criteria  || $partial) {
    3258:             if ($this->isNew() && null === $this->collContentAssocs) {
    3259:                 // return empty collection
    3260:                 $this->initContentAssocs();
    3261:             } else {
    3262:                 $collContentAssocs = ContentAssocQuery::create(null, $criteria)
    3263:                     ->filterByProduct($this)
    3264:                     ->find($con);
    3265:                 if (null !== $criteria) {
    3266:                     if (false !== $this->collContentAssocsPartial && count($collContentAssocs)) {
    3267:                       $this->initContentAssocs(false);
    3268:
    3269:                       foreach($collContentAssocs as $obj) {
    3270:                         if (false == $this->collContentAssocs->contains($obj)) {
    3271:                           $this->collContentAssocs->append($obj);
    3272:                         }
    3273:                       }
    3274:
    3275:                       $this->collContentAssocsPartial = true;
    3276:                     }
    3277:
    3278:                     return $collContentAssocs;
    3279:                 }
    3280:
    3281:                 if($partial && $this->collContentAssocs) {
    3282:                     foreach($this->collContentAssocs as $obj) {
    3283:                         if($obj->isNew()) {
    3284:                             $collContentAssocs[] = $obj;
    3285:                         }
    3286:                     }
    3287:                 }
    3288:
    3289:                 $this->collContentAssocs = $collContentAssocs;
    3290:                 $this->collContentAssocsPartial = false;
    3291:             }
    3292:         }
    3293:
    3294:         return $this->collContentAssocs;
    3295:     }
    3296:
    3297:     /**
    3298:      * Sets a collection of ContentAssoc objects related by a one-to-many relationship
    3299:      * to the current object.
    3300:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    3301:      * and new objects from the given Propel collection.
    3302:      *
    3303:      * @param PropelCollection $contentAssocs A Propel collection.
    3304:      * @param PropelPDO $con Optional connection object
    3305:      */
    3306:     public function setContentAssocs(PropelCollection $contentAssocs, PropelPDO $con = null)
    3307:     {
    3308:         $this->contentAssocsScheduledForDeletion = $this->getContentAssocs(new Criteria(), $con)->diff($contentAssocs);
    3309:
    3310:         foreach ($this->contentAssocsScheduledForDeletion as $contentAssocRemoved) {
    3311:             $contentAssocRemoved->setProduct(null);
    3312:         }
    3313:
    3314:         $this->collContentAssocs = null;
    3315:         foreach ($contentAssocs as $contentAssoc) {
    3316:             $this->addContentAssoc($contentAssoc);
    3317:         }
    3318:
    3319:         $this->collContentAssocs = $contentAssocs;
    3320:         $this->collContentAssocsPartial = false;
    3321:     }
    3322:
    3323:     /**
    3324:      * Returns the number of related ContentAssoc objects.
    3325:      *
    3326:      * @param Criteria $criteria
    3327:      * @param boolean $distinct
    3328:      * @param PropelPDO $con
    3329:      * @return int             Count of related ContentAssoc objects.
    3330:      * @throws PropelException
    3331:      */
    3332:     public function countContentAssocs(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    3333:     {
    3334:         $partial = $this->collContentAssocsPartial && !$this->isNew();
    3335:         if (null === $this->collContentAssocs || null !== $criteria || $partial) {
    3336:             if ($this->isNew() && null === $this->collContentAssocs) {
    3337:                 return 0;
    3338:             } else {
    3339:                 if($partial && !$criteria) {
    3340:                     return count($this->getContentAssocs());
    3341:                 }
    3342:                 $query = ContentAssocQuery::create(null, $criteria);
    3343:                 if ($distinct) {
    3344:                     $query->distinct();
    3345:                 }
    3346:
    3347:                 return $query
    3348:                     ->filterByProduct($this)
    3349:                     ->count($con);
    3350:             }
    3351:         } else {
    3352:             return count($this->collContentAssocs);
    3353:         }
    3354:     }
    3355:
    3356:     /**
    3357:      * Method called to associate a ContentAssoc object to this object
    3358:      * through the ContentAssoc foreign key attribute.
    3359:      *
    3360:      * @param    ContentAssoc $l ContentAssoc
    3361:      * @return Product The current object (for fluent API support)
    3362:      */
    3363:     public function addContentAssoc(ContentAssoc $l)
    3364:     {
    3365:         if ($this->collContentAssocs === null) {
    3366:             $this->initContentAssocs();
    3367:             $this->collContentAssocsPartial = true;
    3368:         }
    3369:         if (!$this->collContentAssocs->contains($l)) { // only add it if the **same** object is not already associated
    3370:             $this->doAddContentAssoc($l);
    3371:         }
    3372:
    3373:         return $this;
    3374:     }
    3375:
    3376:     /**
    3377:      * @param   ContentAssoc $contentAssoc The contentAssoc object to add.
    3378:      */
    3379:     protected function doAddContentAssoc($contentAssoc)
    3380:     {
    3381:         $this->collContentAssocs[]= $contentAssoc;
    3382:         $contentAssoc->setProduct($this);
    3383:     }
    3384:
    3385:     /**
    3386:      * @param   ContentAssoc $contentAssoc The contentAssoc object to remove.
    3387:      */
    3388:     public function removeContentAssoc($contentAssoc)
    3389:     {
    3390:         if ($this->getContentAssocs()->contains($contentAssoc)) {
    3391:             $this->collContentAssocs->remove($this->collContentAssocs->search($contentAssoc));
    3392:             if (null === $this->contentAssocsScheduledForDeletion) {
    3393:                 $this->contentAssocsScheduledForDeletion = clone $this->collContentAssocs;
    3394:                 $this->contentAssocsScheduledForDeletion->clear();
    3395:             }
    3396:             $this->contentAssocsScheduledForDeletion[]= $contentAssoc;
    3397:             $contentAssoc->setProduct(null);
    3398:         }
    3399:     }
    3400:
    3401:
    3402:     /**
    3403:      * If this collection has already been initialized with
    3404:      * an identical criteria, it returns the collection.
    3405:      * Otherwise if this Product is new, it will return
    3406:      * an empty collection; or if this Product has previously
    3407:      * been saved, it will retrieve related ContentAssocs from storage.
    3408:      *
    3409:      * This method is protected by default in order to keep the public
    3410:      * api reasonable.  You can provide public methods for those you
    3411:      * actually need in Product.
    3412:      *
    3413:      * @param Criteria $criteria optional Criteria object to narrow the query
    3414:      * @param PropelPDO $con optional connection object
    3415:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3416:      * @return PropelObjectCollection|ContentAssoc[] List of ContentAssoc objects
    3417:      */
    3418:     public function getContentAssocsJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3419:     {
    3420:         $query = ContentAssocQuery::create(null, $criteria);
    3421:         $query->joinWith('Category', $join_behavior);
    3422:
    3423:         return $this->getContentAssocs($query, $con);
    3424:     }
    3425:
    3426:
    3427:     /**
    3428:      * If this collection has already been initialized with
    3429:      * an identical criteria, it returns the collection.
    3430:      * Otherwise if this Product is new, it will return
    3431:      * an empty collection; or if this Product has previously
    3432:      * been saved, it will retrieve related ContentAssocs from storage.
    3433:      *
    3434:      * This method is protected by default in order to keep the public
    3435:      * api reasonable.  You can provide public methods for those you
    3436:      * actually need in Product.
    3437:      *
    3438:      * @param Criteria $criteria optional Criteria object to narrow the query
    3439:      * @param PropelPDO $con optional connection object
    3440:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3441:      * @return PropelObjectCollection|ContentAssoc[] List of ContentAssoc objects
    3442:      */
    3443:     public function getContentAssocsJoinContent($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3444:     {
    3445:         $query = ContentAssocQuery::create(null, $criteria);
    3446:         $query->joinWith('Content', $join_behavior);
    3447:
    3448:         return $this->getContentAssocs($query, $con);
    3449:     }
    3450:
    3451:     /**
    3452:      * Clears out the collImages collection
    3453:      *
    3454:      * This does not modify the database; however, it will remove any associated objects, causing
    3455:      * them to be refetched by subsequent calls to accessor method.
    3456:      *
    3457:      * @return void
    3458:      * @see        addImages()
    3459:      */
    3460:     public function clearImages()
    3461:     {
    3462:         $this->collImages = null; // important to set this to null since that means it is uninitialized
    3463:         $this->collImagesPartial = null;
    3464:     }
    3465:
    3466:     /**
    3467:      * reset is the collImages collection loaded partially
    3468:      *
    3469:      * @return void
    3470:      */
    3471:     public function resetPartialImages($v = true)
    3472:     {
    3473:         $this->collImagesPartial = $v;
    3474:     }
    3475:
    3476:     /**
    3477:      * Initializes the collImages collection.
    3478:      *
    3479:      * By default this just sets the collImages collection to an empty array (like clearcollImages());
    3480:      * however, you may wish to override this method in your stub class to provide setting appropriate
    3481:      * to your application -- for example, setting the initial array to the values stored in database.
    3482:      *
    3483:      * @param boolean $overrideExisting If set to true, the method call initializes
    3484:      *                                        the collection even if it is not empty
    3485:      *
    3486:      * @return void
    3487:      */
    3488:     public function initImages($overrideExisting = true)
    3489:     {
    3490:         if (null !== $this->collImages && !$overrideExisting) {
    3491:             return;
    3492:         }
    3493:         $this->collImages = new PropelObjectCollection();
    3494:         $this->collImages->setModel('Image');
    3495:     }
    3496:
    3497:     /**
    3498:      * Gets an array of Image objects which contain a foreign key that references this object.
    3499:      *
    3500:      * If the $criteria is not null, it is used to always fetch the results from the database.
    3501:      * Otherwise the results are fetched from the database the first time, then cached.
    3502:      * Next time the same method is called without $criteria, the cached collection is returned.
    3503:      * If this Product is new, it will return
    3504:      * an empty collection or the current collection; the criteria is ignored on a new object.
    3505:      *
    3506:      * @param Criteria $criteria optional Criteria object to narrow the query
    3507:      * @param PropelPDO $con optional connection object
    3508:      * @return PropelObjectCollection|Image[] List of Image objects
    3509:      * @throws PropelException
    3510:      */
    3511:     public function getImages($criteria = null, PropelPDO $con = null)
    3512:     {
    3513:         $partial = $this->collImagesPartial && !$this->isNew();
    3514:         if (null === $this->collImages || null !== $criteria  || $partial) {
    3515:             if ($this->isNew() && null === $this->collImages) {
    3516:                 // return empty collection
    3517:                 $this->initImages();
    3518:             } else {
    3519:                 $collImages = ImageQuery::create(null, $criteria)
    3520:                     ->filterByProduct($this)
    3521:                     ->find($con);
    3522:                 if (null !== $criteria) {
    3523:                     if (false !== $this->collImagesPartial && count($collImages)) {
    3524:                       $this->initImages(false);
    3525:
    3526:                       foreach($collImages as $obj) {
    3527:                         if (false == $this->collImages->contains($obj)) {
    3528:                           $this->collImages->append($obj);
    3529:                         }
    3530:                       }
    3531:
    3532:                       $this->collImagesPartial = true;
    3533:                     }
    3534:
    3535:                     return $collImages;
    3536:                 }
    3537:
    3538:                 if($partial && $this->collImages) {
    3539:                     foreach($this->collImages as $obj) {
    3540:                         if($obj->isNew()) {
    3541:                             $collImages[] = $obj;
    3542:                         }
    3543:                     }
    3544:                 }
    3545:
    3546:                 $this->collImages = $collImages;
    3547:                 $this->collImagesPartial = false;
    3548:             }
    3549:         }
    3550:
    3551:         return $this->collImages;
    3552:     }
    3553:
    3554:     /**
    3555:      * Sets a collection of Image objects related by a one-to-many relationship
    3556:      * to the current object.
    3557:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    3558:      * and new objects from the given Propel collection.
    3559:      *
    3560:      * @param PropelCollection $images A Propel collection.
    3561:      * @param PropelPDO $con Optional connection object
    3562:      */
    3563:     public function setImages(PropelCollection $images, PropelPDO $con = null)
    3564:     {
    3565:         $this->imagesScheduledForDeletion = $this->getImages(new Criteria(), $con)->diff($images);
    3566:
    3567:         foreach ($this->imagesScheduledForDeletion as $imageRemoved) {
    3568:             $imageRemoved->setProduct(null);
    3569:         }
    3570:
    3571:         $this->collImages = null;
    3572:         foreach ($images as $image) {
    3573:             $this->addImage($image);
    3574:         }
    3575:
    3576:         $this->collImages = $images;
    3577:         $this->collImagesPartial = false;
    3578:     }
    3579:
    3580:     /**
    3581:      * Returns the number of related Image objects.
    3582:      *
    3583:      * @param Criteria $criteria
    3584:      * @param boolean $distinct
    3585:      * @param PropelPDO $con
    3586:      * @return int             Count of related Image objects.
    3587:      * @throws PropelException
    3588:      */
    3589:     public function countImages(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    3590:     {
    3591:         $partial = $this->collImagesPartial && !$this->isNew();
    3592:         if (null === $this->collImages || null !== $criteria || $partial) {
    3593:             if ($this->isNew() && null === $this->collImages) {
    3594:                 return 0;
    3595:             } else {
    3596:                 if($partial && !$criteria) {
    3597:                     return count($this->getImages());
    3598:                 }
    3599:                 $query = ImageQuery::create(null, $criteria);
    3600:                 if ($distinct) {
    3601:                     $query->distinct();
    3602:                 }
    3603:
    3604:                 return $query
    3605:                     ->filterByProduct($this)
    3606:                     ->count($con);
    3607:             }
    3608:         } else {
    3609:             return count($this->collImages);
    3610:         }
    3611:     }
    3612:
    3613:     /**
    3614:      * Method called to associate a Image object to this object
    3615:      * through the Image foreign key attribute.
    3616:      *
    3617:      * @param    Image $l Image
    3618:      * @return Product The current object (for fluent API support)
    3619:      */
    3620:     public function addImage(Image $l)
    3621:     {
    3622:         if ($this->collImages === null) {
    3623:             $this->initImages();
    3624:             $this->collImagesPartial = true;
    3625:         }
    3626:         if (!$this->collImages->contains($l)) { // only add it if the **same** object is not already associated
    3627:             $this->doAddImage($l);
    3628:         }
    3629:
    3630:         return $this;
    3631:     }
    3632:
    3633:     /**
    3634:      * @param   Image $image The image object to add.
    3635:      */
    3636:     protected function doAddImage($image)
    3637:     {
    3638:         $this->collImages[]= $image;
    3639:         $image->setProduct($this);
    3640:     }
    3641:
    3642:     /**
    3643:      * @param   Image $image The image object to remove.
    3644:      */
    3645:     public function removeImage($image)
    3646:     {
    3647:         if ($this->getImages()->contains($image)) {
    3648:             $this->collImages->remove($this->collImages->search($image));
    3649:             if (null === $this->imagesScheduledForDeletion) {
    3650:                 $this->imagesScheduledForDeletion = clone $this->collImages;
    3651:                 $this->imagesScheduledForDeletion->clear();
    3652:             }
    3653:             $this->imagesScheduledForDeletion[]= $image;
    3654:             $image->setProduct(null);
    3655:         }
    3656:     }
    3657:
    3658:
    3659:     /**
    3660:      * If this collection has already been initialized with
    3661:      * an identical criteria, it returns the collection.
    3662:      * Otherwise if this Product is new, it will return
    3663:      * an empty collection; or if this Product has previously
    3664:      * been saved, it will retrieve related Images from storage.
    3665:      *
    3666:      * This method is protected by default in order to keep the public
    3667:      * api reasonable.  You can provide public methods for those you
    3668:      * actually need in Product.
    3669:      *
    3670:      * @param Criteria $criteria optional Criteria object to narrow the query
    3671:      * @param PropelPDO $con optional connection object
    3672:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3673:      * @return PropelObjectCollection|Image[] List of Image objects
    3674:      */
    3675:     public function getImagesJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3676:     {
    3677:         $query = ImageQuery::create(null, $criteria);
    3678:         $query->joinWith('Category', $join_behavior);
    3679:
    3680:         return $this->getImages($query, $con);
    3681:     }
    3682:
    3683:
    3684:     /**
    3685:      * If this collection has already been initialized with
    3686:      * an identical criteria, it returns the collection.
    3687:      * Otherwise if this Product is new, it will return
    3688:      * an empty collection; or if this Product has previously
    3689:      * been saved, it will retrieve related Images from storage.
    3690:      *
    3691:      * This method is protected by default in order to keep the public
    3692:      * api reasonable.  You can provide public methods for those you
    3693:      * actually need in Product.
    3694:      *
    3695:      * @param Criteria $criteria optional Criteria object to narrow the query
    3696:      * @param PropelPDO $con optional connection object
    3697:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3698:      * @return PropelObjectCollection|Image[] List of Image objects
    3699:      */
    3700:     public function getImagesJoinContent($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3701:     {
    3702:         $query = ImageQuery::create(null, $criteria);
    3703:         $query->joinWith('Content', $join_behavior);
    3704:
    3705:         return $this->getImages($query, $con);
    3706:     }
    3707:
    3708:
    3709:     /**
    3710:      * If this collection has already been initialized with
    3711:      * an identical criteria, it returns the collection.
    3712:      * Otherwise if this Product is new, it will return
    3713:      * an empty collection; or if this Product has previously
    3714:      * been saved, it will retrieve related Images from storage.
    3715:      *
    3716:      * This method is protected by default in order to keep the public
    3717:      * api reasonable.  You can provide public methods for those you
    3718:      * actually need in Product.
    3719:      *
    3720:      * @param Criteria $criteria optional Criteria object to narrow the query
    3721:      * @param PropelPDO $con optional connection object
    3722:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3723:      * @return PropelObjectCollection|Image[] List of Image objects
    3724:      */
    3725:     public function getImagesJoinFolder($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3726:     {
    3727:         $query = ImageQuery::create(null, $criteria);
    3728:         $query->joinWith('Folder', $join_behavior);
    3729:
    3730:         return $this->getImages($query, $con);
    3731:     }
    3732:
    3733:     /**
    3734:      * Clears out the collDocuments collection
    3735:      *
    3736:      * This does not modify the database; however, it will remove any associated objects, causing
    3737:      * them to be refetched by subsequent calls to accessor method.
    3738:      *
    3739:      * @return void
    3740:      * @see        addDocuments()
    3741:      */
    3742:     public function clearDocuments()
    3743:     {
    3744:         $this->collDocuments = null; // important to set this to null since that means it is uninitialized
    3745:         $this->collDocumentsPartial = null;
    3746:     }
    3747:
    3748:     /**
    3749:      * reset is the collDocuments collection loaded partially
    3750:      *
    3751:      * @return void
    3752:      */
    3753:     public function resetPartialDocuments($v = true)
    3754:     {
    3755:         $this->collDocumentsPartial = $v;
    3756:     }
    3757:
    3758:     /**
    3759:      * Initializes the collDocuments collection.
    3760:      *
    3761:      * By default this just sets the collDocuments collection to an empty array (like clearcollDocuments());
    3762:      * however, you may wish to override this method in your stub class to provide setting appropriate
    3763:      * to your application -- for example, setting the initial array to the values stored in database.
    3764:      *
    3765:      * @param boolean $overrideExisting If set to true, the method call initializes
    3766:      *                                        the collection even if it is not empty
    3767:      *
    3768:      * @return void
    3769:      */
    3770:     public function initDocuments($overrideExisting = true)
    3771:     {
    3772:         if (null !== $this->collDocuments && !$overrideExisting) {
    3773:             return;
    3774:         }
    3775:         $this->collDocuments = new PropelObjectCollection();
    3776:         $this->collDocuments->setModel('Document');
    3777:     }
    3778:
    3779:     /**
    3780:      * Gets an array of Document objects which contain a foreign key that references this object.
    3781:      *
    3782:      * If the $criteria is not null, it is used to always fetch the results from the database.
    3783:      * Otherwise the results are fetched from the database the first time, then cached.
    3784:      * Next time the same method is called without $criteria, the cached collection is returned.
    3785:      * If this Product is new, it will return
    3786:      * an empty collection or the current collection; the criteria is ignored on a new object.
    3787:      *
    3788:      * @param Criteria $criteria optional Criteria object to narrow the query
    3789:      * @param PropelPDO $con optional connection object
    3790:      * @return PropelObjectCollection|Document[] List of Document objects
    3791:      * @throws PropelException
    3792:      */
    3793:     public function getDocuments($criteria = null, PropelPDO $con = null)
    3794:     {
    3795:         $partial = $this->collDocumentsPartial && !$this->isNew();
    3796:         if (null === $this->collDocuments || null !== $criteria  || $partial) {
    3797:             if ($this->isNew() && null === $this->collDocuments) {
    3798:                 // return empty collection
    3799:                 $this->initDocuments();
    3800:             } else {
    3801:                 $collDocuments = DocumentQuery::create(null, $criteria)
    3802:                     ->filterByProduct($this)
    3803:                     ->find($con);
    3804:                 if (null !== $criteria) {
    3805:                     if (false !== $this->collDocumentsPartial && count($collDocuments)) {
    3806:                       $this->initDocuments(false);
    3807:
    3808:                       foreach($collDocuments as $obj) {
    3809:                         if (false == $this->collDocuments->contains($obj)) {
    3810:                           $this->collDocuments->append($obj);
    3811:                         }
    3812:                       }
    3813:
    3814:                       $this->collDocumentsPartial = true;
    3815:                     }
    3816:
    3817:                     return $collDocuments;
    3818:                 }
    3819:
    3820:                 if($partial && $this->collDocuments) {
    3821:                     foreach($this->collDocuments as $obj) {
    3822:                         if($obj->isNew()) {
    3823:                             $collDocuments[] = $obj;
    3824:                         }
    3825:                     }
    3826:                 }
    3827:
    3828:                 $this->collDocuments = $collDocuments;
    3829:                 $this->collDocumentsPartial = false;
    3830:             }
    3831:         }
    3832:
    3833:         return $this->collDocuments;
    3834:     }
    3835:
    3836:     /**
    3837:      * Sets a collection of Document objects related by a one-to-many relationship
    3838:      * to the current object.
    3839:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    3840:      * and new objects from the given Propel collection.
    3841:      *
    3842:      * @param PropelCollection $documents A Propel collection.
    3843:      * @param PropelPDO $con Optional connection object
    3844:      */
    3845:     public function setDocuments(PropelCollection $documents, PropelPDO $con = null)
    3846:     {
    3847:         $this->documentsScheduledForDeletion = $this->getDocuments(new Criteria(), $con)->diff($documents);
    3848:
    3849:         foreach ($this->documentsScheduledForDeletion as $documentRemoved) {
    3850:             $documentRemoved->setProduct(null);
    3851:         }
    3852:
    3853:         $this->collDocuments = null;
    3854:         foreach ($documents as $document) {
    3855:             $this->addDocument($document);
    3856:         }
    3857:
    3858:         $this->collDocuments = $documents;
    3859:         $this->collDocumentsPartial = false;
    3860:     }
    3861:
    3862:     /**
    3863:      * Returns the number of related Document objects.
    3864:      *
    3865:      * @param Criteria $criteria
    3866:      * @param boolean $distinct
    3867:      * @param PropelPDO $con
    3868:      * @return int             Count of related Document objects.
    3869:      * @throws PropelException
    3870:      */
    3871:     public function countDocuments(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    3872:     {
    3873:         $partial = $this->collDocumentsPartial && !$this->isNew();
    3874:         if (null === $this->collDocuments || null !== $criteria || $partial) {
    3875:             if ($this->isNew() && null === $this->collDocuments) {
    3876:                 return 0;
    3877:             } else {
    3878:                 if($partial && !$criteria) {
    3879:                     return count($this->getDocuments());
    3880:                 }
    3881:                 $query = DocumentQuery::create(null, $criteria);
    3882:                 if ($distinct) {
    3883:                     $query->distinct();
    3884:                 }
    3885:
    3886:                 return $query
    3887:                     ->filterByProduct($this)
    3888:                     ->count($con);
    3889:             }
    3890:         } else {
    3891:             return count($this->collDocuments);
    3892:         }
    3893:     }
    3894:
    3895:     /**
    3896:      * Method called to associate a Document object to this object
    3897:      * through the Document foreign key attribute.
    3898:      *
    3899:      * @param    Document $l Document
    3900:      * @return Product The current object (for fluent API support)
    3901:      */
    3902:     public function addDocument(Document $l)
    3903:     {
    3904:         if ($this->collDocuments === null) {
    3905:             $this->initDocuments();
    3906:             $this->collDocumentsPartial = true;
    3907:         }
    3908:         if (!$this->collDocuments->contains($l)) { // only add it if the **same** object is not already associated
    3909:             $this->doAddDocument($l);
    3910:         }
    3911:
    3912:         return $this;
    3913:     }
    3914:
    3915:     /**
    3916:      * @param   Document $document The document object to add.
    3917:      */
    3918:     protected function doAddDocument($document)
    3919:     {
    3920:         $this->collDocuments[]= $document;
    3921:         $document->setProduct($this);
    3922:     }
    3923:
    3924:     /**
    3925:      * @param   Document $document The document object to remove.
    3926:      */
    3927:     public function removeDocument($document)
    3928:     {
    3929:         if ($this->getDocuments()->contains($document)) {
    3930:             $this->collDocuments->remove($this->collDocuments->search($document));
    3931:             if (null === $this->documentsScheduledForDeletion) {
    3932:                 $this->documentsScheduledForDeletion = clone $this->collDocuments;
    3933:                 $this->documentsScheduledForDeletion->clear();
    3934:             }
    3935:             $this->documentsScheduledForDeletion[]= $document;
    3936:             $document->setProduct(null);
    3937:         }
    3938:     }
    3939:
    3940:
    3941:     /**
    3942:      * If this collection has already been initialized with
    3943:      * an identical criteria, it returns the collection.
    3944:      * Otherwise if this Product is new, it will return
    3945:      * an empty collection; or if this Product has previously
    3946:      * been saved, it will retrieve related Documents from storage.
    3947:      *
    3948:      * This method is protected by default in order to keep the public
    3949:      * api reasonable.  You can provide public methods for those you
    3950:      * actually need in Product.
    3951:      *
    3952:      * @param Criteria $criteria optional Criteria object to narrow the query
    3953:      * @param PropelPDO $con optional connection object
    3954:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3955:      * @return PropelObjectCollection|Document[] List of Document objects
    3956:      */
    3957:     public function getDocumentsJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3958:     {
    3959:         $query = DocumentQuery::create(null, $criteria);
    3960:         $query->joinWith('Category', $join_behavior);
    3961:
    3962:         return $this->getDocuments($query, $con);
    3963:     }
    3964:
    3965:
    3966:     /**
    3967:      * If this collection has already been initialized with
    3968:      * an identical criteria, it returns the collection.
    3969:      * Otherwise if this Product is new, it will return
    3970:      * an empty collection; or if this Product has previously
    3971:      * been saved, it will retrieve related Documents from storage.
    3972:      *
    3973:      * This method is protected by default in order to keep the public
    3974:      * api reasonable.  You can provide public methods for those you
    3975:      * actually need in Product.
    3976:      *
    3977:      * @param Criteria $criteria optional Criteria object to narrow the query
    3978:      * @param PropelPDO $con optional connection object
    3979:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    3980:      * @return PropelObjectCollection|Document[] List of Document objects
    3981:      */
    3982:     public function getDocumentsJoinContent($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    3983:     {
    3984:         $query = DocumentQuery::create(null, $criteria);
    3985:         $query->joinWith('Content', $join_behavior);
    3986:
    3987:         return $this->getDocuments($query, $con);
    3988:     }
    3989:
    3990:
    3991:     /**
    3992:      * If this collection has already been initialized with
    3993:      * an identical criteria, it returns the collection.
    3994:      * Otherwise if this Product is new, it will return
    3995:      * an empty collection; or if this Product has previously
    3996:      * been saved, it will retrieve related Documents from storage.
    3997:      *
    3998:      * This method is protected by default in order to keep the public
    3999:      * api reasonable.  You can provide public methods for those you
    4000:      * actually need in Product.
    4001:      *
    4002:      * @param Criteria $criteria optional Criteria object to narrow the query
    4003:      * @param PropelPDO $con optional connection object
    4004:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    4005:      * @return PropelObjectCollection|Document[] List of Document objects
    4006:      */
    4007:     public function getDocumentsJoinFolder($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    4008:     {
    4009:         $query = DocumentQuery::create(null, $criteria);
    4010:         $query->joinWith('Folder', $join_behavior);
    4011:
    4012:         return $this->getDocuments($query, $con);
    4013:     }
    4014:
    4015:     /**
    4016:      * Clears out the collAccessorysRelatedByProductId collection
    4017:      *
    4018:      * This does not modify the database; however, it will remove any associated objects, causing
    4019:      * them to be refetched by subsequent calls to accessor method.
    4020:      *
    4021:      * @return void
    4022:      * @see        addAccessorysRelatedByProductId()
    4023:      */
    4024:     public function clearAccessorysRelatedByProductId()
    4025:     {
    4026:         $this->collAccessorysRelatedByProductId = null; // important to set this to null since that means it is uninitialized
    4027:         $this->collAccessorysRelatedByProductIdPartial = null;
    4028:     }
    4029:
    4030:     /**
    4031:      * reset is the collAccessorysRelatedByProductId collection loaded partially
    4032:      *
    4033:      * @return void
    4034:      */
    4035:     public function resetPartialAccessorysRelatedByProductId($v = true)
    4036:     {
    4037:         $this->collAccessorysRelatedByProductIdPartial = $v;
    4038:     }
    4039:
    4040:     /**
    4041:      * Initializes the collAccessorysRelatedByProductId collection.
    4042:      *
    4043:      * By default this just sets the collAccessorysRelatedByProductId collection to an empty array (like clearcollAccessorysRelatedByProductId());
    4044:      * however, you may wish to override this method in your stub class to provide setting appropriate
    4045:      * to your application -- for example, setting the initial array to the values stored in database.
    4046:      *
    4047:      * @param boolean $overrideExisting If set to true, the method call initializes
    4048:      *                                        the collection even if it is not empty
    4049:      *
    4050:      * @return void
    4051:      */
    4052:     public function initAccessorysRelatedByProductId($overrideExisting = true)
    4053:     {
    4054:         if (null !== $this->collAccessorysRelatedByProductId && !$overrideExisting) {
    4055:             return;
    4056:         }
    4057:         $this->collAccessorysRelatedByProductId = new PropelObjectCollection();
    4058:         $this->collAccessorysRelatedByProductId->setModel('Accessory');
    4059:     }
    4060:
    4061:     /**
    4062:      * Gets an array of Accessory objects which contain a foreign key that references this object.
    4063:      *
    4064:      * If the $criteria is not null, it is used to always fetch the results from the database.
    4065:      * Otherwise the results are fetched from the database the first time, then cached.
    4066:      * Next time the same method is called without $criteria, the cached collection is returned.
    4067:      * If this Product is new, it will return
    4068:      * an empty collection or the current collection; the criteria is ignored on a new object.
    4069:      *
    4070:      * @param Criteria $criteria optional Criteria object to narrow the query
    4071:      * @param PropelPDO $con optional connection object
    4072:      * @return PropelObjectCollection|Accessory[] List of Accessory objects
    4073:      * @throws PropelException
    4074:      */
    4075:     public function getAccessorysRelatedByProductId($criteria = null, PropelPDO $con = null)
    4076:     {
    4077:         $partial = $this->collAccessorysRelatedByProductIdPartial && !$this->isNew();
    4078:         if (null === $this->collAccessorysRelatedByProductId || null !== $criteria  || $partial) {
    4079:             if ($this->isNew() && null === $this->collAccessorysRelatedByProductId) {
    4080:                 // return empty collection
    4081:                 $this->initAccessorysRelatedByProductId();
    4082:             } else {
    4083:                 $collAccessorysRelatedByProductId = AccessoryQuery::create(null, $criteria)
    4084:                     ->filterByProductRelatedByProductId($this)
    4085:                     ->find($con);
    4086:                 if (null !== $criteria) {
    4087:                     if (false !== $this->collAccessorysRelatedByProductIdPartial && count($collAccessorysRelatedByProductId)) {
    4088:                       $this->initAccessorysRelatedByProductId(false);
    4089:
    4090:                       foreach($collAccessorysRelatedByProductId as $obj) {
    4091:                         if (false == $this->collAccessorysRelatedByProductId->contains($obj)) {
    4092:                           $this->collAccessorysRelatedByProductId->append($obj);
    4093:                         }
    4094:                       }
    4095:
    4096:                       $this->collAccessorysRelatedByProductIdPartial = true;
    4097:                     }
    4098:
    4099:                     return $collAccessorysRelatedByProductId;
    4100:                 }
    4101:
    4102:                 if($partial && $this->collAccessorysRelatedByProductId) {
    4103:                     foreach($this->collAccessorysRelatedByProductId as $obj) {
    4104:                         if($obj->isNew()) {
    4105:                             $collAccessorysRelatedByProductId[] = $obj;
    4106:                         }
    4107:                     }
    4108:                 }
    4109:
    4110:                 $this->collAccessorysRelatedByProductId = $collAccessorysRelatedByProductId;
    4111:                 $this->collAccessorysRelatedByProductIdPartial = false;
    4112:             }
    4113:         }
    4114:
    4115:         return $this->collAccessorysRelatedByProductId;
    4116:     }
    4117:
    4118:     /**
    4119:      * Sets a collection of AccessoryRelatedByProductId objects related by a one-to-many relationship
    4120:      * to the current object.
    4121:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    4122:      * and new objects from the given Propel collection.
    4123:      *
    4124:      * @param PropelCollection $accessorysRelatedByProductId A Propel collection.
    4125:      * @param PropelPDO $con Optional connection object
    4126:      */
    4127:     public function setAccessorysRelatedByProductId(PropelCollection $accessorysRelatedByProductId, PropelPDO $con = null)
    4128:     {
    4129:         $this->accessorysRelatedByProductIdScheduledForDeletion = $this->getAccessorysRelatedByProductId(new Criteria(), $con)->diff($accessorysRelatedByProductId);
    4130:
    4131:         foreach ($this->accessorysRelatedByProductIdScheduledForDeletion as $accessoryRelatedByProductIdRemoved) {
    4132:             $accessoryRelatedByProductIdRemoved->setProductRelatedByProductId(null);
    4133:         }
    4134:
    4135:         $this->collAccessorysRelatedByProductId = null;
    4136:         foreach ($accessorysRelatedByProductId as $accessoryRelatedByProductId) {
    4137:             $this->addAccessoryRelatedByProductId($accessoryRelatedByProductId);
    4138:         }
    4139:
    4140:         $this->collAccessorysRelatedByProductId = $accessorysRelatedByProductId;
    4141:         $this->collAccessorysRelatedByProductIdPartial = false;
    4142:     }
    4143:
    4144:     /**
    4145:      * Returns the number of related Accessory objects.
    4146:      *
    4147:      * @param Criteria $criteria
    4148:      * @param boolean $distinct
    4149:      * @param PropelPDO $con
    4150:      * @return int             Count of related Accessory objects.
    4151:      * @throws PropelException
    4152:      */
    4153:     public function countAccessorysRelatedByProductId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    4154:     {
    4155:         $partial = $this->collAccessorysRelatedByProductIdPartial && !$this->isNew();
    4156:         if (null === $this->collAccessorysRelatedByProductId || null !== $criteria || $partial) {
    4157:             if ($this->isNew() && null === $this->collAccessorysRelatedByProductId) {
    4158:                 return 0;
    4159:             } else {
    4160:                 if($partial && !$criteria) {
    4161:                     return count($this->getAccessorysRelatedByProductId());
    4162:                 }
    4163:                 $query = AccessoryQuery::create(null, $criteria);
    4164:                 if ($distinct) {
    4165:                     $query->distinct();
    4166:                 }
    4167:
    4168:                 return $query
    4169:                     ->filterByProductRelatedByProductId($this)
    4170:                     ->count($con);
    4171:             }
    4172:         } else {
    4173:             return count($this->collAccessorysRelatedByProductId);
    4174:         }
    4175:     }
    4176:
    4177:     /**
    4178:      * Method called to associate a Accessory object to this object
    4179:      * through the Accessory foreign key attribute.
    4180:      *
    4181:      * @param    Accessory $l Accessory
    4182:      * @return Product The current object (for fluent API support)
    4183:      */
    4184:     public function addAccessoryRelatedByProductId(Accessory $l)
    4185:     {
    4186:         if ($this->collAccessorysRelatedByProductId === null) {
    4187:             $this->initAccessorysRelatedByProductId();
    4188:             $this->collAccessorysRelatedByProductIdPartial = true;
    4189:         }
    4190:         if (!$this->collAccessorysRelatedByProductId->contains($l)) { // only add it if the **same** object is not already associated
    4191:             $this->doAddAccessoryRelatedByProductId($l);
    4192:         }
    4193:
    4194:         return $this;
    4195:     }
    4196:
    4197:     /**
    4198:      * @param   AccessoryRelatedByProductId $accessoryRelatedByProductId The accessoryRelatedByProductId object to add.
    4199:      */
    4200:     protected function doAddAccessoryRelatedByProductId($accessoryRelatedByProductId)
    4201:     {
    4202:         $this->collAccessorysRelatedByProductId[]= $accessoryRelatedByProductId;
    4203:         $accessoryRelatedByProductId->setProductRelatedByProductId($this);
    4204:     }
    4205:
    4206:     /**
    4207:      * @param   AccessoryRelatedByProductId $accessoryRelatedByProductId The accessoryRelatedByProductId object to remove.
    4208:      */
    4209:     public function removeAccessoryRelatedByProductId($accessoryRelatedByProductId)
    4210:     {
    4211:         if ($this->getAccessorysRelatedByProductId()->contains($accessoryRelatedByProductId)) {
    4212:             $this->collAccessorysRelatedByProductId->remove($this->collAccessorysRelatedByProductId->search($accessoryRelatedByProductId));
    4213:             if (null === $this->accessorysRelatedByProductIdScheduledForDeletion) {
    4214:                 $this->accessorysRelatedByProductIdScheduledForDeletion = clone $this->collAccessorysRelatedByProductId;
    4215:                 $this->accessorysRelatedByProductIdScheduledForDeletion->clear();
    4216:             }
    4217:             $this->accessorysRelatedByProductIdScheduledForDeletion[]= $accessoryRelatedByProductId;
    4218:             $accessoryRelatedByProductId->setProductRelatedByProductId(null);
    4219:         }
    4220:     }
    4221:
    4222:     /**
    4223:      * Clears out the collAccessorysRelatedByAccessory collection
    4224:      *
    4225:      * This does not modify the database; however, it will remove any associated objects, causing
    4226:      * them to be refetched by subsequent calls to accessor method.
    4227:      *
    4228:      * @return void
    4229:      * @see        addAccessorysRelatedByAccessory()
    4230:      */
    4231:     public function clearAccessorysRelatedByAccessory()
    4232:     {
    4233:         $this->collAccessorysRelatedByAccessory = null; // important to set this to null since that means it is uninitialized
    4234:         $this->collAccessorysRelatedByAccessoryPartial = null;
    4235:     }
    4236:
    4237:     /**
    4238:      * reset is the collAccessorysRelatedByAccessory collection loaded partially
    4239:      *
    4240:      * @return void
    4241:      */
    4242:     public function resetPartialAccessorysRelatedByAccessory($v = true)
    4243:     {
    4244:         $this->collAccessorysRelatedByAccessoryPartial = $v;
    4245:     }
    4246:
    4247:     /**
    4248:      * Initializes the collAccessorysRelatedByAccessory collection.
    4249:      *
    4250:      * By default this just sets the collAccessorysRelatedByAccessory collection to an empty array (like clearcollAccessorysRelatedByAccessory());
    4251:      * however, you may wish to override this method in your stub class to provide setting appropriate
    4252:      * to your application -- for example, setting the initial array to the values stored in database.
    4253:      *
    4254:      * @param boolean $overrideExisting If set to true, the method call initializes
    4255:      *                                        the collection even if it is not empty
    4256:      *
    4257:      * @return void
    4258:      */
    4259:     public function initAccessorysRelatedByAccessory($overrideExisting = true)
    4260:     {
    4261:         if (null !== $this->collAccessorysRelatedByAccessory && !$overrideExisting) {
    4262:             return;
    4263:         }
    4264:         $this->collAccessorysRelatedByAccessory = new PropelObjectCollection();
    4265:         $this->collAccessorysRelatedByAccessory->setModel('Accessory');
    4266:     }
    4267:
    4268:     /**
    4269:      * Gets an array of Accessory objects which contain a foreign key that references this object.
    4270:      *
    4271:      * If the $criteria is not null, it is used to always fetch the results from the database.
    4272:      * Otherwise the results are fetched from the database the first time, then cached.
    4273:      * Next time the same method is called without $criteria, the cached collection is returned.
    4274:      * If this Product is new, it will return
    4275:      * an empty collection or the current collection; the criteria is ignored on a new object.
    4276:      *
    4277:      * @param Criteria $criteria optional Criteria object to narrow the query
    4278:      * @param PropelPDO $con optional connection object
    4279:      * @return PropelObjectCollection|Accessory[] List of Accessory objects
    4280:      * @throws PropelException
    4281:      */
    4282:     public function getAccessorysRelatedByAccessory($criteria = null, PropelPDO $con = null)
    4283:     {
    4284:         $partial = $this->collAccessorysRelatedByAccessoryPartial && !$this->isNew();
    4285:         if (null === $this->collAccessorysRelatedByAccessory || null !== $criteria  || $partial) {
    4286:             if ($this->isNew() && null === $this->collAccessorysRelatedByAccessory) {
    4287:                 // return empty collection
    4288:                 $this->initAccessorysRelatedByAccessory();
    4289:             } else {
    4290:                 $collAccessorysRelatedByAccessory = AccessoryQuery::create(null, $criteria)
    4291:                     ->filterByProductRelatedByAccessory($this)
    4292:                     ->find($con);
    4293:                 if (null !== $criteria) {
    4294:                     if (false !== $this->collAccessorysRelatedByAccessoryPartial && count($collAccessorysRelatedByAccessory)) {
    4295:                       $this->initAccessorysRelatedByAccessory(false);
    4296:
    4297:                       foreach($collAccessorysRelatedByAccessory as $obj) {
    4298:                         if (false == $this->collAccessorysRelatedByAccessory->contains($obj)) {
    4299:                           $this->collAccessorysRelatedByAccessory->append($obj);
    4300:                         }
    4301:                       }
    4302:
    4303:                       $this->collAccessorysRelatedByAccessoryPartial = true;
    4304:                     }
    4305:
    4306:                     return $collAccessorysRelatedByAccessory;
    4307:                 }
    4308:
    4309:                 if($partial && $this->collAccessorysRelatedByAccessory) {
    4310:                     foreach($this->collAccessorysRelatedByAccessory as $obj) {
    4311:                         if($obj->isNew()) {
    4312:                             $collAccessorysRelatedByAccessory[] = $obj;
    4313:                         }
    4314:                     }
    4315:                 }
    4316:
    4317:                 $this->collAccessorysRelatedByAccessory = $collAccessorysRelatedByAccessory;
    4318:                 $this->collAccessorysRelatedByAccessoryPartial = false;
    4319:             }
    4320:         }
    4321:
    4322:         return $this->collAccessorysRelatedByAccessory;
    4323:     }
    4324:
    4325:     /**
    4326:      * Sets a collection of AccessoryRelatedByAccessory objects related by a one-to-many relationship
    4327:      * to the current object.
    4328:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    4329:      * and new objects from the given Propel collection.
    4330:      *
    4331:      * @param PropelCollection $accessorysRelatedByAccessory A Propel collection.
    4332:      * @param PropelPDO $con Optional connection object
    4333:      */
    4334:     public function setAccessorysRelatedByAccessory(PropelCollection $accessorysRelatedByAccessory, PropelPDO $con = null)
    4335:     {
    4336:         $this->accessorysRelatedByAccessoryScheduledForDeletion = $this->getAccessorysRelatedByAccessory(new Criteria(), $con)->diff($accessorysRelatedByAccessory);
    4337:
    4338:         foreach ($this->accessorysRelatedByAccessoryScheduledForDeletion as $accessoryRelatedByAccessoryRemoved) {
    4339:             $accessoryRelatedByAccessoryRemoved->setProductRelatedByAccessory(null);
    4340:         }
    4341:
    4342:         $this->collAccessorysRelatedByAccessory = null;
    4343:         foreach ($accessorysRelatedByAccessory as $accessoryRelatedByAccessory) {
    4344:             $this->addAccessoryRelatedByAccessory($accessoryRelatedByAccessory);
    4345:         }
    4346:
    4347:         $this->collAccessorysRelatedByAccessory = $accessorysRelatedByAccessory;
    4348:         $this->collAccessorysRelatedByAccessoryPartial = false;
    4349:     }
    4350:
    4351:     /**
    4352:      * Returns the number of related Accessory objects.
    4353:      *
    4354:      * @param Criteria $criteria
    4355:      * @param boolean $distinct
    4356:      * @param PropelPDO $con
    4357:      * @return int             Count of related Accessory objects.
    4358:      * @throws PropelException
    4359:      */
    4360:     public function countAccessorysRelatedByAccessory(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    4361:     {
    4362:         $partial = $this->collAccessorysRelatedByAccessoryPartial && !$this->isNew();
    4363:         if (null === $this->collAccessorysRelatedByAccessory || null !== $criteria || $partial) {
    4364:             if ($this->isNew() && null === $this->collAccessorysRelatedByAccessory) {
    4365:                 return 0;
    4366:             } else {
    4367:                 if($partial && !$criteria) {
    4368:                     return count($this->getAccessorysRelatedByAccessory());
    4369:                 }
    4370:                 $query = AccessoryQuery::create(null, $criteria);
    4371:                 if ($distinct) {
    4372:                     $query->distinct();
    4373:                 }
    4374:
    4375:                 return $query
    4376:                     ->filterByProductRelatedByAccessory($this)
    4377:                     ->count($con);
    4378:             }
    4379:         } else {
    4380:             return count($this->collAccessorysRelatedByAccessory);
    4381:         }
    4382:     }
    4383:
    4384:     /**
    4385:      * Method called to associate a Accessory object to this object
    4386:      * through the Accessory foreign key attribute.
    4387:      *
    4388:      * @param    Accessory $l Accessory
    4389:      * @return Product The current object (for fluent API support)
    4390:      */
    4391:     public function addAccessoryRelatedByAccessory(Accessory $l)
    4392:     {
    4393:         if ($this->collAccessorysRelatedByAccessory === null) {
    4394:             $this->initAccessorysRelatedByAccessory();
    4395:             $this->collAccessorysRelatedByAccessoryPartial = true;
    4396:         }
    4397:         if (!$this->collAccessorysRelatedByAccessory->contains($l)) { // only add it if the **same** object is not already associated
    4398:             $this->doAddAccessoryRelatedByAccessory($l);
    4399:         }
    4400:
    4401:         return $this;
    4402:     }
    4403:
    4404:     /**
    4405:      * @param   AccessoryRelatedByAccessory $accessoryRelatedByAccessory The accessoryRelatedByAccessory object to add.
    4406:      */
    4407:     protected function doAddAccessoryRelatedByAccessory($accessoryRelatedByAccessory)
    4408:     {
    4409:         $this->collAccessorysRelatedByAccessory[]= $accessoryRelatedByAccessory;
    4410:         $accessoryRelatedByAccessory->setProductRelatedByAccessory($this);
    4411:     }
    4412:
    4413:     /**
    4414:      * @param   AccessoryRelatedByAccessory $accessoryRelatedByAccessory The accessoryRelatedByAccessory object to remove.
    4415:      */
    4416:     public function removeAccessoryRelatedByAccessory($accessoryRelatedByAccessory)
    4417:     {
    4418:         if ($this->getAccessorysRelatedByAccessory()->contains($accessoryRelatedByAccessory)) {
    4419:             $this->collAccessorysRelatedByAccessory->remove($this->collAccessorysRelatedByAccessory->search($accessoryRelatedByAccessory));
    4420:             if (null === $this->accessorysRelatedByAccessoryScheduledForDeletion) {
    4421:                 $this->accessorysRelatedByAccessoryScheduledForDeletion = clone $this->collAccessorysRelatedByAccessory;
    4422:                 $this->accessorysRelatedByAccessoryScheduledForDeletion->clear();
    4423:             }
    4424:             $this->accessorysRelatedByAccessoryScheduledForDeletion[]= $accessoryRelatedByAccessory;
    4425:             $accessoryRelatedByAccessory->setProductRelatedByAccessory(null);
    4426:         }
    4427:     }
    4428:
    4429:     /**
    4430:      * Clears out the collRewritings collection
    4431:      *
    4432:      * This does not modify the database; however, it will remove any associated objects, causing
    4433:      * them to be refetched by subsequent calls to accessor method.
    4434:      *
    4435:      * @return void
    4436:      * @see        addRewritings()
    4437:      */
    4438:     public function clearRewritings()
    4439:     {
    4440:         $this->collRewritings = null; // important to set this to null since that means it is uninitialized
    4441:         $this->collRewritingsPartial = null;
    4442:     }
    4443:
    4444:     /**
    4445:      * reset is the collRewritings collection loaded partially
    4446:      *
    4447:      * @return void
    4448:      */
    4449:     public function resetPartialRewritings($v = true)
    4450:     {
    4451:         $this->collRewritingsPartial = $v;
    4452:     }
    4453:
    4454:     /**
    4455:      * Initializes the collRewritings collection.
    4456:      *
    4457:      * By default this just sets the collRewritings collection to an empty array (like clearcollRewritings());
    4458:      * however, you may wish to override this method in your stub class to provide setting appropriate
    4459:      * to your application -- for example, setting the initial array to the values stored in database.
    4460:      *
    4461:      * @param boolean $overrideExisting If set to true, the method call initializes
    4462:      *                                        the collection even if it is not empty
    4463:      *
    4464:      * @return void
    4465:      */
    4466:     public function initRewritings($overrideExisting = true)
    4467:     {
    4468:         if (null !== $this->collRewritings && !$overrideExisting) {
    4469:             return;
    4470:         }
    4471:         $this->collRewritings = new PropelObjectCollection();
    4472:         $this->collRewritings->setModel('Rewriting');
    4473:     }
    4474:
    4475:     /**
    4476:      * Gets an array of Rewriting objects which contain a foreign key that references this object.
    4477:      *
    4478:      * If the $criteria is not null, it is used to always fetch the results from the database.
    4479:      * Otherwise the results are fetched from the database the first time, then cached.
    4480:      * Next time the same method is called without $criteria, the cached collection is returned.
    4481:      * If this Product is new, it will return
    4482:      * an empty collection or the current collection; the criteria is ignored on a new object.
    4483:      *
    4484:      * @param Criteria $criteria optional Criteria object to narrow the query
    4485:      * @param PropelPDO $con optional connection object
    4486:      * @return PropelObjectCollection|Rewriting[] List of Rewriting objects
    4487:      * @throws PropelException
    4488:      */
    4489:     public function getRewritings($criteria = null, PropelPDO $con = null)
    4490:     {
    4491:         $partial = $this->collRewritingsPartial && !$this->isNew();
    4492:         if (null === $this->collRewritings || null !== $criteria  || $partial) {
    4493:             if ($this->isNew() && null === $this->collRewritings) {
    4494:                 // return empty collection
    4495:                 $this->initRewritings();
    4496:             } else {
    4497:                 $collRewritings = RewritingQuery::create(null, $criteria)
    4498:                     ->filterByProduct($this)
    4499:                     ->find($con);
    4500:                 if (null !== $criteria) {
    4501:                     if (false !== $this->collRewritingsPartial && count($collRewritings)) {
    4502:                       $this->initRewritings(false);
    4503:
    4504:                       foreach($collRewritings as $obj) {
    4505:                         if (false == $this->collRewritings->contains($obj)) {
    4506:                           $this->collRewritings->append($obj);
    4507:                         }
    4508:                       }
    4509:
    4510:                       $this->collRewritingsPartial = true;
    4511:                     }
    4512:
    4513:                     return $collRewritings;
    4514:                 }
    4515:
    4516:                 if($partial && $this->collRewritings) {
    4517:                     foreach($this->collRewritings as $obj) {
    4518:                         if($obj->isNew()) {
    4519:                             $collRewritings[] = $obj;
    4520:                         }
    4521:                     }
    4522:                 }
    4523:
    4524:                 $this->collRewritings = $collRewritings;
    4525:                 $this->collRewritingsPartial = false;
    4526:             }
    4527:         }
    4528:
    4529:         return $this->collRewritings;
    4530:     }
    4531:
    4532:     /**
    4533:      * Sets a collection of Rewriting objects related by a one-to-many relationship
    4534:      * to the current object.
    4535:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    4536:      * and new objects from the given Propel collection.
    4537:      *
    4538:      * @param PropelCollection $rewritings A Propel collection.
    4539:      * @param PropelPDO $con Optional connection object
    4540:      */
    4541:     public function setRewritings(PropelCollection $rewritings, PropelPDO $con = null)
    4542:     {
    4543:         $this->rewritingsScheduledForDeletion = $this->getRewritings(new Criteria(), $con)->diff($rewritings);
    4544:
    4545:         foreach ($this->rewritingsScheduledForDeletion as $rewritingRemoved) {
    4546:             $rewritingRemoved->setProduct(null);
    4547:         }
    4548:
    4549:         $this->collRewritings = null;
    4550:         foreach ($rewritings as $rewriting) {
    4551:             $this->addRewriting($rewriting);
    4552:         }
    4553:
    4554:         $this->collRewritings = $rewritings;
    4555:         $this->collRewritingsPartial = false;
    4556:     }
    4557:
    4558:     /**
    4559:      * Returns the number of related Rewriting objects.
    4560:      *
    4561:      * @param Criteria $criteria
    4562:      * @param boolean $distinct
    4563:      * @param PropelPDO $con
    4564:      * @return int             Count of related Rewriting objects.
    4565:      * @throws PropelException
    4566:      */
    4567:     public function countRewritings(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    4568:     {
    4569:         $partial = $this->collRewritingsPartial && !$this->isNew();
    4570:         if (null === $this->collRewritings || null !== $criteria || $partial) {
    4571:             if ($this->isNew() && null === $this->collRewritings) {
    4572:                 return 0;
    4573:             } else {
    4574:                 if($partial && !$criteria) {
    4575:                     return count($this->getRewritings());
    4576:                 }
    4577:                 $query = RewritingQuery::create(null, $criteria);
    4578:                 if ($distinct) {
    4579:                     $query->distinct();
    4580:                 }
    4581:
    4582:                 return $query
    4583:                     ->filterByProduct($this)
    4584:                     ->count($con);
    4585:             }
    4586:         } else {
    4587:             return count($this->collRewritings);
    4588:         }
    4589:     }
    4590:
    4591:     /**
    4592:      * Method called to associate a Rewriting object to this object
    4593:      * through the Rewriting foreign key attribute.
    4594:      *
    4595:      * @param    Rewriting $l Rewriting
    4596:      * @return Product The current object (for fluent API support)
    4597:      */
    4598:     public function addRewriting(Rewriting $l)
    4599:     {
    4600:         if ($this->collRewritings === null) {
    4601:             $this->initRewritings();
    4602:             $this->collRewritingsPartial = true;
    4603:         }
    4604:         if (!$this->collRewritings->contains($l)) { // only add it if the **same** object is not already associated
    4605:             $this->doAddRewriting($l);
    4606:         }
    4607:
    4608:         return $this;
    4609:     }
    4610:
    4611:     /**
    4612:      * @param   Rewriting $rewriting The rewriting object to add.
    4613:      */
    4614:     protected function doAddRewriting($rewriting)
    4615:     {
    4616:         $this->collRewritings[]= $rewriting;
    4617:         $rewriting->setProduct($this);
    4618:     }
    4619:
    4620:     /**
    4621:      * @param   Rewriting $rewriting The rewriting object to remove.
    4622:      */
    4623:     public function removeRewriting($rewriting)
    4624:     {
    4625:         if ($this->getRewritings()->contains($rewriting)) {
    4626:             $this->collRewritings->remove($this->collRewritings->search($rewriting));
    4627:             if (null === $this->rewritingsScheduledForDeletion) {
    4628:                 $this->rewritingsScheduledForDeletion = clone $this->collRewritings;
    4629:                 $this->rewritingsScheduledForDeletion->clear();
    4630:             }
    4631:             $this->rewritingsScheduledForDeletion[]= $rewriting;
    4632:             $rewriting->setProduct(null);
    4633:         }
    4634:     }
    4635:
    4636:
    4637:     /**
    4638:      * If this collection has already been initialized with
    4639:      * an identical criteria, it returns the collection.
    4640:      * Otherwise if this Product is new, it will return
    4641:      * an empty collection; or if this Product has previously
    4642:      * been saved, it will retrieve related Rewritings from storage.
    4643:      *
    4644:      * This method is protected by default in order to keep the public
    4645:      * api reasonable.  You can provide public methods for those you
    4646:      * actually need in Product.
    4647:      *
    4648:      * @param Criteria $criteria optional Criteria object to narrow the query
    4649:      * @param PropelPDO $con optional connection object
    4650:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    4651:      * @return PropelObjectCollection|Rewriting[] List of Rewriting objects
    4652:      */
    4653:     public function getRewritingsJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    4654:     {
    4655:         $query = RewritingQuery::create(null, $criteria);
    4656:         $query->joinWith('Category', $join_behavior);
    4657:
    4658:         return $this->getRewritings($query, $con);
    4659:     }
    4660:
    4661:
    4662:     /**
    4663:      * If this collection has already been initialized with
    4664:      * an identical criteria, it returns the collection.
    4665:      * Otherwise if this Product is new, it will return
    4666:      * an empty collection; or if this Product has previously
    4667:      * been saved, it will retrieve related Rewritings from storage.
    4668:      *
    4669:      * This method is protected by default in order to keep the public
    4670:      * api reasonable.  You can provide public methods for those you
    4671:      * actually need in Product.
    4672:      *
    4673:      * @param Criteria $criteria optional Criteria object to narrow the query
    4674:      * @param PropelPDO $con optional connection object
    4675:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    4676:      * @return PropelObjectCollection|Rewriting[] List of Rewriting objects
    4677:      */
    4678:     public function getRewritingsJoinFolder($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    4679:     {
    4680:         $query = RewritingQuery::create(null, $criteria);
    4681:         $query->joinWith('Folder', $join_behavior);
    4682:
    4683:         return $this->getRewritings($query, $con);
    4684:     }
    4685:
    4686:
    4687:     /**
    4688:      * If this collection has already been initialized with
    4689:      * an identical criteria, it returns the collection.
    4690:      * Otherwise if this Product is new, it will return
    4691:      * an empty collection; or if this Product has previously
    4692:      * been saved, it will retrieve related Rewritings from storage.
    4693:      *
    4694:      * This method is protected by default in order to keep the public
    4695:      * api reasonable.  You can provide public methods for those you
    4696:      * actually need in Product.
    4697:      *
    4698:      * @param Criteria $criteria optional Criteria object to narrow the query
    4699:      * @param PropelPDO $con optional connection object
    4700:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    4701:      * @return PropelObjectCollection|Rewriting[] List of Rewriting objects
    4702:      */
    4703:     public function getRewritingsJoinContent($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    4704:     {
    4705:         $query = RewritingQuery::create(null, $criteria);
    4706:         $query->joinWith('Content', $join_behavior);
    4707:
    4708:         return $this->getRewritings($query, $con);
    4709:     }
    4710:
    4711:     /**
    4712:      * Clears out the collProductI18ns collection
    4713:      *
    4714:      * This does not modify the database; however, it will remove any associated objects, causing
    4715:      * them to be refetched by subsequent calls to accessor method.
    4716:      *
    4717:      * @return void
    4718:      * @see        addProductI18ns()
    4719:      */
    4720:     public function clearProductI18ns()
    4721:     {
    4722:         $this->collProductI18ns = null; // important to set this to null since that means it is uninitialized
    4723:         $this->collProductI18nsPartial = null;
    4724:     }
    4725:
    4726:     /**
    4727:      * reset is the collProductI18ns collection loaded partially
    4728:      *
    4729:      * @return void
    4730:      */
    4731:     public function resetPartialProductI18ns($v = true)
    4732:     {
    4733:         $this->collProductI18nsPartial = $v;
    4734:     }
    4735:
    4736:     /**
    4737:      * Initializes the collProductI18ns collection.
    4738:      *
    4739:      * By default this just sets the collProductI18ns collection to an empty array (like clearcollProductI18ns());
    4740:      * however, you may wish to override this method in your stub class to provide setting appropriate
    4741:      * to your application -- for example, setting the initial array to the values stored in database.
    4742:      *
    4743:      * @param boolean $overrideExisting If set to true, the method call initializes
    4744:      *                                        the collection even if it is not empty
    4745:      *
    4746:      * @return void
    4747:      */
    4748:     public function initProductI18ns($overrideExisting = true)
    4749:     {
    4750:         if (null !== $this->collProductI18ns && !$overrideExisting) {
    4751:             return;
    4752:         }
    4753:         $this->collProductI18ns = new PropelObjectCollection();
    4754:         $this->collProductI18ns->setModel('ProductI18n');
    4755:     }
    4756:
    4757:     /**
    4758:      * Gets an array of ProductI18n objects which contain a foreign key that references this object.
    4759:      *
    4760:      * If the $criteria is not null, it is used to always fetch the results from the database.
    4761:      * Otherwise the results are fetched from the database the first time, then cached.
    4762:      * Next time the same method is called without $criteria, the cached collection is returned.
    4763:      * If this Product is new, it will return
    4764:      * an empty collection or the current collection; the criteria is ignored on a new object.
    4765:      *
    4766:      * @param Criteria $criteria optional Criteria object to narrow the query
    4767:      * @param PropelPDO $con optional connection object
    4768:      * @return PropelObjectCollection|ProductI18n[] List of ProductI18n objects
    4769:      * @throws PropelException
    4770:      */
    4771:     public function getProductI18ns($criteria = null, PropelPDO $con = null)
    4772:     {
    4773:         $partial = $this->collProductI18nsPartial && !$this->isNew();
    4774:         if (null === $this->collProductI18ns || null !== $criteria  || $partial) {
    4775:             if ($this->isNew() && null === $this->collProductI18ns) {
    4776:                 // return empty collection
    4777:                 $this->initProductI18ns();
    4778:             } else {
    4779:                 $collProductI18ns = ProductI18nQuery::create(null, $criteria)
    4780:                     ->filterByProduct($this)
    4781:                     ->find($con);
    4782:                 if (null !== $criteria) {
    4783:                     if (false !== $this->collProductI18nsPartial && count($collProductI18ns)) {
    4784:                       $this->initProductI18ns(false);
    4785:
    4786:                       foreach($collProductI18ns as $obj) {
    4787:                         if (false == $this->collProductI18ns->contains($obj)) {
    4788:                           $this->collProductI18ns->append($obj);
    4789:                         }
    4790:                       }
    4791:
    4792:                       $this->collProductI18nsPartial = true;
    4793:                     }
    4794:
    4795:                     return $collProductI18ns;
    4796:                 }
    4797:
    4798:                 if($partial && $this->collProductI18ns) {
    4799:                     foreach($this->collProductI18ns as $obj) {
    4800:                         if($obj->isNew()) {
    4801:                             $collProductI18ns[] = $obj;
    4802:                         }
    4803:                     }
    4804:                 }
    4805:
    4806:                 $this->collProductI18ns = $collProductI18ns;
    4807:                 $this->collProductI18nsPartial = false;
    4808:             }
    4809:         }
    4810:
    4811:         return $this->collProductI18ns;
    4812:     }
    4813:
    4814:     /**
    4815:      * Sets a collection of ProductI18n objects related by a one-to-many relationship
    4816:      * to the current object.
    4817:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    4818:      * and new objects from the given Propel collection.
    4819:      *
    4820:      * @param PropelCollection $productI18ns A Propel collection.
    4821:      * @param PropelPDO $con Optional connection object
    4822:      */
    4823:     public function setProductI18ns(PropelCollection $productI18ns, PropelPDO $con = null)
    4824:     {
    4825:         $this->productI18nsScheduledForDeletion = $this->getProductI18ns(new Criteria(), $con)->diff($productI18ns);
    4826:
    4827:         foreach ($this->productI18nsScheduledForDeletion as $productI18nRemoved) {
    4828:             $productI18nRemoved->setProduct(null);
    4829:         }
    4830:
    4831:         $this->collProductI18ns = null;
    4832:         foreach ($productI18ns as $productI18n) {
    4833:             $this->addProductI18n($productI18n);
    4834:         }
    4835:
    4836:         $this->collProductI18ns = $productI18ns;
    4837:         $this->collProductI18nsPartial = false;
    4838:     }
    4839:
    4840:     /**
    4841:      * Returns the number of related ProductI18n objects.
    4842:      *
    4843:      * @param Criteria $criteria
    4844:      * @param boolean $distinct
    4845:      * @param PropelPDO $con
    4846:      * @return int             Count of related ProductI18n objects.
    4847:      * @throws PropelException
    4848:      */
    4849:     public function countProductI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    4850:     {
    4851:         $partial = $this->collProductI18nsPartial && !$this->isNew();
    4852:         if (null === $this->collProductI18ns || null !== $criteria || $partial) {
    4853:             if ($this->isNew() && null === $this->collProductI18ns) {
    4854:                 return 0;
    4855:             } else {
    4856:                 if($partial && !$criteria) {
    4857:                     return count($this->getProductI18ns());
    4858:                 }
    4859:                 $query = ProductI18nQuery::create(null, $criteria);
    4860:                 if ($distinct) {
    4861:                     $query->distinct();
    4862:                 }
    4863:
    4864:                 return $query
    4865:                     ->filterByProduct($this)
    4866:                     ->count($con);
    4867:             }
    4868:         } else {
    4869:             return count($this->collProductI18ns);
    4870:         }
    4871:     }
    4872:
    4873:     /**
    4874:      * Method called to associate a ProductI18n object to this object
    4875:      * through the ProductI18n foreign key attribute.
    4876:      *
    4877:      * @param    ProductI18n $l ProductI18n
    4878:      * @return Product The current object (for fluent API support)
    4879:      */
    4880:     public function addProductI18n(ProductI18n $l)
    4881:     {
    4882:         if ($l && $locale = $l->getLocale()) {
    4883:             $this->setLocale($locale);
    4884:             $this->currentTranslations[$locale] = $l;
    4885:         }
    4886:         if ($this->collProductI18ns === null) {
    4887:             $this->initProductI18ns();
    4888:             $this->collProductI18nsPartial = true;
    4889:         }
    4890:         if (!$this->collProductI18ns->contains($l)) { // only add it if the **same** object is not already associated
    4891:             $this->doAddProductI18n($l);
    4892:         }
    4893:
    4894:         return $this;
    4895:     }
    4896:
    4897:     /**
    4898:      * @param   ProductI18n $productI18n The productI18n object to add.
    4899:      */
    4900:     protected function doAddProductI18n($productI18n)
    4901:     {
    4902:         $this->collProductI18ns[]= $productI18n;
    4903:         $productI18n->setProduct($this);
    4904:     }
    4905:
    4906:     /**
    4907:      * @param   ProductI18n $productI18n The productI18n object to remove.
    4908:      */
    4909:     public function removeProductI18n($productI18n)
    4910:     {
    4911:         if ($this->getProductI18ns()->contains($productI18n)) {
    4912:             $this->collProductI18ns->remove($this->collProductI18ns->search($productI18n));
    4913:             if (null === $this->productI18nsScheduledForDeletion) {
    4914:                 $this->productI18nsScheduledForDeletion = clone $this->collProductI18ns;
    4915:                 $this->productI18nsScheduledForDeletion->clear();
    4916:             }
    4917:             $this->productI18nsScheduledForDeletion[]= $productI18n;
    4918:             $productI18n->setProduct(null);
    4919:         }
    4920:     }
    4921:
    4922:     /**
    4923:      * Clears out the collProductVersions collection
    4924:      *
    4925:      * This does not modify the database; however, it will remove any associated objects, causing
    4926:      * them to be refetched by subsequent calls to accessor method.
    4927:      *
    4928:      * @return void
    4929:      * @see        addProductVersions()
    4930:      */
    4931:     public function clearProductVersions()
    4932:     {
    4933:         $this->collProductVersions = null; // important to set this to null since that means it is uninitialized
    4934:         $this->collProductVersionsPartial = null;
    4935:     }
    4936:
    4937:     /**
    4938:      * reset is the collProductVersions collection loaded partially
    4939:      *
    4940:      * @return void
    4941:      */
    4942:     public function resetPartialProductVersions($v = true)
    4943:     {
    4944:         $this->collProductVersionsPartial = $v;
    4945:     }
    4946:
    4947:     /**
    4948:      * Initializes the collProductVersions collection.
    4949:      *
    4950:      * By default this just sets the collProductVersions collection to an empty array (like clearcollProductVersions());
    4951:      * however, you may wish to override this method in your stub class to provide setting appropriate
    4952:      * to your application -- for example, setting the initial array to the values stored in database.
    4953:      *
    4954:      * @param boolean $overrideExisting If set to true, the method call initializes
    4955:      *                                        the collection even if it is not empty
    4956:      *
    4957:      * @return void
    4958:      */
    4959:     public function initProductVersions($overrideExisting = true)
    4960:     {
    4961:         if (null !== $this->collProductVersions && !$overrideExisting) {
    4962:             return;
    4963:         }
    4964:         $this->collProductVersions = new PropelObjectCollection();
    4965:         $this->collProductVersions->setModel('ProductVersion');
    4966:     }
    4967:
    4968:     /**
    4969:      * Gets an array of ProductVersion objects which contain a foreign key that references this object.
    4970:      *
    4971:      * If the $criteria is not null, it is used to always fetch the results from the database.
    4972:      * Otherwise the results are fetched from the database the first time, then cached.
    4973:      * Next time the same method is called without $criteria, the cached collection is returned.
    4974:      * If this Product is new, it will return
    4975:      * an empty collection or the current collection; the criteria is ignored on a new object.
    4976:      *
    4977:      * @param Criteria $criteria optional Criteria object to narrow the query
    4978:      * @param PropelPDO $con optional connection object
    4979:      * @return PropelObjectCollection|ProductVersion[] List of ProductVersion objects
    4980:      * @throws PropelException
    4981:      */
    4982:     public function getProductVersions($criteria = null, PropelPDO $con = null)
    4983:     {
    4984:         $partial = $this->collProductVersionsPartial && !$this->isNew();
    4985:         if (null === $this->collProductVersions || null !== $criteria  || $partial) {
    4986:             if ($this->isNew() && null === $this->collProductVersions) {
    4987:                 // return empty collection
    4988:                 $this->initProductVersions();
    4989:             } else {
    4990:                 $collProductVersions = ProductVersionQuery::create(null, $criteria)
    4991:                     ->filterByProduct($this)
    4992:                     ->find($con);
    4993:                 if (null !== $criteria) {
    4994:                     if (false !== $this->collProductVersionsPartial && count($collProductVersions)) {
    4995:                       $this->initProductVersions(false);
    4996:
    4997:                       foreach($collProductVersions as $obj) {
    4998:                         if (false == $this->collProductVersions->contains($obj)) {
    4999:                           $this->collProductVersions->append($obj);
    5000:                         }
    5001:                       }
    5002:
    5003:                       $this->collProductVersionsPartial = true;
    5004:                     }
    5005:
    5006:                     return $collProductVersions;
    5007:                 }
    5008:
    5009:                 if($partial && $this->collProductVersions) {
    5010:                     foreach($this->collProductVersions as $obj) {
    5011:                         if($obj->isNew()) {
    5012:                             $collProductVersions[] = $obj;
    5013:                         }
    5014:                     }
    5015:                 }
    5016:
    5017:                 $this->collProductVersions = $collProductVersions;
    5018:                 $this->collProductVersionsPartial = false;
    5019:             }
    5020:         }
    5021:
    5022:         return $this->collProductVersions;
    5023:     }
    5024:
    5025:     /**
    5026:      * Sets a collection of ProductVersion objects related by a one-to-many relationship
    5027:      * to the current object.
    5028:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    5029:      * and new objects from the given Propel collection.
    5030:      *
    5031:      * @param PropelCollection $productVersions A Propel collection.
    5032:      * @param PropelPDO $con Optional connection object
    5033:      */
    5034:     public function setProductVersions(PropelCollection $productVersions, PropelPDO $con = null)
    5035:     {
    5036:         $this->productVersionsScheduledForDeletion = $this->getProductVersions(new Criteria(), $con)->diff($productVersions);
    5037:
    5038:         foreach ($this->productVersionsScheduledForDeletion as $productVersionRemoved) {
    5039:             $productVersionRemoved->setProduct(null);
    5040:         }
    5041:
    5042:         $this->collProductVersions = null;
    5043:         foreach ($productVersions as $productVersion) {
    5044:             $this->addProductVersion($productVersion);
    5045:         }
    5046:
    5047:         $this->collProductVersions = $productVersions;
    5048:         $this->collProductVersionsPartial = false;
    5049:     }
    5050:
    5051:     /**
    5052:      * Returns the number of related ProductVersion objects.
    5053:      *
    5054:      * @param Criteria $criteria
    5055:      * @param boolean $distinct
    5056:      * @param PropelPDO $con
    5057:      * @return int             Count of related ProductVersion objects.
    5058:      * @throws PropelException
    5059:      */
    5060:     public function countProductVersions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    5061:     {
    5062:         $partial = $this->collProductVersionsPartial && !$this->isNew();
    5063:         if (null === $this->collProductVersions || null !== $criteria || $partial) {
    5064:             if ($this->isNew() && null === $this->collProductVersions) {
    5065:                 return 0;
    5066:             } else {
    5067:                 if($partial && !$criteria) {
    5068:                     return count($this->getProductVersions());
    5069:                 }
    5070:                 $query = ProductVersionQuery::create(null, $criteria);
    5071:                 if ($distinct) {
    5072:                     $query->distinct();
    5073:                 }
    5074:
    5075:                 return $query
    5076:                     ->filterByProduct($this)
    5077:                     ->count($con);
    5078:             }
    5079:         } else {
    5080:             return count($this->collProductVersions);
    5081:         }
    5082:     }
    5083:
    5084:     /**
    5085:      * Method called to associate a ProductVersion object to this object
    5086:      * through the ProductVersion foreign key attribute.
    5087:      *
    5088:      * @param    ProductVersion $l ProductVersion
    5089:      * @return Product The current object (for fluent API support)
    5090:      */
    5091:     public function addProductVersion(ProductVersion $l)
    5092:     {
    5093:         if ($this->collProductVersions === null) {
    5094:             $this->initProductVersions();
    5095:             $this->collProductVersionsPartial = true;
    5096:         }
    5097:         if (!$this->collProductVersions->contains($l)) { // only add it if the **same** object is not already associated
    5098:             $this->doAddProductVersion($l);
    5099:         }
    5100:
    5101:         return $this;
    5102:     }
    5103:
    5104:     /**
    5105:      * @param   ProductVersion $productVersion The productVersion object to add.
    5106:      */
    5107:     protected function doAddProductVersion($productVersion)
    5108:     {
    5109:         $this->collProductVersions[]= $productVersion;
    5110:         $productVersion->setProduct($this);
    5111:     }
    5112:
    5113:     /**
    5114:      * @param   ProductVersion $productVersion The productVersion object to remove.
    5115:      */
    5116:     public function removeProductVersion($productVersion)
    5117:     {
    5118:         if ($this->getProductVersions()->contains($productVersion)) {
    5119:             $this->collProductVersions->remove($this->collProductVersions->search($productVersion));
    5120:             if (null === $this->productVersionsScheduledForDeletion) {
    5121:                 $this->productVersionsScheduledForDeletion = clone $this->collProductVersions;
    5122:                 $this->productVersionsScheduledForDeletion->clear();
    5123:             }
    5124:             $this->productVersionsScheduledForDeletion[]= $productVersion;
    5125:             $productVersion->setProduct(null);
    5126:         }
    5127:     }
    5128:
    5129:     /**
    5130:      * Clears the current object and sets all attributes to their default values
    5131:      */
    5132:     public function clear()
    5133:     {
    5134:         $this->id = null;
    5135:         $this->tax_rule_id = null;
    5136:         $this->ref = null;
    5137:         $this->price = null;
    5138:         $this->price2 = null;
    5139:         $this->ecotax = null;
    5140:         $this->newness = null;
    5141:         $this->promo = null;
    5142:         $this->stock = null;
    5143:         $this->visible = null;
    5144:         $this->weight = null;
    5145:         $this->position = null;
    5146:         $this->created_at = null;
    5147:         $this->updated_at = null;
    5148:         $this->version = null;
    5149:         $this->version_created_at = null;
    5150:         $this->version_created_by = null;
    5151:         $this->alreadyInSave = false;
    5152:         $this->alreadyInValidation = false;
    5153:         $this->clearAllReferences();
    5154:         $this->applyDefaultValues();
    5155:         $this->resetModified();
    5156:         $this->setNew(true);
    5157:         $this->setDeleted(false);
    5158:     }
    5159:
    5160:     /**
    5161:      * Resets all references to other model objects or collections of model objects.
    5162:      *
    5163:      * This method is a user-space workaround for PHP's inability to garbage collect
    5164:      * objects with circular references (even in PHP 5.3). This is currently necessary
    5165:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    5166:      *
    5167:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    5168:      */
    5169:     public function clearAllReferences($deep = false)
    5170:     {
    5171:         if ($deep) {
    5172:             if ($this->collProductCategorys) {
    5173:                 foreach ($this->collProductCategorys as $o) {
    5174:                     $o->clearAllReferences($deep);
    5175:                 }
    5176:             }
    5177:             if ($this->collFeatureProds) {
    5178:                 foreach ($this->collFeatureProds as $o) {
    5179:                     $o->clearAllReferences($deep);
    5180:                 }
    5181:             }
    5182:             if ($this->collStocks) {
    5183:                 foreach ($this->collStocks as $o) {
    5184:                     $o->clearAllReferences($deep);
    5185:                 }
    5186:             }
    5187:             if ($this->collContentAssocs) {
    5188:                 foreach ($this->collContentAssocs as $o) {
    5189:                     $o->clearAllReferences($deep);
    5190:                 }
    5191:             }
    5192:             if ($this->collImages) {
    5193:                 foreach ($this->collImages as $o) {
    5194:                     $o->clearAllReferences($deep);
    5195:                 }
    5196:             }
    5197:             if ($this->collDocuments) {
    5198:                 foreach ($this->collDocuments as $o) {
    5199:                     $o->clearAllReferences($deep);
    5200:                 }
    5201:             }
    5202:             if ($this->collAccessorysRelatedByProductId) {
    5203:                 foreach ($this->collAccessorysRelatedByProductId as $o) {
    5204:                     $o->clearAllReferences($deep);
    5205:                 }
    5206:             }
    5207:             if ($this->collAccessorysRelatedByAccessory) {
    5208:                 foreach ($this->collAccessorysRelatedByAccessory as $o) {
    5209:                     $o->clearAllReferences($deep);
    5210:                 }
    5211:             }
    5212:             if ($this->collRewritings) {
    5213:                 foreach ($this->collRewritings as $o) {
    5214:                     $o->clearAllReferences($deep);
    5215:                 }
    5216:             }
    5217:             if ($this->collProductI18ns) {
    5218:                 foreach ($this->collProductI18ns as $o) {
    5219:                     $o->clearAllReferences($deep);
    5220:                 }
    5221:             }
    5222:             if ($this->collProductVersions) {
    5223:                 foreach ($this->collProductVersions as $o) {
    5224:                     $o->clearAllReferences($deep);
    5225:                 }
    5226:             }
    5227:         } // if ($deep)
    5228:
    5229:         // i18n behavior
    5230:         $this->currentLocale = 'en_EN';
    5231:         $this->currentTranslations = null;
    5232:
    5233:         if ($this->collProductCategorys instanceof PropelCollection) {
    5234:             $this->collProductCategorys->clearIterator();
    5235:         }
    5236:         $this->collProductCategorys = null;
    5237:         if ($this->collFeatureProds instanceof PropelCollection) {
    5238:             $this->collFeatureProds->clearIterator();
    5239:         }
    5240:         $this->collFeatureProds = null;
    5241:         if ($this->collStocks instanceof PropelCollection) {
    5242:             $this->collStocks->clearIterator();
    5243:         }
    5244:         $this->collStocks = null;
    5245:         if ($this->collContentAssocs instanceof PropelCollection) {
    5246:             $this->collContentAssocs->clearIterator();
    5247:         }
    5248:         $this->collContentAssocs = null;
    5249:         if ($this->collImages instanceof PropelCollection) {
    5250:             $this->collImages->clearIterator();
    5251:         }
    5252:         $this->collImages = null;
    5253:         if ($this->collDocuments instanceof PropelCollection) {
    5254:             $this->collDocuments->clearIterator();
    5255:         }
    5256:         $this->collDocuments = null;
    5257:         if ($this->collAccessorysRelatedByProductId instanceof PropelCollection) {
    5258:             $this->collAccessorysRelatedByProductId->clearIterator();
    5259:         }
    5260:         $this->collAccessorysRelatedByProductId = null;
    5261:         if ($this->collAccessorysRelatedByAccessory instanceof PropelCollection) {
    5262:             $this->collAccessorysRelatedByAccessory->clearIterator();
    5263:         }
    5264:         $this->collAccessorysRelatedByAccessory = null;
    5265:         if ($this->collRewritings instanceof PropelCollection) {
    5266:             $this->collRewritings->clearIterator();
    5267:         }
    5268:         $this->collRewritings = null;
    5269:         if ($this->collProductI18ns instanceof PropelCollection) {
    5270:             $this->collProductI18ns->clearIterator();
    5271:         }
    5272:         $this->collProductI18ns = null;
    5273:         if ($this->collProductVersions instanceof PropelCollection) {
    5274:             $this->collProductVersions->clearIterator();
    5275:         }
    5276:         $this->collProductVersions = null;
    5277:         $this->aTaxRule = null;
    5278:     }
    5279:
    5280:     /**
    5281:      * return the string representation of this object
    5282:      *
    5283:      * @return string
    5284:      */
    5285:     public function __toString()
    5286:     {
    5287:         return (string) $this->exportTo(ProductPeer::DEFAULT_STRING_FORMAT);
    5288:     }
    5289:
    5290:     /**
    5291:      * return true is the object is in saving state
    5292:      *
    5293:      * @return boolean
    5294:      */
    5295:     public function isAlreadyInSave()
    5296:     {
    5297:         return $this->alreadyInSave;
    5298:     }
    5299:
    5300:     // timestampable behavior
    5301:
    5302:     /**
    5303:      * Mark the current object so that the update date doesn't get updated during next save
    5304:      *
    5305:      * @return     Product The current object (for fluent API support)
    5306:      */
    5307:     public function keepUpdateDateUnchanged()
    5308:     {
    5309:         $this->modifiedColumns[] = ProductPeer::UPDATED_AT;
    5310:
    5311:         return $this;
    5312:     }
    5313:
    5314:     // i18n behavior
    5315:
    5316:     /**
    5317:      * Sets the locale for translations
    5318:      *
    5319:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    5320:      *
    5321:      * @return    Product The current object (for fluent API support)
    5322:      */
    5323:     public function setLocale($locale = 'en_EN')
    5324:     {
    5325:         $this->currentLocale = $locale;
    5326:
    5327:         return $this;
    5328:     }
    5329:
    5330:     /**
    5331:      * Gets the locale for translations
    5332:      *
    5333:      * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
    5334:      */
    5335:     public function getLocale()
    5336:     {
    5337:         return $this->currentLocale;
    5338:     }
    5339:
    5340:     /**
    5341:      * Returns the current translation for a given locale
    5342:      *
    5343:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    5344:      * @param     PropelPDO $con an optional connection object
    5345:      *
    5346:      * @return ProductI18n */
    5347:     public function getTranslation($locale = 'en_EN', PropelPDO $con = null)
    5348:     {
    5349:         if (!isset($this->currentTranslations[$locale])) {
    5350:             if (null !== $this->collProductI18ns) {
    5351:                 foreach ($this->collProductI18ns as $translation) {
    5352:                     if ($translation->getLocale() == $locale) {
    5353:                         $this->currentTranslations[$locale] = $translation;
    5354:
    5355:                         return $translation;
    5356:                     }
    5357:                 }
    5358:             }
    5359:             if ($this->isNew()) {
    5360:                 $translation = new ProductI18n();
    5361:                 $translation->setLocale($locale);
    5362:             } else {
    5363:                 $translation = ProductI18nQuery::create()
    5364:                     ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    5365:                     ->findOneOrCreate($con);
    5366:                 $this->currentTranslations[$locale] = $translation;
    5367:             }
    5368:             $this->addProductI18n($translation);
    5369:         }
    5370:
    5371:         return $this->currentTranslations[$locale];
    5372:     }
    5373:
    5374:     /**
    5375:      * Remove the translation for a given locale
    5376:      *
    5377:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    5378:      * @param     PropelPDO $con an optional connection object
    5379:      *
    5380:      * @return    Product The current object (for fluent API support)
    5381:      */
    5382:     public function removeTranslation($locale = 'en_EN', PropelPDO $con = null)
    5383:     {
    5384:         if (!$this->isNew()) {
    5385:             ProductI18nQuery::create()
    5386:                 ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    5387:                 ->delete($con);
    5388:         }
    5389:         if (isset($this->currentTranslations[$locale])) {
    5390:             unset($this->currentTranslations[$locale]);
    5391:         }
    5392:         foreach ($this->collProductI18ns as $key => $translation) {
    5393:             if ($translation->getLocale() == $locale) {
    5394:                 unset($this->collProductI18ns[$key]);
    5395:                 break;
    5396:             }
    5397:         }
    5398:
    5399:         return $this;
    5400:     }
    5401:
    5402:     /**
    5403:      * Returns the current translation
    5404:      *
    5405:      * @param     PropelPDO $con an optional connection object
    5406:      *
    5407:      * @return ProductI18n */
    5408:     public function getCurrentTranslation(PropelPDO $con = null)
    5409:     {
    5410:         return $this->getTranslation($this->getLocale(), $con);
    5411:     }
    5412:
    5413:
    5414:         /**
    5415:          * Get the [title] column value.
    5416:          *
    5417:          * @return string
    5418:          */
    5419:         public function getTitle()
    5420:         {
    5421:         return $this->getCurrentTranslation()->getTitle();
    5422:     }
    5423:
    5424:
    5425:         /**
    5426:          * Set the value of [title] column.
    5427:          *
    5428:          * @param string $v new value
    5429:          * @return ProductI18n The current object (for fluent API support)
    5430:          */
    5431:         public function setTitle($v)
    5432:         {    $this->getCurrentTranslation()->setTitle($v);
    5433:
    5434:         return $this;
    5435:     }
    5436:
    5437:
    5438:         /**
    5439:          * Get the [description] column value.
    5440:          *
    5441:          * @return string
    5442:          */
    5443:         public function getDescription()
    5444:         {
    5445:         return $this->getCurrentTranslation()->getDescription();
    5446:     }
    5447:
    5448:
    5449:         /**
    5450:          * Set the value of [description] column.
    5451:          *
    5452:          * @param string $v new value
    5453:          * @return ProductI18n The current object (for fluent API support)
    5454:          */
    5455:         public function setDescription($v)
    5456:         {    $this->getCurrentTranslation()->setDescription($v);
    5457:
    5458:         return $this;
    5459:     }
    5460:
    5461:
    5462:         /**
    5463:          * Get the [chapo] column value.
    5464:          *
    5465:          * @return string
    5466:          */
    5467:         public function getChapo()
    5468:         {
    5469:         return $this->getCurrentTranslation()->getChapo();
    5470:     }
    5471:
    5472:
    5473:         /**
    5474:          * Set the value of [chapo] column.
    5475:          *
    5476:          * @param string $v new value
    5477:          * @return ProductI18n The current object (for fluent API support)
    5478:          */
    5479:         public function setChapo($v)
    5480:         {    $this->getCurrentTranslation()->setChapo($v);
    5481:
    5482:         return $this;
    5483:     }
    5484:
    5485:
    5486:         /**
    5487:          * Get the [postscriptum] column value.
    5488:          *
    5489:          * @return string
    5490:          */
    5491:         public function getPostscriptum()
    5492:         {
    5493:         return $this->getCurrentTranslation()->getPostscriptum();
    5494:     }
    5495:
    5496:
    5497:         /**
    5498:          * Set the value of [postscriptum] column.
    5499:          *
    5500:          * @param string $v new value
    5501:          * @return ProductI18n The current object (for fluent API support)
    5502:          */
    5503:         public function setPostscriptum($v)
    5504:         {    $this->getCurrentTranslation()->setPostscriptum($v);
    5505:
    5506:         return $this;
    5507:     }
    5508:
    5509:     // versionable behavior
    5510:
    5511:     /**
    5512:      * Enforce a new Version of this object upon next save.
    5513:      *
    5514:      * @return Product
    5515:      */
    5516:     public function enforceVersioning()
    5517:     {
    5518:         $this->enforceVersion = true;
    5519:
    5520:         return $this;
    5521:     }
    5522:
    5523:     /**
    5524:      * Checks whether the current state must be recorded as a version
    5525:      *
    5526:      * @param PropelPDO $con An optional PropelPDO connection to use.
    5527:      *
    5528:      * @return  boolean
    5529:      */
    5530:     public function isVersioningNecessary($con = null)
    5531:     {
    5532:         if ($this->alreadyInSave) {
    5533:             return false;
    5534:         }
    5535:
    5536:         if ($this->enforceVersion) {
    5537:             return true;
    5538:         }
    5539:
    5540:         if (ProductPeer::isVersioningEnabled() && ($this->isNew() || $this->isModified() || $this->isDeleted())) {
    5541:             return true;
    5542:         }
    5543:
    5544:         return false;
    5545:     }
    5546:
    5547:     /**
    5548:      * Creates a version of the current object and saves it.
    5549:      *
    5550:      * @param   PropelPDO $con the connection to use
    5551:      *
    5552:      * @return  ProductVersion A version object
    5553:      */
    5554:     public function addVersion($con = null)
    5555:     {
    5556:         $this->enforceVersion = false;
    5557:
    5558:         $version = new ProductVersion();
    5559:         $version->setId($this->getId());
    5560:         $version->setTaxRuleId($this->getTaxRuleId());
    5561:         $version->setRef($this->getRef());
    5562:         $version->setPrice($this->getPrice());
    5563:         $version->setPrice2($this->getPrice2());
    5564:         $version->setEcotax($this->getEcotax());
    5565:         $version->setNewness($this->getNewness());
    5566:         $version->setPromo($this->getPromo());
    5567:         $version->setStock($this->getStock());
    5568:         $version->setVisible($this->getVisible());
    5569:         $version->setWeight($this->getWeight());
    5570:         $version->setPosition($this->getPosition());
    5571:         $version->setCreatedAt($this->getCreatedAt());
    5572:         $version->setUpdatedAt($this->getUpdatedAt());
    5573:         $version->setVersion($this->getVersion());
    5574:         $version->setVersionCreatedAt($this->getVersionCreatedAt());
    5575:         $version->setVersionCreatedBy($this->getVersionCreatedBy());
    5576:         $version->setProduct($this);
    5577:         $version->save($con);
    5578:
    5579:         return $version;
    5580:     }
    5581:
    5582:     /**
    5583:      * Sets the properties of the curent object to the value they had at a specific version
    5584:      *
    5585:      * @param   integer $versionNumber The version number to read
    5586:      * @param   PropelPDO $con the connection to use
    5587:      *
    5588:      * @return  Product The current object (for fluent API support)
    5589:      * @throws  PropelException - if no object with the given version can be found.
    5590:      */
    5591:     public function toVersion($versionNumber, $con = null)
    5592:     {
    5593:         $version = $this->getOneVersion($versionNumber, $con);
    5594:         if (!$version) {
    5595:             throw new PropelException(sprintf('No Product object found with version %d', $version));
    5596:         }
    5597:         $this->populateFromVersion($version, $con);
    5598:
    5599:         return $this;
    5600:     }
    5601:
    5602:     /**
    5603:      * Sets the properties of the curent object to the value they had at a specific version
    5604:      *
    5605:      * @param   ProductVersion $version The version object to use
    5606:      * @param   PropelPDO $con the connection to use
    5607:      * @param   array $loadedObjects objects thats been loaded in a chain of populateFromVersion calls on referrer or fk objects.
    5608:      *
    5609:      * @return  Product The current object (for fluent API support)
    5610:      */
    5611:     public function populateFromVersion($version, $con = null, &$loadedObjects = array())
    5612:     {
    5613:
    5614:         $loadedObjects['Product'][$version->getId()][$version->getVersion()] = $this;
    5615:         $this->setId($version->getId());
    5616:         $this->setTaxRuleId($version->getTaxRuleId());
    5617:         $this->setRef($version->getRef());
    5618:         $this->setPrice($version->getPrice());
    5619:         $this->setPrice2($version->getPrice2());
    5620:         $this->setEcotax($version->getEcotax());
    5621:         $this->setNewness($version->getNewness());
    5622:         $this->setPromo($version->getPromo());
    5623:         $this->setStock($version->getStock());
    5624:         $this->setVisible($version->getVisible());
    5625:         $this->setWeight($version->getWeight());
    5626:         $this->setPosition($version->getPosition());
    5627:         $this->setCreatedAt($version->getCreatedAt());
    5628:         $this->setUpdatedAt($version->getUpdatedAt());
    5629:         $this->setVersion($version->getVersion());
    5630:         $this->setVersionCreatedAt($version->getVersionCreatedAt());
    5631:         $this->setVersionCreatedBy($version->getVersionCreatedBy());
    5632:
    5633:         return $this;
    5634:     }
    5635:
    5636:     /**
    5637:      * Gets the latest persisted version number for the current object
    5638:      *
    5639:      * @param   PropelPDO $con the connection to use
    5640:      *
    5641:      * @return  integer
    5642:      */
    5643:     public function getLastVersionNumber($con = null)
    5644:     {
    5645:         $v = ProductVersionQuery::create()
    5646:             ->filterByProduct($this)
    5647:             ->orderByVersion('desc')
    5648:             ->findOne($con);
    5649:         if (!$v) {
    5650:             return 0;
    5651:         }
    5652:
    5653:         return $v->getVersion();
    5654:     }
    5655:
    5656:     /**
    5657:      * Checks whether the current object is the latest one
    5658:      *
    5659:      * @param   PropelPDO $con the connection to use
    5660:      *
    5661:      * @return  boolean
    5662:      */
    5663:     public function isLastVersion($con = null)
    5664:     {
    5665:         return $this->getLastVersionNumber($con) == $this->getVersion();
    5666:     }
    5667:
    5668:     /**
    5669:      * Retrieves a version object for this entity and a version number
    5670:      *
    5671:      * @param   integer $versionNumber The version number to read
    5672:      * @param   PropelPDO $con the connection to use
    5673:      *
    5674:      * @return  ProductVersion A version object
    5675:      */
    5676:     public function getOneVersion($versionNumber, $con = null)
    5677:     {
    5678:         return ProductVersionQuery::create()
    5679:             ->filterByProduct($this)
    5680:             ->filterByVersion($versionNumber)
    5681:             ->findOne($con);
    5682:     }
    5683:
    5684:     /**
    5685:      * Gets all the versions of this object, in incremental order
    5686:      *
    5687:      * @param   PropelPDO $con the connection to use
    5688:      *
    5689:      * @return  PropelObjectCollection A list of ProductVersion objects
    5690:      */
    5691:     public function getAllVersions($con = null)
    5692:     {
    5693:         $criteria = new Criteria();
    5694:         $criteria->addAscendingOrderByColumn(ProductVersionPeer::VERSION);
    5695:
    5696:         return $this->getProductVersions($criteria, $con);
    5697:     }
    5698:
    5699:     /**
    5700:      * Compares the current object with another of its version.
    5701:      * <code>
    5702:      * print_r($book->compareVersion(1));
    5703:      * => array(
    5704:      *   '1' => array('Title' => 'Book title at version 1'),
    5705:      *   '2' => array('Title' => 'Book title at version 2')
    5706:      * );
    5707:      * </code>
    5708:      *
    5709:      * @param   integer   $versionNumber
    5710:      * @param   string    $keys Main key used for the result diff (versions|columns)
    5711:      * @param   PropelPDO $con the connection to use
    5712:      * @param   array     $ignoredColumns  The columns to exclude from the diff.
    5713:      *
    5714:      * @return  array A list of differences
    5715:      */
    5716:     public function compareVersion($versionNumber, $keys = 'columns', $con = null, $ignoredColumns = array())
    5717:     {
    5718:         $fromVersion = $this->toArray();
    5719:         $toVersion = $this->getOneVersion($versionNumber, $con)->toArray();
    5720:
    5721:         return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns);
    5722:     }
    5723:
    5724:     /**
    5725:      * Compares two versions of the current object.
    5726:      * <code>
    5727:      * print_r($book->compareVersions(1, 2));
    5728:      * => array(
    5729:      *   '1' => array('Title' => 'Book title at version 1'),
    5730:      *   '2' => array('Title' => 'Book title at version 2')
    5731:      * );
    5732:      * </code>
    5733:      *
    5734:      * @param   integer   $fromVersionNumber
    5735:      * @param   integer   $toVersionNumber
    5736:      * @param   string    $keys Main key used for the result diff (versions|columns)
    5737:      * @param   PropelPDO $con the connection to use
    5738:      * @param   array     $ignoredColumns  The columns to exclude from the diff.
    5739:      *
    5740:      * @return  array A list of differences
    5741:      */
    5742:     public function compareVersions($fromVersionNumber, $toVersionNumber, $keys = 'columns', $con = null, $ignoredColumns = array())
    5743:     {
    5744:         $fromVersion = $this->getOneVersion($fromVersionNumber, $con)->toArray();
    5745:         $toVersion = $this->getOneVersion($toVersionNumber, $con)->toArray();
    5746:
    5747:         return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns);
    5748:     }
    5749:
    5750:     /**
    5751:      * Computes the diff between two versions.
    5752:      * <code>
    5753:      * print_r($this->computeDiff(1, 2));
    5754:      * => array(
    5755:      *   '1' => array('Title' => 'Book title at version 1'),
    5756:      *   '2' => array('Title' => 'Book title at version 2')
    5757:      * );
    5758:      * </code>
    5759:      *
    5760:      * @param   array     $fromVersion     An array representing the original version.
    5761:      * @param   array     $toVersion       An array representing the destination version.
    5762:      * @param   string    $keys            Main key used for the result diff (versions|columns).
    5763:      * @param   array     $ignoredColumns  The columns to exclude from the diff.
    5764:      *
    5765:      * @return  array A list of differences
    5766:      */
    5767:     protected function computeDiff($fromVersion, $toVersion, $keys = 'columns', $ignoredColumns = array())
    5768:     {
    5769:         $fromVersionNumber = $fromVersion['Version'];
    5770:         $toVersionNumber = $toVersion['Version'];
    5771:         $ignoredColumns = array_merge(array(
    5772:             'Version',
    5773:             'VersionCreatedAt',
    5774:             'VersionCreatedBy',
    5775:         ), $ignoredColumns);
    5776:         $diff = array();
    5777:         foreach ($fromVersion as $key => $value) {
    5778:             if (in_array($key, $ignoredColumns)) {
    5779:                 continue;
    5780:             }
    5781:             if ($toVersion[$key] != $value) {
    5782:                 switch ($keys) {
    5783:                     case 'versions':
    5784:                         $diff[$fromVersionNumber][$key] = $value;
    5785:                         $diff[$toVersionNumber][$key] = $toVersion[$key];
    5786:                         break;
    5787:                     default:
    5788:                         $diff[$key] = array(
    5789:                             $fromVersionNumber => $value,
    5790:                             $toVersionNumber => $toVersion[$key],
    5791:                         );
    5792:                         break;
    5793:                 }
    5794:             }
    5795:         }
    5796:
    5797:         return $diff;
    5798:     }
    5799:     /**
    5800:      * retrieve the last $number versions.
    5801:      *
    5802:      * @param integer $number the number of record to return.
    5803:      * @param ProductVersionQuery|Criteria $criteria Additional criteria to filter.
    5804:      * @param PropelPDO $con An optional connection to use.
    5805:      *
    5806:      * @return PropelCollection|ProductVersion[] List of ProductVersion objects
    5807:      */
    5808:     public function getLastVersions($number = 10, $criteria = null, PropelPDO $con = null)
    5809:     {
    5810:         $criteria = ProductVersionQuery::create(null, $criteria);
    5811:         $criteria->addDescendingOrderByColumn(ProductVersionPeer::VERSION);
    5812:         $criteria->limit($number);
    5813:
    5814:         return $this->getProductVersions($criteria, $con);
    5815:     }
    5816: }
    5817: