/**
  * Constructor
  */
 public function __construct($product, $options)
 {
     // Important:
     // A subscription must always have a valid $product.
     // The following exception is for the sole purpose of making this class
     // compatible with the \Cx\Core\Html\Controller\ViewGenerator library
     // for autogenerating user-interfaces.
     if (!$product) {
         return;
     }
     $this->subscriptionDate = new \DateTime();
     $this->product = $product;
     $this->setProductEntity($product->getNewEntityForSale($options));
     $objCurrency = null;
     if ($this->getOrder()) {
         $objCurrency = $this->getOrder()->getCurrency();
     } else {
         $defaultCurrencyId = \Cx\Modules\Crm\Controller\CrmLibrary::getDefaultCurrencyId();
         $objCurrency = $defaultCurrencyId ? \Env::get('em')->getRepository('Cx\\Modules\\Crm\\Model\\Entity\\Currency')->findOneById($defaultCurrencyId) : null;
     }
     $this->paymentAmount = $product->getPaymentAmount($options['renewalUnit'], $options['renewalQuantifier'], $objCurrency);
     $this->paymentState = self::PAYMENT_OPEN;
     if ($product->isExpirable()) {
         $this->expirationDate = $product->getExpirationDate($options['renewalUnit'], $options['renewalQuantifier']);
     }
     if ($product->isRenewable()) {
         list($this->renewalUnit, $this->renewalQuantifier) = $product->getRenewalDefinition($options['renewalUnit'], $options['renewalQuantifier']);
         $this->renewalDate = $product->getRenewalDate($this->renewalUnit, $this->renewalQuantifier);
     }
     if (isset($options['description'])) {
         $this->setDescription($options['description']);
     }
     //Set state initialized to active.
     $this->state = self::STATE_ACTIVE;
 }