assets/s2dishipping.php /// Art: Shop Business Logic /// Inhalt: Klasse shipping_method, Klasse shipping /// Beschreibung: Business Logic für den Versand /// Benötigt: config.php /// CCML-Parsing: nein /// ////////////////////////////////////////////////////////////////////////////////////////// /// /// Letzte Änderungen: /// 11.07.2008 Anpassung für neuen Merkzettel /// 22.09.2009 split -> explode /// shop to date 7 /// 09.12.209 Nationale Versandarten hinzugefügt /// ////////////////////////////////////////////////////////////////////////////////////////// ///<16.12.2009/7.0.0.1/> if (!defined('SHOP_TO_DATE')) die('Forbidden'); // Klasse Versand-Methode class shipping_method { var $uid = ""; var $caption = ""; var $info = ""; var $vat = 0; var $free = 0; var $noship = ''; var $price = array(); var $weight = array(); var $actualprice = -1; var $parameter = null; var $trackingurl = null; var $total = null; function shipping_method() { } // Preis nach Gewicht anpassen und Versankostenfreiheit prüfen function calc_price($weight, $price) { $this->actualprice = -1; if ($this->weight[1] == 0) { // Nur ein Preis $this->actualprice = $this->price[1]; } else { // Preis nach Gewicht for ($i = count($this->weight); $i > 0; $i--) { if ($this->weight[$i] != 0) { if ($weight <= $this->weight[$i]) $this->actualprice = $this->price[$i]; } } } // Versandkostenfrei? if ($price >= $this->free && $this->free != 0 && $this->actualprice != -1) $this->actualprice = 0; } } // Klasse Versand class shipping { var $shippingmethods = array(); // Konstruktor Versand-Methoden definieren function shipping() { global $smethods; foreach ($smethods as $s) { $sm = new shipping_method(); $sm->uid = $s['uid']; $sm->caption = $s['caption']; $sm->info = $s['info']; $sm->vat = $s['vat']; $sm->free = $s['free']; // Umsatzsteueranpassung Spanien $sm->noship = $s['noship']; $sm->perpiece = $s['perpiece']; foreach ($s['price'] as $k => $v) { $sm->price[$k] = $s['price'][$k]; $sm->weight[$k] = $s['weight'][$k]; } $sm->parameter = $s['parameter']; $sm->trackingurl = $s['trackingurl']; $sm->countries = $s['countries']; $sm->zipallow = $s['zipallow']; $sm->zipdeny = $s['zipdeny']; array_push($this->shippingmethods, $sm); } } // Preise und nicht erlaubte Methoden kontrollieren für Auswahl Methoden function calc_prices(&$order) { $found = false; foreach (array_keys($this->shippingmethods) as $key) { $sm = &$this->shippingmethods[$key]; $sm->calc_price($order->get_weight(), $order->get_subtotal() - $order->get_rebate()); // Nicht erlaubte Methode? foreach ($order->items as $item) if ($item->quantity && !$item->memo) if (!$item->download_uid && strstr($item->noship, $sm->uid)) $sm->actualprice = -1; // Versand in das Land möglich? if ($sm->countries) { $country_found = false; $this_cc2 = substr($order->client->deviating_shipping_address ? $order->client->shipping_country : $order->client->country, 0, 2); foreach (explode(',', $sm->countries) as $cc2) if ($this_cc2 == $cc2) $country_found = true; if (!$country_found) $sm->actualprice = -1; } // Versand an diese Postleitzahl erlaubt? if ($sm->zipallow) { $country_found = false; $this_zip = $order->client->deviating_shipping_address ? $order->client->shipping_zip : $order->client->zip; foreach (explode(',', $sm->zipallow) as $zip) if (strpos($this_zip, $zip) === 0) $country_found = true; if (!$country_found) $sm->actualprice = -1; } // Versand an diese Postleitzahl verboten? if ($sm->zipdeny) { $this_zip = $order->client->deviating_shipping_address ? $order->client->shipping_zip : $order->client->zip; foreach (explode(',', $sm->zipdeny) as $zip) if (strpos($this_zip, $zip) === 0) $sm->actualprice = -1; } // Umsatzsteueranpassung Spanien if (CC_SITE_LOCALE_ES) { $zips = explode(' ', $sm->noship); $myzip = $order->client->get_zip(); if ($myzip && in_array($myzip, $zips)) $sm->actualprice = -1; } // Ggf. Auswahl löschen if ($sm->actualprice == -1 && $sm->uid == $order->client->shipping_uid) $order->client->shipping_uid = null; if ($sm->uid == $order->client->shipping_uid) $found = true; } if (!$found) $order->client->shipping_uid = null; } // Bestimmte Versandmethode auslesen function get($uid) { foreach ($this->shippingmethods as $sm) { if ($sm->uid == $uid) return $sm; } } } ?>