Пример #1
2
    public function getHtml()
    {
        $transHtml = array();
        $request = $this->controller->getRequest();
        if ($this->controller instanceof CheckoutController && $request->getActionName() == 'completed') {
            $session = new Session();
            if ($orderID = $session->get('completedOrderID')) {
                $order = CustomerOrder::getInstanceByID((int) $session->get('completedOrderID'), CustomerOrder::LOAD_DATA);
                $order->loadAll();
                $orderArray = $order->toArray();
                $data = array($order->getID(), '', $orderArray['total'][$orderArray['Currency']['ID']], $order->getTaxAmount(), $orderArray['ShippingAddress']['city'], $orderArray['ShippingAddress']['stateName'], $orderArray['ShippingAddress']['countryID']);
                $transHtml[] = 'pageTracker._addTrans' . $this->getJSParams($data);
                foreach ($orderArray['cartItems'] as $item) {
                    $data = array($order->getID(), $item['Product']['sku'], $item['Product']['name'], $item['Product']['Category']['name'], $item['price'], $item['count']);
                    $transHtml[] = 'pageTracker._addItem' . $this->getJSParams($data);
                }
            }
            $transHtml[] = 'pageTracker._trackTrans();';
        }
        return '<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("' . $this->getValue('code') . '");
pageTracker._initData();
pageTracker._trackPageview();
' . implode("\n", $transHtml) . '
</script>';
    }
Пример #2
0
 public function deleteInstancesByOrder(CustomerOrder $order)
 {
     // remove other ExpressCheckout instances for this order
     $f = new ARDeleteFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('ExpressCheckout', 'orderID'), $order->getID()));
     ActiveRecordModel::deleteRecordSet('ExpressCheckout', $f);
 }
Пример #3
0
 public function applyToOrder(CustomerOrder $order)
 {
     $amount = $order->getCurrency()->convertAmount(CustomerOrder::getApplication()->getDefaultCurrency(), $this->getDiscountAmount($order->totalAmount->get()));
     $orderDiscount = OrderDiscount::getNewInstance($order);
     $orderDiscount->amount->set($amount);
     $orderDiscount->description->set($this->parentCondition->getParam('name_lang'));
     $order->registerOrderDiscount($orderDiscount);
 }
Пример #4
0
 public function applyToOrder(CustomerOrder $order)
 {
     $currencyID = $this->getFieldValue('currency', '');
     if ($currencyID) {
         $currency = Currency::getInstanceById($currencyID);
         $order->changeCurrency($currency);
         ActiveRecordModel::getApplication()->getRequest()->set('currency', $currencyID);
     }
 }
Пример #5
0
 public static function getRecordSetByOrder(CustomerOrder $order, ARSelectFilter $filter = null, $loadReferencedRecords = false)
 {
     if (!$filter) {
         $filter = new ARSelectFilter();
     }
     $filter->mergeCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'orderID'), $order->getID()));
     $filter->setOrder(new ARFieldHandle(__CLASS__, 'time'), ARSelectFilter::ORDER_DESC);
     return self::getRecordSet($filter, $loadReferencedRecords);
 }
 /**
  * Sends an email receipt to customer
  *
  * @param  CustomerOrder $order
  * @return bool
  * @todo  Make subject configurable
  * @todo  Make tempalte more generic
  */
 public function emailCustomer($order)
 {
     $subject = 'Thank you for order on ' . date('Y-m-d' . '!') . ' from website';
     $from = SS_SEND_EMAIL_FROM;
     $to = $this->Email;
     $email = new Email();
     $email->setFrom($from)->setTo($to)->setSubject($subject)->setTemplate('CustomerEmail')->populateTemplate(new ArrayData(array('Customer' => $order->Customer(), 'CartItems' => $order->OrderItems(), 'ShippingCostTotal' => $order->shippingcost(), 'CartTotal' => $order->TotalAmount)));
     // $email->populateTemplate($order);
     $email->send();
 }
function parseOrderXml($xml)
{
    $orderArray =& $GLOBALS["orderArray"];
    foreach ($xml->customerOrder as $customerOrder) {
        $newOrder = new CustomerOrder($customerOrder);
        if ($newOrder->isEligibleDate()) {
            $orderArray[$newOrder->getUuid()] = $newOrder;
            $GLOBALS["numberOfOrders"]++;
        }
    }
}
Пример #8
0
 public function set()
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $orderID = $request->get('orderID');
     $shippingServiceID = $request->get('shippingServiceID');
     if (intval($orderID) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Shipment', 'orderID'), $orderID));
     } else {
         throw new Exception("Order ID is required");
     }
     $order = CustomerOrder::getInstanceById($orderID);
     $order->load();
     $order->loadAll();
     $shipments = $order->getShipments();
     foreach ($shipments as $key => $shipment) {
         $shipment->setRateId($shippingServiceID);
     }
     $order->serializeShipments();
     $order->save(true);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     return new SimpleXMLResponse($response);
 }
Пример #9
0
 private function reloadOrder(CustomerOrder $order)
 {
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceById($order->getID(), true);
     $order->loadAll();
     return $order;
 }
Пример #10
0
 function testTransactionCurrencyConverting()
 {
     $eur = Currency::getNewInstance('EUR');
     $eur->rate->set('3.4528');
     $eur->save();
     $this->products[0]->setPrice($this->usd, '9.99');
     $this->order->addProduct($this->products[0], 1);
     $this->order->save();
     $this->order->changeCurrency($this->usd);
     //$this->order->finalize();
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $details = new LiveCartTransaction($order, $eur);
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $this->assertEquals($details->amount->get(), '2.89');
     $result = new TransactionResult();
     $result->amount->set($details->amount->get());
     $result->currency->set($details->currency->get());
     $transaction = Transaction::getNewInstance($order, $result);
     $transaction->type->set(Transaction::TYPE_SALE);
     $this->assertEquals($transaction->amount->get(), '9.99');
     $this->assertEquals($transaction->realAmount->get(), '2.89');
     $transaction->save();
     $this->assertFalse((bool) $order->isFinalized->get());
     $order->finalize();
     $this->assertTrue((bool) $order->isFinalized->get());
     $this->assertEquals($order->getPaidAmount(), '9.99');
     $this->assertEquals($order->totalAmount->get(), '9.99');
     $this->assertTrue((bool) $order->isPaid->get());
 }
Пример #11
0
 public function getStatuses()
 {
     $this->setChartType(self::PIE);
     $q = $this->getQuery('COUNT(*)');
     $f = $q->getFilter();
     $q->addField('IF (isCancelled = 1, -2, IF (isPaid = 0, -1, IF (status IS NULL, 0, status)))', null, 'entry');
     $f->setGrouping(new ARExpressionHandle('entry'));
     $this->getReportData($q);
     foreach ($this->values['x'] as $value) {
         $value->label = $this->application->translate(CustomerOrder::getStatusName($value->originalName));
     }
 }
Пример #12
0
 protected function initOrder()
 {
     // set up currency
     $this->setUpCurrency();
     $this->usd->decimalCount->set(2);
     $this->usd->clearRoundingRules();
     $this->usd->save();
     // initialize order
     ActiveRecordModel::executeUpdate('DELETE FROM User WHERE email="*****@*****.**"');
     $user = User::getNewInstance('*****@*****.**');
     $user->save();
     $this->user = $user;
     $address = UserAddress::getNewInstance();
     $address->countryID->set('US');
     $state = State::getInstanceById(1, State::LOAD_DATA);
     $address->state->set(State::getInstanceById(1));
     $address->postalCode->set(90210);
     $address->save();
     $billing = BillingAddress::getNewInstance($user, $address);
     $billing->save();
     $address = clone $address;
     $address->save();
     $shipping = ShippingAddress::getNewInstance($user, $address);
     $shipping->save();
     $this->order = CustomerOrder::getNewInstance($user);
     $this->order->shippingAddress->set($shipping->userAddress->get());
     $this->order->billingAddress->set($billing->userAddress->get());
     // set up products
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test1');
     $product->save();
     $product->setPrice('USD', 100);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test2');
     $product->save();
     $product->setPrice('USD', 200);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test3');
     $product->save();
     $product->setPrice('USD', 400);
     $product->isSeparateShipment->set(true);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
 }
Пример #13
0
 protected function processRecord(CustomerOrder $order)
 {
     $order->processMass_history = new OrderHistory($order, SessionUser::getUser());
     switch ($this->getAction()) {
         case 'setNew':
             $status = CustomerOrder::STATUS_NEW;
             break;
         case 'setProcessing':
             $status = CustomerOrder::STATUS_PROCESSING;
             break;
         case 'setAwaitingShipment':
             $status = CustomerOrder::STATUS_AWAITING;
             break;
         case 'setShipped':
             $status = CustomerOrder::STATUS_SHIPPED;
             break;
         case 'setReturned':
             $status = CustomerOrder::STATUS_RETURNED;
             break;
         case 'setUnfinalized':
             $order->isFinalized->set(0);
             break;
         case 'setCancel':
             $order->cancel();
             break;
         case 'setFinalized':
             if (!$order->isFinalized->get() && $order->user->get()) {
                 $order->finalize();
             }
             break;
     }
     if (isset($status) && $status != $order->status->get()) {
         $order->setStatus($status);
         $this->params['controller']->sendStatusNotifyEmail($order);
     }
 }
Пример #14
0
 function send()
 {
     $parser = $this->getParser();
     $request = $this->application->getRequest();
     $apiFieldNames = $parser->getApiFieldNames();
     $orderID = $request->get('orderID');
     $comment = $request->get('text');
     if (!isset($orderID)) {
         throw new Exception("Order ID is required");
     }
     if (!isset($comment)) {
         throw new Exception("User comment is required");
     }
     $order = CustomerOrder::getInstanceById($orderID, CustomerOrder::LOAD_DATA);
     $order->user->get()->load();
     $note = OrderNote::getNewInstance($order, $order->user->get());
     $note->isAdmin->set(false);
     $note->text->set($comment);
     $note->save();
     $note->load(true);
     /*if ($this->application->config->get('NOTIFY_NEW_NOTE'))
             {
                 $order->user->get()->load();
     
                 $email = new Email($this->application);
                 $email->setTo($this->application->config->get('NOTIFICATION_EMAIL'), $this->application->config->get('STORE_NAME'));
                 $email->setTemplate('notify.message');
                 $email->set('order', $order->toArray(array('payments' => true)));
                 $email->set('message', $note->toArray());
                 $email->set('user', $order->user->toArray());
                 $email->send();
             }*/
     $f = new ARSelectFilter();
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'ID'), $note->getID()));
     $orderNotes = ActiveRecordModel::getRecordSetArray('OrderNote', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     while ($notes = array_shift($orderNotes)) {
         $xmlPage = $response->addChild('note');
         foreach ($notes as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlPage->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Пример #15
0
 private function createOrder()
 {
     $user = User::getNewInstance('*****@*****.**');
     $user->save();
     $currency = Currency::getInstanceByID('USD');
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->stockCount->set(100);
     $product->setPrice($currency, 100);
     $product->setValueByLang('name', null, 'Test name');
     $product->setValueByLang('shortDescription', null, 'Really short description');
     $product->save();
     $order = CustomerOrder::getNewInstance($user);
     $order->addProduct($product, 1);
     $order->save();
     return $order;
 }
Пример #16
0
 public function changeRecurringProductPeriod()
 {
     $request = $this->getRequest();
     $orderedItemID = $request->get('id');
     $billingPlandropdownName = $request->get('recurringBillingPlan');
     $recurringID = $request->get($billingPlandropdownName);
     $orderedItem = ActiveRecordModel::getInstanceByID('OrderedItem', $orderedItemID, true);
     $recurringItem = RecurringItem::getInstanceByOrderedItem($orderedItem);
     if ($recurringItem) {
         $recurringItem->setRecurringProductPeriod(RecurringProductPeriod::getInstanceByID($recurringID));
         $recurringItem->save();
         $orderedItem->updateBasePriceToCalculatedPrice();
     }
     $this->order->loadItemData();
     $this->order->mergeItems();
     $this->order->save();
     return new ActionRedirectResponse('order', 'index', array('query' => 'return=' . $this->request->get('return')));
 }
Пример #17
0
 protected function getLastOrders()
 {
     $f = select();
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), false));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'dateCompleted'), 'desc');
     $f->setLimit(10);
     $customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
     $ordersArray = array();
     if ($customerOrders->size() > 0) {
         $i = 0;
         foreach ($customerOrders as $order) {
             $ordersArray[$i] = $order->toArray();
             $ordersArray[$i]['status_name'] = CustomerOrder::getStatusName($ordersArray[$i]['status'] ? $ordersArray[$i]['status'] : CustomerOrder::STATUS_NEW);
             $i++;
         }
         return $ordersArray;
     }
     return array();
 }
Пример #18
0
 public function add()
 {
     if ($this->buildOrderNoteValidator()->isValid()) {
         $order = CustomerOrder::getInstanceById($this->request->get('id'), CustomerOrder::LOAD_DATA);
         $note = OrderNote::getNewInstance($order, $this->user);
         $note->isAdmin->set(true);
         $note->text->set($this->request->get('comment'));
         $note->save();
         if ($this->config->get('EMAIL_ORDERNOTE')) {
             $order->user->get()->load();
             $email = new Email($this->application);
             $email->setUser($order->user->get());
             $email->setTemplate('order.message');
             $email->set('order', $order->toArray(array('payments' => true)));
             $email->set('message', $note->toArray());
             $email->send();
         }
         return new ActionRedirectResponse('backend.orderNote', 'view', array('id' => $note->getID()));
     } else {
         return new RawResponse('invalid');
     }
 }
Пример #19
0
 private function serializeToArray(CustomerOrder $order)
 {
     $array = array();
     $array['ID'] = $order->getID();
     $array['totalAmount'] = $order->totalAmount->get();
     $array['isCancelled'] = (int) $order->isCancelled->get();
     $array['status'] = (int) $order->status->get();
     $array['shipments'] = array();
     foreach ($order->getShipments() as $shipment) {
         $shippingServiceArray = null;
         if ($shipment->shippingService->get() && (int) $shipment->shippingService->get()->getID()) {
             $shippingServiceArray = $shipment->shippingService->get()->toArray();
         } else {
             $shippingService = unserialize($shipment->shippingServiceData->get());
             $shippingServiceArray = null;
             if (is_object($shippingService)) {
                 $shippingService->setApplication($order->getApplication());
                 $shippingServiceArray = $shippingService->toArray();
             }
         }
         $array['shipments'][$shipment->getID()] = array('ID' => $shipment->getID(), 'status' => (int) $shipment->status->get(), 'ShippingService' => $shippingServiceArray);
     }
     $array['items'] = array();
     foreach ($order->getOrderedItems() as $item) {
         $array['items'][$item->getID()] = array('ID' => $item->getID(), 'shipmentID' => $item->shipment->get() ? $item->shipment->get()->getID() : null, 'count' => (int) $item->count->get(), 'price' => $item->price->get(), 'Product' => array('ID' => (int) $item->getProduct()->getID(), 'sku' => $item->getProduct()->sku->get(), 'name' => $item->getProduct()->getName($order->getApplication()->getDefaultLanguageCode()), 'isDownloadable' => (int) $item->getProduct()->isDownloadable()), 'Shipment' => $item->shipment->get() && isset($array['shipments'][$item->shipment->get()->getID()]) ? $array['shipments'][$item->shipment->get()->getID()] : array('ID' => 0));
     }
     // @todo: dirty fix
     if ($order->shippingAddress->get()) {
         if ($order->shippingAddress->get()->state->get()) {
             $order->shippingAddress->get()->state->get()->load();
         }
         $array['ShippingAddress'] = $order->shippingAddress->get()->toArray();
     } else {
         $array['ShippingAddress'] = array();
     }
     if ($order->billingAddress->get()) {
         if ($order->billingAddress->get()->state->get()) {
             $order->billingAddress->get()->state->get()->load();
         }
         $array['BillingAddress'] = $order->billingAddress->get()->toArray();
     } else {
         $array['BillingAddress'] = array();
     }
     return $array;
 }
Пример #20
0
 public function index()
 {
     $response = new ActionResponse();
     $customerOrder = CustomerOrder::getInstanceById($this->request->get('id'), true, array('User', 'Currency'));
     $logs = array();
     foreach (OrderLog::getRecordSetByOrder($customerOrder, null, array('User'))->toArray() as $entry) {
         if (!$entry['oldValue']) {
             $entry['oldValue'] = array();
         }
         if (!$entry['newValue']) {
             $entry['newValue'] = array();
         }
         if ($entry['action'] != OrderLog::ACTION_REMOVED_WITH_SHIPMENT) {
             $logs[] = $entry;
             $logs[count($logs) - 1]['items'] = array();
         } else {
             $logs[count($logs) - 1]['items'][] = $entry;
         }
     }
     $response->set('defaultCurrencyCode', $this->application->getDefaultCurrencyCode());
     $response->set('logs', $logs);
     return $response;
 }
Пример #21
0
 public function add_coupon()
 {
     $request = $this->application->getRequest();
     $code = $request->get('couponCode');
     $orderID = $request->get('orderID');
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if (strlen($code)) {
         $order = CustomerOrder::getInstanceByID($orderID, CustomerOrder::LOAD_DATA);
         $condition = DiscountCondition::getInstanceByCoupon($code);
         if ($condition) {
             if (!$order->hasCoupon($code)) {
                 $coupon = OrderCoupon::getNewInstance($order, $code);
                 $coupon->save();
                 $order->getCoupons(true);
                 if ($order->hasCoupon($code)) {
                     $order->loadAll();
                     $order->getTotal(true);
                     $order->totalAmount->set($order->getTotal(true));
                     $order->getTaxAmount();
                     $order->save();
                     $response->addChild('message', 'Coupon ' . $code . ' was successfully added');
                 } else {
                     throw new Exception("Cant add coupon " . $code);
                 }
             } else {
                 throw new Exception("The coupon " . $code . " already added");
             }
         } else {
             throw new Exception("Cant add coupon " . $code);
         }
         $order->getCoupons(true);
     } else {
         throw new Exception("Incorrect coupon code" . $code);
     }
     return new SimpleXMLResponse($response);
 }
Пример #22
0
 public function update()
 {
     $userID = $this->getApplication()->getRequest()->get('userID');
     $orderID = $this->getApplication()->getRequest()->get('ID');
     if (intval($userID) == 0 || intval($orderID) == 0) {
         throw new Exception("User and Order ID not set");
     }
     $user = User::getInstanceByID($userID);
     $order = CustomerOrder::getInstanceById($orderID);
     $user->load();
     $user->loadAddresses();
     $order->loadAll();
     return $this->apiActionGetOrdersBySelectFilter(select(eq(f('CustomerOrder.ID'), $this->getApplication()->getRequest()->get('ID'))));
 }
Пример #23
0
 /**
  * @role update
  */
 public function update()
 {
     $order = CustomerOrder::getInstanceByID((int) $this->request->get('ID'));
     return $this->save($order);
 }
Пример #24
0
 public static function save(CustomerOrder $order)
 {
     // mark shipment data as modified - to force saving
     $order->getShipments();
     $order->save();
     self::setOrder($order);
 }
Пример #25
0
 public function __construct(CustomerOrder $order, Currency $currency)
 {
     parent::__construct();
     $this->order = $order;
     $order->loadAll();
     // billing address
     if ($address = $order->billingAddress->get()) {
         $fields = array('firstName', 'lastName', 'companyName', 'phone', 'city', 'postalCode', 'countryID' => 'country');
         foreach ($fields as $key => $field) {
             $addressField = is_numeric($key) ? $field : $key;
             $this->{$field}->set($address->{$addressField}->get());
         }
         $this->state->set($this->getStateValue($address));
         $this->address->set($address->address1->get() . ' ' . $address->address2->get());
     }
     // shipping address
     $address = $order->shippingAddress->get();
     if (!$address) {
         $address = $order->billingAddress->get();
     }
     if ($address) {
         foreach ($fields as $key => $field) {
             $addressField = is_numeric($key) ? $field : $key;
             $field = 'shipping' . ucfirst($field);
             $this->{$field}->set($address->{$addressField}->get());
         }
         $this->shippingState->set($this->getStateValue($address));
         $this->shippingAddress->set($address->address1->get() . ' ' . $address->address2->get());
     }
     // amount
     $order->currency->set($currency);
     $this->amount->set(round($order->getDueAmount(), 2));
     $this->currency->set($currency->getID());
     // transaction identification
     $this->invoiceID->set($order->getID());
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $this->ipAddress->set($_SERVER['REMOTE_ADDR']);
     }
     // customer identification
     if ($order->user->get()) {
         $order->user->get()->load();
         $this->shippingEmail->set($order->user->get()->email->get());
         $this->email->set($order->user->get()->email->get());
         $this->clientID->set($order->user->get()->getID());
     }
     // order details
     // load variation data
     $variations = new ProductSet();
     foreach ($order->getShoppingCartItems() as $item) {
         if ($item->product->get() && $item->product->get()->parent->get()) {
             $variations->unshift($item->product->get());
         }
     }
     if ($variations->size()) {
         $variations->loadVariations();
     }
     foreach ($order->getShoppingCartItems() as $item) {
         $product = $item->getProduct();
         $variations = array();
         foreach ($product->getRegisteredVariations() as $variation) {
             $variations[] = $variation->getValueByLang('name');
         }
         $ri = RecurringItem::getInstanceByOrderedItem($item);
         if ($ri && $ri->isExistingRecord()) {
             $ri->load();
         } else {
             $ri = null;
         }
         $this->addLineItem($product->getName() . ($variations ? ' (' . implode(' / ', $variations) . ')' : ''), $item->getPrice(false), $item->count->get(), $product->sku->get(), $ri);
     }
     if ($discount = $order->getFixedDiscountAmount()) {
         $this->addLineItem(CustomerOrder::getApplication()->translate('_discount'), $discount * -1, 1, 'discount');
     }
     foreach ($order->getShipments() as $shipment) {
         if ($rate = $shipment->getSelectedRate()) {
             $rate = $rate->toArray();
             $name = empty($rate['ShippingService']['name_lang']) ? $rate['serviceName'] : $rate['ShippingService']['name_lang'];
             $this->addLineItem($name, $shipment->getShippingTotalBeforeTax(), 1, 'shipping');
         }
     }
     if ($taxes = $order->getTaxBreakdown()) {
         foreach ($taxes as $id => $amount) {
             $tax = Tax::getInstanceById($id, true);
             $this->addLineItem($tax->getValueByLang('name', null), $amount, 1, 'tax');
         }
     }
 }
Пример #26
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>');
 }
Пример #27
0
 public function saveCustomerOrder(CustomerOrder $order)
 {
     $order->shippingAddress->get()->save();
     $order->billingAddress->get()->save();
     $order->save();
     $shipment = $order->getShipments()->get(0);
     $shipment->shippingAmount->set($order->rawData['shipping_cost']);
     $shipment->save();
     if ($order->rawData['tax'] > 0) {
         $tax = ActiveRecordModel::getNewInstance('ShipmentTax');
         $tax->shipment->set($shipment);
         $tax->amount->set($order->rawData['tax']);
         $tax->save();
         $shipment->addFixedTax($tax);
         $shipment->status->set(Shipment::STATUS_SHIPPED);
         $shipment->save();
     }
     return parent::saveCustomerOrder($order);
 }
Пример #28
0
 public function getInstance(CustomerOrder $order, $gatewayTransactionID)
 {
     return $order->getRelatedRecordSet(__CLASS__, select(eq(__CLASS__ . '.gatewayTransactionID', $gatewayTransactionID)))->get(0);
 }
Пример #29
0
 /**
  * @return RequestValidator
  */
 private function buildCartValidator(CustomerOrder $order, $options)
 {
     unset($_SESSION['optionError']);
     $validator = $this->getValidator("cartValidator", $this->request);
     foreach ($order->getOrderedItems() as $item) {
         $this->buildItemValidation($validator, $item, $options, $item->getID());
     }
     if ($this->config->get('CHECKOUT_CUSTOM_FIELDS') == 'CART_PAGE') {
         $order->getSpecification()->setValidation($validator, true);
     }
     if ($this->isTosInCartPage()) {
         $validator->addCheck('tos', new IsNotEmptyCheck($this->translate('_err_agree_to_tos')));
     }
     return $validator;
 }
Пример #30
0
 public function stopRebills($order = null)
 {
     if ($order === null) {
         $request = $this->getRequest();
         $id = $request->get('id');
         $order = CustomerOrder::getInstanceById($id);
     }
     if ($this->canCancelRecurring($order)) {
         $order->cancelFurtherRebills();
         // localy in store database.
         return new JSONResponse(array('recurringStatus' => $this->translate('_recurring_status_expired'), 'rebillCount' => 0), 'success');
     }
     return new JSONResponse(null, 'failure', $this->translate('_cannot_cancel_subscription'));
 }