Beispiel #1
0
 /**
  * Get's the shipping provider module id from a name
  *
  * @param string $name The name to get the shipping module id for
  *
  * @return string
  **/
 public function GetShippingProviderModuleByName($name)
 {
     // $cost['description']. ' ('.$zoneInfo['zonename'].')'
     $shipping_zones = GetShippingZoneInfo();
     foreach ($shipping_zones as $shipping_zone) {
         if (!isset($shipping_zone['methods']) || !is_array($shipping_zone['methods'])) {
             continue;
         }
         foreach ($shipping_zone['methods'] as $shipping_method) {
             if ($shipping_method['methodname'] == $name) {
                 // Check for static method names
                 return $shipping_method['methodmodule'];
             }
             if ($shipping_method['methodname'] . ' (' . $shipping_zone['zonename'] . ')' == $name) {
                 // Check for static method names
                 return $shipping_method['methodmodule'];
             }
             foreach (array_keys($shipping_method['vars']) as $shipping_var) {
                 $test_name = $shipping_method['methodname'] . ' ' . $shipping_var;
                 if ($test_name == $name) {
                     // Check for real time shipping names
                     return $shipping_method['methodmodule'];
                 }
             }
         }
     }
     return $name;
 }
 /**
  * Add the shipping information to the google object representation of the customers cart.
  *
  * @return void
  **/
 private function AddShippingInformationToCart()
 {
     $shippingZones = GetShippingZoneInfo();
     $defaultZone = null;
     $coveredLocations = array();
     $defaultShippingMethods = array();
     // Do all the normal zones first (skip the default one)
     // this is so that we can work out where "everywhere else" equates to
     foreach ($shippingZones as $shippingZone) {
         // If the zone has no enabled methods
         if (!isset($shippingZone['methods'])) {
             continue;
         }
         // Skip the default zone for now
         if (!isset($shippingZone['locationtype'])) {
             continue;
         }
         foreach ($shippingZone['methods'] as $method) {
             $module = null;
             if (!GetModuleById('shipping', $module, $method['methodmodule'])) {
                 continue;
             }
             if ($module === null) {
                 continue;
             }
             $module->SetMethodId($method['methodid']);
             $deliveryMethods = $module->GetAvailableDeliveryMethods();
             foreach ($deliveryMethods as $deliveryMethod) {
                 $shipping_name = $deliveryMethod . ' (' . $shippingZone['zonename'] . ')';
                 // If it's a flat rate
                 if ($module->_flatrate) {
                     $defaultCost = $module->GetValue('defaultcost');
                     if ($defaultCost === null) {
                         $defaultCost = $this->GetValue('fallbackshippingcost');
                     }
                     $ship = new GoogleMerchantCalculatedShipping($shipping_name, $defaultCost);
                 } else {
                     $ship = new GoogleMerchantCalculatedShipping($shipping_name, $this->GetValue('fallbackshippingcost'));
                 }
                 $ShippingRestrictions = $this->GetShippingRestrictions($shippingZone);
                 $this->AddDefaultShippingRestrictions($shippingZone);
                 if ($ShippingRestrictions !== false) {
                     // Address filters are used when a customer goes to the google checkout page
                     $ship->AddAddressFilters($ShippingRestrictions);
                     // Shipping restrictions are used if the merchant callback calculation fails
                     $ship->AddShippingRestrictions($ShippingRestrictions);
                 }
                 $this->cart->AddShipping($ship);
             }
         }
     }
     // Now add the methods for the default zone
     foreach ($shippingZones as $shippingZone) {
         // If the zone has no enabled methods
         if (!isset($shippingZone['methods'])) {
             continue;
         }
         // Skip any non-default zones now
         if (isset($shippingZone['locationtype'])) {
             continue;
         }
         foreach ($shippingZone['methods'] as $method) {
             $module = null;
             if (!GetModuleById('shipping', $module, $method['methodmodule'])) {
                 continue;
             }
             if ($module === null) {
                 continue;
             }
             $module->SetMethodId($method['methodid']);
             $deliveryMethods = $module->GetAvailableDeliveryMethods();
             foreach ($deliveryMethods as $deliveryMethod) {
                 $shipping_name = $deliveryMethod;
                 // If it's a flat rate
                 if ($module->_flatrate) {
                     $defaultCost = $module->GetValue('defaultcost');
                     if ($defaultCost === null) {
                         $defaultCost = $this->GetValue('fallbackshippingcost');
                     }
                     $ship = new GoogleMerchantCalculatedShipping($shipping_name, $defaultCost);
                 } else {
                     $ship = new GoogleMerchantCalculatedShipping($shipping_name, $this->GetValue('fallbackshippingcost'));
                 }
                 if ($this->defaultZoneGFilter) {
                     // Address filters are used when a customer goes to the google checkout page
                     $ship->AddAddressFilters($this->defaultZoneGFilter);
                     // Shipping restrictions are used if the merchant callback calculation fails
                     $ship->AddShippingRestrictions($this->defaultZoneGFilter);
                 }
                 $this->cart->AddShipping($ship);
             }
         }
     }
 }
		/**
		 * Add the shipping information to the google object representation of the customers cart.
		 *
		 * @return void
		 **/
		private function AddShippingInformationToCart()
		{
			$quote = getCustomerQuote();
			$noShippingCost = 0;
			$fixedShippingCost = 0;
			$fixedShippingProducts = 0;

			$items = $quote->getItems();
			foreach($items as $item) {
				if($item->getType() != PT_PHYSICAL) {
					continue;
				}

				if($item->hasFreeShipping()) {
					++$noShippingCost;
				}
				else if($item->getFixedShippingCost() > 0) {
					++$fixedShippingProducts;
					$fixedShippingCost += $item->getFixedShippingCost() * $item->getQuantity();
				}
			}

			// Global free shipping options
			$addFreeShipping = false;
			if ($quote->getHasFreeShipping() || $noShippingCost)
			{
				$freeShippingName = GetLang('FreeShipping');
				$addFreeShipping = true;
			}

			// Global fixed shipping on items option
			$addFixedShipping = false;
			if (count($items) == $fixedShippingProducts) {
				$fixedShippingName = GetConfig('StoreName');
				$addFixedShipping = true;
			}

			// Not all the products have a fixed shipping so keep on chugging away
			$shippingZones = GetShippingZoneInfo();

			// Do all the normal zones first (skip the default one)
			// this is so that we can work out where "everywhere else" equates to
			foreach ($shippingZones as $shippingZone) {
				// Skip the default zone for now
				if (!isset($shippingZone['locationtype'])) {
					continue;
				}

				$shippingRestrictions = $this->GetShippingRestrictions($shippingZone);
				$this->AddDefaultShippingRestrictions($shippingZone);

				// Add in the free shipping option if we have it
				if($addFreeShipping || !empty($shippingZone['zonefreeshipping'])) {
					$freeShippingName = GetLang('FreeShipping');
					$ship = new GoogleMerchantCalculatedShipping($freeShippingName . ' ('.$shippingZone['zonename'].')', 0);
					if ($shippingRestrictions !== false) {
						// Address filters are used when a customer goes to the google checkout page
						$ship->AddAddressFilters($shippingRestrictions);

						// Shipping restrictions are used if the merchant callback calculation fails
						$ship->AddShippingRestrictions($shippingRestrictions);
					}

					$ship->AddAddressFilters($shippingRestrictions);
					$this->cart->AddShipping($ship);
				}

				// Add in the fixed shipping option if we have it
				if($addFixedShipping) {
					$ship = new GoogleMerchantCalculatedShipping($fixedShippingName . ' ('.$shippingZone['zonename'].')', $fixedShippingCost);
					if ($shippingRestrictions !== false) {
						// Address filters are used when a customer goes to the google checkout page
						$ship->AddAddressFilters($shippingRestrictions);

						// Shipping restrictions are used if the merchant callback calculation fails
						$ship->AddShippingRestrictions($shippingRestrictions);
					}

					$ship->AddAddressFilters($shippingRestrictions);
					$this->cart->AddShipping($ship);
				}

				$this->AddShippingZoneMethodsToCart($shippingZone, $shippingRestrictions, $fixedShippingCost, true);
			}

			// Now add the methods for the default zone
			foreach ($shippingZones as $shippingZone) {
				// Skip any non-default zones now
				if (isset($shippingZone['locationtype'])) {
					continue;
				}

				// Add free shipping options
				if ($addFreeShipping || !empty($shippingZone['zonefreeshipping']))
				{
					$freeShippingName = GetLang('FreeShipping');
					$ship = new GoogleMerchantCalculatedShipping($freeShippingName, 0);
					$Gfilter = new GoogleShippingFilters();
					$Gfilter->SetAllowedWorldArea(true);
					$ship->AddAddressFilters($Gfilter);

					if ($this->defaultZoneGFilter) {
						// Address filters are used when a customer goes to the google checkout page
						$ship->AddAddressFilters($this->defaultZoneGFilter);

						// Shipping restrictions are used if the merchant callback calculation fails
						$ship->AddShippingRestrictions($this->defaultZoneGFilter);
					}

					$this->cart->AddShipping($ship);
				}

				// Add fixed shipping on items option
				if ($addFixedShipping) {
					$Gfilter = new GoogleShippingFilters();
					$ship = new GoogleMerchantCalculatedShipping($fixedShippingName, $fixedShippingCost);
					$Gfilter->SetAllowedWorldArea(true);
					$ship->AddAddressFilters($Gfilter);

					if ($this->defaultZoneGFilter) {
						// Address filters are used when a customer goes to the google checkout page
						$ship->AddAddressFilters($this->defaultZoneGFilter);

						// Shipping restrictions are used if the merchant callback calculation fails
						$ship->AddShippingRestrictions($this->defaultZoneGFilter);
					}

					$this->cart->AddShipping($ship);
				}

				$this->AddShippingZoneMethodsToCart($shippingZone, $this->defaultZoneGFilter, $fixedShippingCost, false);
			}
		}