Esempio n. 1
0
 public function generateTestInvoices()
 {
     return;
     ClassLoader::import('application.model.category.*');
     ClassLoader::import('application.model.product.*');
     $config = ActiveRecordModel::getApplication()->getConfig();
     $config->set('RECURRING_BILLING_PAYMENT_DUE_DATE_DAYS', 7);
     $config->save();
     // data
     $userID = 110;
     $product1ID = 339;
     $recurringProductPeriodID = 19;
     // ~
     // create first order
     $user = User::getInstanceByID($userID, true);
     $product1 = Product::getInstanceByID($product1ID, true);
     $order = CustomerOrder::getNewInstance($user);
     $order->save(true);
     $rpp = RecurringProductPeriod::getInstanceByID($recurringProductPeriodID);
     $item = $order->addProduct($product1, 1, true);
     $item->save();
     $recurringItem = RecurringItem::getNewInstance($rpp, $item);
     $recurringItem->setupPrice->set(100);
     $recurringItem->periodPrice->set(25);
     $recurringItem->save();
     $order->finalize();
     // generate invoices
     echo '<pre>Invoices for {CustomerOrder ID:' . $order->getID() . '}:', "\n";
     $now = time();
     for ($ts = $now; $ts < strtotime('+20 months', $now); $ts = $ts + 60 * 60 * 24) {
         $z = CustomerOrder::generateRecurringInvoices(date('Y-m-d', $ts));
         foreach ($z as $id) {
             echo '{CustomerOrder ID:' . $id . '}', "\n";
         }
     }
     die('-done-</pre>');
 }
Esempio n. 2
0
 private function addProductToCart($id, $prefix = '')
 {
     if ($prefix && !$this->request->get($prefix . 'count')) {
         return '"';
     }
     $product = Product::getInstanceByID($id, true, array('Category'));
     $productRedirect = new ActionRedirectResponse('product', 'index', array('id' => $product->getID(), 'query' => 'return=' . $this->request->get('return')));
     if (!$product->isAvailable()) {
         $productController = new ProductController($this->application);
         $productController->setErrorMessage($this->translate('_product_unavailable'));
         return $productRedirect;
     }
     $variations = !$product->parent->get() ? $product->getVariationData($this->application) : array();
     ClassLoader::import('application.controller.ProductController');
     $validator = ProductController::buildAddToCartValidator($product->getOptions(true)->toArray(), $variations, $prefix);
     if (!$validator->isValid()) {
         return $productRedirect;
     }
     // check if a variation needs to be added to cart instead of a parent product
     if ($variations) {
         $product = $this->getVariationFromRequest($variations);
     }
     $count = $this->request->get($prefix . 'count', 1);
     if ($count < $product->getMinimumQuantity()) {
         $count = $product->getMinimumQuantity();
     }
     $item = $this->order->addProduct($product, $count);
     if ($item instanceof OrderedItem) {
         $item->name->set($product->name->get());
         foreach ($product->getOptions(true) as $option) {
             $this->modifyItemOption($item, $option, $this->request, $prefix . 'option_' . $option->getID());
         }
         if ($this->order->isMultiAddress->get()) {
             $item->save();
         }
         if ($product->type->get() == Product::TYPE_RECURRING) {
             if ($item->isExistingRecord() == false) {
                 $item->save();
                 // or save in SessionOrder::save()
             }
             $recurringID = $this->getRequest()->get('recurringID');
             $recurringProductPeriod = $product->getRecurringProductPeriodById($recurringID);
             if ($recurringProductPeriod == null) {
                 $recurringProductPeriod = $product->getDefaultRecurringProductPeriod();
             }
             if ($recurringProductPeriod) {
                 $instance = RecurringItem::getNewInstance($recurringProductPeriod, $item);
                 $instance->save();
                 $item->updateBasePriceToCalculatedPrice();
             }
             // what if product with type recurring but no plan? just ignore?
         }
     }
 }
Esempio n. 3
0
 private function addRecurringProduct($order, $product, $count, $recurringProductPeriod, $setupPrice = 0, $periodPrice = 0, $shipment = null)
 {
     $item = $order->addProduct($product, $count, true, $shipment);
     $item->save();
     $recurringItem = RecurringItem::getNewInstance($recurringProductPeriod, $item);
     // pass setup and period prices here because createRecurringProductPeriod() does not create prices in ProductPrice table.
     $recurringItem->setupPrice->set((double) $setupPrice);
     $recurringItem->periodPrice->set((double) $periodPrice);
     $recurringItem->save();
     $product->type->set(Product::TYPE_RECURRING);
     return array($item, $recurringItem);
 }