Ejemplo n.º 1
0
 public function testGetAllDeliveryZones()
 {
     $zonesCount = DeliveryZone::getAll()->getTotalRecordCount();
     $zone0 = DeliveryZone::getNewInstance();
     $zone0->name->set(':TEST_ZONE_1');
     $zone0->isEnabled->set(0);
     $zone0->save();
     $zone1 = DeliveryZone::getNewInstance();
     $zone1->name->set(':TEST_ZONE_2');
     $zone1->isEnabled->set(1);
     $zone1->save();
     $this->assertEquals(DeliveryZone::getAll()->getTotalRecordCount(), $zonesCount + 2);
 }
Ejemplo n.º 2
0
 /**
  * Main settings page
  */
 public function index()
 {
     $zones = array(0 => array('ID' => -1, 'name' => $this->translate('_default_zone')), 1 => array('ID' => -2, 'name' => $this->translate('_delivery_zones')), 2 => array('ID' => -3, 'name' => $this->translate('_tax_zones')));
     foreach (DeliveryZone::getAll()->toArray() as $zone) {
         $zones[1]['items'][] = array('ID' => $zone['ID'], 'name' => $zone['name'], 'type' => $zone['type']);
         $zones[2]['items'][] = array('ID' => $zone['ID'], 'name' => $zone['name'], 'type' => $zone['type']);
     }
     $response = new ActionResponse();
     $response->set('zones', json_encode($zones));
     $response->set('countryGroups', json_encode($this->locale->info()->getCountryGroups()));
     $response->set('testAddress', new Form(new RequestValidator('testAddress', $this->request)));
     $response->set('countries', array_merge(array('' => ''), $this->application->getEnabledCountries()));
     return $response;
 }
Ejemplo n.º 3
0
 private function saveTaxRates(Tax $tax)
 {
     $zones = DeliveryZone::getAll();
     $zones->add(DeliveryZone::getDefaultZoneInstance());
     $classes = TaxClass::getAllClasses();
     ActiveRecord::beginTransaction();
     foreach ($zones as $zone) {
         // delete all zone tax rates
         $taxRates = $zone->getTaxRates();
         foreach ($taxRates as $rate) {
             if ($rate->taxID->get()->getID() == $tax->getID()) {
                 $rate->delete();
             }
         }
         $this->saveRate($zone, $tax);
         foreach ($classes as $class) {
             $this->saveRate($zone, $tax, $class);
         }
     }
     ActiveRecord::commit();
 }
Ejemplo n.º 4
0
 public function getHandler($returnUrl = '', $cancelUrl = '')
 {
     $application = ActiveRecordModel::getApplication();
     $GLOBALS['merchant_id'] = $this->getConfigValue('merchant_id');
     if ($this->getConfigValue('sandbox') && !defined('PHPGCHECKOUT_USE_SANDBOX')) {
         define('PHPGCHECKOUT_USE_SANDBOX', true);
     }
     include_once dirname(dirname(__FILE__)) . '/library/google/config.php';
     if ($this->order) {
         $GLOBALS['GCheckout_currency'] = $this->getValidCurrency($this->order->getCurrency()->getID());
     }
     $handler = new gCart($this->getConfigValue('merchant_id'), $this->getConfigValue('merchant_key'));
     $handler->setMerchantCheckoutFlowSupport($returnUrl, $cancelUrl, $this->application->getConfig()->get('REQUIRE_PHONE'));
     // add cart items
     if ($this->order) {
         $items = array();
         foreach ($this->order->getOrderedItems() as $item) {
             if (!$item->isSavedForLater->get()) {
                 $gItem = new gItem(htmlspecialchars($item->product->get()->getValueByLang('name')), htmlspecialchars($item->product->get()->getValueByLang('shortDescription')), $item->count->get(), $item->price->get());
                 $gItem->setPrivateItemData('<item-id>' . $item->getID() . '</item-id><order-id>' . $this->order->getID() . '</order-id>');
                 $items[] = $gItem;
             }
             // add discounts
             if ($discounts = $this->order->getFixedDiscountAmount()) {
                 $items[] = new gItem($application->translate('_discount'), '', 1, $discounts * -1);
             }
             $handler->addItems($items);
         }
         // get shipping rates for all zones - silly, eh?
         if ($this->order->isShippingRequired()) {
             $shipment = $this->order->getShipments()->get(0);
             $zoneCountries = $zoneStates = $zoneZips = array();
             foreach (DeliveryZone::getAll() as $zone) {
                 $countries = $zone->getCountries()->extractField('countryCode');
                 $states = array();
                 foreach ($zone->getStates()->extractReferencedItemSet('state') as $state) {
                     if ($state->countryID == 'US') {
                         $states[] = $state->code->get();
                     } else {
                         $countries[] = $state->countryID->get();
                     }
                 }
                 $countries = array_intersect(array_unique($countries), $this->getSupportedCountries());
                 $zipMasks = $zone->getZipMasks()->extractField('mask');
                 foreach ($zone->getShippingRates($shipment)->toArray() as $rate) {
                     $name = $rate['serviceName'] ? $rate['serviceName'] : $rate['ShippingService']['name_lang'];
                     $gRate = new gShipping($name, round($rate['costAmount'], 2), 'merchant-calculated-shipping');
                     // @todo: remove this. chokes up on non-US postal codes
                     $zipMasks = array();
                     $gRate->addAllowedAreas($countries, $states, $zipMasks);
                     $shipping[$name] = $gRate;
                 }
                 $zoneCountries = array_merge($zoneCountries, $countries);
                 $zoneStates = array_merge($zoneStates, $states);
                 $zoneZips = array_merge($zoneZips, $zipMasks);
             }
             // default zone
             $enabledCountries = array_keys($application->getConfig()->get('ENABLED_COUNTRIES'));
             $defCountries = array_intersect($enabledCountries, $zoneCountries, $this->getSupportedCountries());
             foreach (DeliveryZone::getDefaultZoneInstance()->getShippingRates($shipment)->toArray() as $rate) {
                 $gRate = new gShipping($rate['serviceName'] ? $rate['serviceName'] : $rate['ShippingService']['name_lang'], round($rate['costAmount'], 2), 'merchant-calculated-shipping');
                 $gRate->addAllowedAreas($defCountries, array(), array());
                 $shipping[] = $gRate;
             }
             $handler->_setShipping($shipping);
         }
     }
     // set merchant calculations
     $router = CustomerOrder::getApplication()->getRouter();
     $calcUrl = $router->createFullUrl($router->createUrl(array('controller' => 'googleCheckout', 'action' => 'index')), !$this->getConfigValue('sandbox'));
     $handler->setMerchantCalculations(new gMerchantCalculations($calcUrl, $this->getConfigValue('coupons')));
     $handler->setDefaultTaxTable(new gTaxTable('Tax', array(new gTaxRule(0))));
     return $handler;
 }