Jump to content

immanueljl

Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • First Name
    Immanuel
  • Last Name
    Julianto Lasmana

Recent Profile Visitors

904 profile views

immanueljl's Achievements

Newbie

Newbie (1/14)

3

Reputation

  1. Halo, kali ini saya mau share module untuk cek ongkir menggunakan API dari raja ongkir. Module ini include JNE, TIKI dan POS. Untuk detailnya cek aja di mari : https://soft-gain.com/2019/02/07/module-hitung-ongkir-jne-tiki-pos/ Dukung pengembangan module ini dengan like & share
  2. Hi, i am just a beginner and i try to create my own carrier module. So far its cool but i stack at this point. I know i can return any integer at "public function getOrderShippingCost($params, $shipping_cost)" as my shipping price. My problem is i have 3 carrier and i want a different cost each carrier. Here my full code: class belvg_freightdelivery extends CarrierModule { const PREFIX = 'belvg_fcd_'; public $id_carrier; protected $_hooks = array( 'header', 'actionCarrierUpdate', 'displayOrderConfirmation', 'displayAdminOrder', 'displayBeforeCarrier', ); protected $_carriers = array( //HERE I PUT 3 CARRIER 'Freight Company' => 'fcd', 'Freight Company2' => 'fcd2', 'Freight Company3' => 'fcd3', ); public function __construct() { $this->name = 'belvg_freightdelivery'; $this->tab = 'shipping_logistics'; $this->version = '1.6.2'; $this->author = 'BelVG'; $this->bootstrap = TRUE; $this->module_key = ''; parent::__construct(); $this->displayName = $this->l('Delivery by freight company'); $this->description = $this->l('If your customer choose “Delivery by freight company”, you get a text field for entering information to the freight company'); } public function getTemplate($area, $file) { return 'views/templates/' . $area . '/' . $file; } public function install() { if (parent::install()) { foreach ($this->_hooks as $hook) { if (!$this->registerHook($hook)) { return FALSE; } } if (!$this->installDB()) { return FALSE; } if (!$this->createCarriers()) { return FALSE; } return TRUE; } return FALSE; } protected function uninstallDB() { $sql = array(); $sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'belvg_freightdelivery`'; foreach ($sql as $_sql) { if (!Db::getInstance()->Execute($_sql)) { return FALSE; } } return TRUE; } protected function installDB() { $sql = array(); $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'belvg_freightdelivery` ( `id_belvg_freightdelivery` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT, `id_order` INT( 11 ) UNSIGNED, `details` TEXT, `date_upd` DATETIME NOT NULL, PRIMARY KEY (`id_belvg_freightdelivery`) ) ENGINE = ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'; foreach ($sql as $_sql) { if (!Db::getInstance()->Execute($_sql)) { return FALSE; } } return TRUE; } protected function createCarriers() { foreach ($this->_carriers as $key => $value) { //Create own carrier $carrier = new Carrier(); $carrier->name = $key; $carrier->active = TRUE; $carrier->deleted = 0; $carrier->shipping_handling = FALSE; $carrier->range_behavior = 0; $carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = 'Depends on the freight company [1-2 days]'; $carrier->shipping_external = TRUE; $carrier->is_module = TRUE; $carrier->external_module_name = $this->name; $carrier->need_range = TRUE; if ($carrier->add()) { $groups = Group::getGroups(true); foreach ($groups as $group) { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array( 'id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group'] ), 'INSERT'); } $rangePrice = new RangePrice(); $rangePrice->id_carrier = $carrier->id; $rangePrice->delimiter1 = '0'; $rangePrice->delimiter2 = '1000000'; $rangePrice->add(); $rangeWeight = new RangeWeight(); $rangeWeight->id_carrier = $carrier->id; $rangeWeight->delimiter1 = '0'; $rangeWeight->delimiter2 = '1000000'; $rangeWeight->add(); $zones = Zone::getZones(true); foreach ($zones as $z) { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT'); Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $z['id_zone'], 'price' => '25'), 'INSERT'); Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '25'), 'INSERT'); } copy(dirname(__FILE__) . '/views/img/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'); Configuration::updateValue(self::PREFIX . $value, $carrier->id); Configuration::updateValue(self::PREFIX . $value . '_reference', $carrier->id); } } return TRUE; } protected function deleteCarriers() { foreach ($this->_carriers as $value) { $tmp_carrier_id = Configuration::get(self::PREFIX . $value); $carrier = new Carrier($tmp_carrier_id); $carrier->delete(); } return TRUE; } public function uninstall() { if (parent::uninstall()) { foreach ($this->_hooks as $hook) { if (!$this->unregisterHook($hook)) { return FALSE; } } /*if (!$this->uninstallDB()) { return FALSE; }*/ if (!$this->deleteCarriers()) { return FALSE; } return TRUE; } return FALSE; } public function getOrderShippingCost($params, $shipping_cost) { //reason of using $shipping_cost => CarrierModuleCore::getOrderShippingCost() //$params - you can use this parameter for customizing delivery price calculation $carrierObj = new Carrier(Configuration::get(self::PREFIX . 'fcd')); $delivery_price = Carrier::getDeliveryPriceByRanges($carrierObj->getRangeTable(), Configuration::get(self::PREFIX . 'fcd')); $max_delivery_price = 0; foreach ($delivery_price as $d_price) { if ($d_price['price'] > $max_delivery_price) { $max_delivery_price = $d_price['price']; } } return $max_delivery_price; //THIS PART RETURN A COST FOR ALL CARRIER, I WANT TO RETURN A DIFFERENT SHIPPING COST PER CARRIER (Example: fcd1 => 100, fcd2 => 200, fcd3 => 300) } public function getOrderShippingCostExternal($params) { return $this->getOrderShippingCost($params, 0); } public function hookActionCarrierUpdate($params) { if ($params['carrier']->id_reference == Configuration::get(self::PREFIX . 'fcd_reference')) { Configuration::updateValue(self::PREFIX . 'fcd', $params['carrier']->id); } } It will be good if someone can help me. Thanks! NOTE: i use prestashop 1.6
×
×
  • Create New...