public function addChoice(GiveItSdkChoice $choice) { if (!$choice->valid()) { return false; } $this->choices[$choice->id] = $choice; return $this; }
private function setDelivery() { $product_price = $this->give_it_product->data['details']['price']; // add a delivery option $delivery = new GiveItSdkOption(array('id' => 'my_id', 'type' => 'layered_delivery', 'name' => 'Shipping', 'tax_delivery' => true)); // loop through all countries for which shipping is defined and create a choice on this option $this->getShippingRules(); $zones = Zone::getZones(false); foreach (self::$shipping_rules as $rule) { if (is_numeric($rule['iso_code'])) { // it's a zone not a country foreach ($zones as $zone) { if ($zone['id_zone'] == $rule['iso_code']) { $country_name = $zone['name']; } } } else { $country_id = Country::getByIso($rule['iso_code']); $country_name = Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $country_id); } $choice = new GiveItSdkChoice(array('id' => $rule['iso_code'], 'name' => $country_name, 'choices_title' => $country_name)); // look for options for this country foreach (self::$shipping_rules as $option) { if ($option['iso_code'] == $rule['iso_code']) { // if option has free_above and price > then display 0 price $option_price = $option['price']; if ($option['free_above'] > 0 && $product_price > $option['free_above']) { $option_price = 0; } $choice->addChoice(new GiveItSdkChoice(array('id' => $option['id'], 'name' => $option['name'], 'price' => $option_price, 'tax_percent' => (int) $option['tax_percent']))); } } $delivery->addChoice($choice); } return $delivery; }