web-dev-qa-db-fra.com

Le champ de configuration du plugin ne montre pas Joomla 3.3

Je crée un plugin d'expédition personnalisé pour Virtuemart-3. il s'est installé avec succès. mais ses champs de configuration ne sont pas visibles.

Voici mon fichier fedex.xml

    <?xml version="1.0" encoding="UTF-8" ?>
<extension version="2.5" type="plugin" group="vmshipment" method="upgrade">
    <name>Fedex</name>
    <creationDate>March 11 2015</creationDate>
    <author>example</author>
    <authorUrl>http://www.example.net</authorUrl>
    <copyright>.</copyright>
    <license>Commercial</license>
    <version>1</version>
    <description>FedEx Shipping</description>

    <files>
        <filename plugin="fedex">fedex.php</filename>
        <folder>live</folder>
        <folder>nusoap</folder>
        <folder>wsdl</folder>
    </files>
    <vmconfig>
        <fields addpath="/administrator/components/com_virtuemart/elements">
            <field type="vmjpluginwarning" />
            <field type="spacer" default="VMSHIPMENT_WEIGHT_COUNTRIES_PLUGIN" level="level1" />
            <field name="fedex_account_number" type="text"   label="FedEx account number" />
            <field name="fedex_access_id" type="text"   label="FedEx access ID"  />
            <field name="fedex_password" type="text"   label="FedEx password"  />
            <field name="fedex_meter_number" type="text"   label="FedEx meter number"  />
            <field name="countries" type="vmcountries"  scope="com_virtuemart" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_COUNTRIES" description="VMSHIPMENT_WEIGHT_COUNTRIES_COUNTRIES_DESC"/>
            <field name="fedex_Origin_Zip" type="text"   label="Origin  Zip code"  />

            <!--<param name="Zip_start" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_Zip_START" description="VMSHIPMENT_WEIGHT_COUNTRIES_Zip_START_DESC"/>
            <param name="Zip_stop" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_Zip_STOP" description="VMSHIPMENT_WEIGHT_COUNTRIES_Zip_STOP_DESC"/>
            -->
            <field name="weight_start" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_START" description="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_START_DESC"/>
            <field name="weight_stop" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_STOP" description="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_STOP_DESC"/>
            <field name="weight_unit" type="vmweightunit" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT" description="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT_DESC"/>
            <!--<param name="nbproducts_start" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_NBPRODUCTS_START" description="VMSHIPMENT_WEIGHT_COUNTRIES_NBPRODUCTS_START_DESC"/>
            <param name="nbproducts_stop" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_NBPRODUCTS_STOP" description="VMSHIPMENT_WEIGHT_COUNTRIES_NBPRODUCTS_STOP_DESC"/>
            -->

            <field name="orderamount_start" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_ORDERAMOUNT_START" description="VMSHIPMENT_WEIGHT_COUNTRIES_ORDERAMOUNT_START_DESC"/>
            <field name="orderamount_stop" type="text" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_ORDERAMOUNT_STOP" description="VMSHIPMENT_WEIGHT_COUNTRIES_ORDERAMOUNT_STOP_DESC"/>


            <field type="text" default="0" name="shipment_cushion_PRIORITY_OVERNIGHT" label="Shipment Cousion for FedEx Priority Overnight (%)" />
            <field type="text" default="0" name="shipment_cushion_STANDARD_OVERNIGHT" label="Shipment Cousion for FedEx Standard Overnight (%)" />
            <field type="text" default="0" name="shipment_cushion_FEDEX_2_DAY_AM" label="Shipment Cousion for FedEx 2 Day Air AM (%)" />
            <field type="text" default="0" name="shipment_cushion_FEDEX_2_DAY" label="Shipment Cousion for FedEx 2 Day Air (%)" />
            <field type="text" default="0" name="shipment_cushion_FEDEX_EXPRESS_SAVER" label="Shipment Cousion for FedEx Express Saver (%)" />
            <field type="text" default="0" name="shipment_cushion_FEDEX_GROUND" label="Shipment Cousion for FedEx Ground (%)" />
            <field type="text" default="0" name="shipment_cushion_PRIORITY_GROUND_HOME_DELIVERY" label="Shipment Cousion for FedEx Ground Home Delivery (%)" />

            <!--
            <param name="cost" type="text"   label="VMSHIPMENT_WEIGHT_COUNTRIES_COST" description="VMSHIPMENT_WEIGHT_COUNTRIES_COST_DESC" />
            <param name="package_fee" type="text"   label="VMSHIPMENT_WEIGHT_COUNTRIES_PACKAGE_FEE" description="VMSHIPMENT_WEIGHT_COUNTRIES_PACKAGE_FEE_DESC" />
            <param name="tax_id" type="vmtaxes" scope="com_virtuemart"  label="VMSHIPMENT_WEIGHT_COUNTRIES_TAX" description="VMSHIPMENT_WEIGHT_COUNTRIES_TAX_DESC" />
            <param name="free_shipment" type="text"    label="VMSHIPMENT_WEIGHT_COUNTRIES_FREE_SHIPPING_AMOUNT" description="VMSHIPMENT_WEIGHT_COUNTRIES_FREE_SHIPPING_AMOUNT_DESC" />-->

        </fields>
    </vmconfig>

    <updateservers>
        <!-- Note: No spaces or linebreaks allowed between the server tags -->
        <server type="extension" name="VirtueMart3 plg_vmshipment_fedex Update Site"><![CDATA[http://virtuemart.net/releases/vm3/plg_vmshipment_weight_countries_update.xml]]></server>
    </updateservers>
</extension>

et mon fedex.php est

if (!class_exists('vmPSPlugin')) {
    require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
}
require_once('ratelib.php');

class plgVmShipmentFedex extends vmPSPlugin {

    // instance of class
    public static $_this = FALSE;
    public static $_fcc = 1;
    public $methods_rates = array();

    function __construct(& $subject, $config) {

        parent::__construct($subject, $config);

        $this->_loggable = TRUE;
        $this->_tablepkey = 'id';
        $this->_tableId = 'id';
        $this->tableFields = array_keys($this->getTableSQLFields());
        $varsToPush = $this->getVarsToPush();

         $this->setConfigParameterable($this->_configTableFieldName, $varsToPush);
        //vmdebug('Muh constructed plgVmShipmentWeight_countries',$varsToPush);
    }

    public function getVmPluginCreateTableSQL() {

        return $this->createTableSQL('Shipment Fedex Table');
    }

    function getTableSQLFields() {

        $SQLfields = array(
            'id' => 'int(1) UNSIGNED NOT NULL AUTO_INCREMENT',
            'virtuemart_order_id' => 'int(11) UNSIGNED',
            'order_number' => 'char(32)',
            'virtuemart_shipmentmethod_id' => 'mediumint(1) UNSIGNED',
            'shipment_name' => 'varchar(5000)',
            'order_weight' => 'decimal(10,4)',
            'shipment_weight_unit' => 'char(3) DEFAULT \'KG\'',
            'shipment_cost' => 'decimal(10,2)',
            'shipment_package_fee' => 'decimal(10,2)',
            'tax_id' => 'smallint(1)'
        );
        return $SQLfields;
    }

    public function plgVmOnShowOrderFEShipment($virtuemart_order_id, $virtuemart_shipmentmethod_id, &$shipment_name) {

        $this->onShowOrderFE($virtuemart_order_id, $virtuemart_shipmentmethod_id, $shipment_name);
    }

    function plgVmConfirmedOrder(VirtueMartCart $cart, $order) {

        if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_shipmentmethod_id))) {
            return NULL; // Another method was selected, do nothing
        }
        if (!$this->selectedThisElement($method->shipment_element)) {
            return FALSE;
        }
        $values['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;
        $values['order_number'] = $order['details']['BT']->order_number;
        $values['virtuemart_shipmentmethod_id'] = $order['details']['BT']->virtuemart_shipmentmethod_id;
        $values['shipment_name'] = $this->renderPluginName($method);
        $values['order_weight'] = $this->getOrderWeight($cart, $method->weight_unit);
        $values['shipment_weight_unit'] = $method->weight_unit;

        $costs = $this->getCosts($cart, $method, $cart->cartPrices);
        if (empty($costs)) {
            $values['shipment_cost'] = 0;
            $values['shipment_package_fee'] = 0;
        } else {
            $values['shipment_cost'] = $method->shipment_cost;
            $values['shipment_package_fee'] = $method->package_fee;
        }

        $values['tax_id'] = $method->tax_id;
        $this->storePSPluginInternalData($values);

        return TRUE;
    }

    public function plgVmOnShowOrderBEShipment($virtuemart_order_id, $virtuemart_shipmentmethod_id) {

        if (!($this->selectedThisByMethodId($virtuemart_shipmentmethod_id))) {
            return NULL;
        }
        $html = $this->getOrderShipmentHtml($virtuemart_order_id);
        return $html;
    }

    function getOrderShipmentHtml($virtuemart_order_id) {

        $db = JFactory::getDBO();
        $q = 'SELECT * FROM `' . $this->_tablename . '` '
                . 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
        $db->setQuery($q);
        if (!($shipinfo = $db->loadObject())) {
            vmWarn(500, $q . " " . $db->getErrorMsg());
            return '';
        }

        if (!class_exists('CurrencyDisplay')) {
            require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
        }

        $currency = CurrencyDisplay::getInstance();
        $tax = ShopFunctions::getTaxByID($shipinfo->tax_id);
        $taxDisplay = is_array($tax) ? $tax['calc_value'] . ' ' . $tax['calc_value_mathop'] : $shipinfo->tax_id;
        $taxDisplay = ($taxDisplay == -1) ? JText::_('COM_VIRTUEMART_PRODUCT_TAX_NONE') : $taxDisplay;

        $html = '<table class="adminlist table">' . "\n";
        $html .= $this->getHtmlHeaderBE();
        $html .= $this->getHtmlRowBE('WEIGHT_COUNTRIES_SHIPPING_NAME', $shipinfo->shipment_name);
        $html .= $this->getHtmlRowBE('WEIGHT_COUNTRIES_WEIGHT', $shipinfo->order_weight . ' ' . ShopFunctions::renderWeightUnit($shipinfo->shipment_weight_unit));
        $html .= $this->getHtmlRowBE('WEIGHT_COUNTRIES_COST', $currency->priceDisplay($shipinfo->shipment_cost));
        $html .= $this->getHtmlRowBE('WEIGHT_COUNTRIES_PACKAGE_FEE', $currency->priceDisplay($shipinfo->shipment_package_fee));
        $html .= $this->getHtmlRowBE('WEIGHT_COUNTRIES_TAX', $taxDisplay);
        $html .= '</table>' . "\n";

        return $html;
    }

    function getPackagesStats(VirtueMartCart $cart) {
        $arrBins = array('5x5x4', '8x8x8', '8x8x16', '12x12x10', '12x12x12', '12x12x18', '13x18x24');
        $arr_itmes = $arr_bins = $arr_weight = $array_packages = array();

        if (is_array($cart->products)) {
            foreach ($arrBins as $string) {
                list($l, $w, $h) = explode('x', $string);
                $arr_bins[] = array('w' => $w, 'h' => $h, 'd' => $l, 'id' => str_replace('x', '-', $string));
            }

            foreach ($cart->products as $product) {
                $arr_itmes[$product->virtuemart_product_id] = array("w" => $product->product_width, "h" => $product->product_height, "d" => $product->product_length, "q" => $arr_itmes[$product->virtuemart_product_id]['q'] + $product->quantity, "vr" => 1, "id" => $product->virtuemart_product_id);
                $arr_weight[$product->virtuemart_product_id] = $product->product_weight;
            }

            $query = array(
                'items' => array_values($arr_itmes),
                'bins' => $arr_bins,


                'params' => array('images_width' => 250, 'images_height' => 250, 'item_coordinates' => 0, 'stats' => 0, 'images_sbs' => 0, 'images_separated' => 0, 'images_complete' => 0)
            );

            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, 'query=' . json_encode($query));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . "/us-east.api.3dbinpacking.com.pem");
            $resp = curl_exec($ch);

            if (curl_errno($ch) == 0) {

                $data = json_decode($resp, true);

                if (isset($data['response'])) {
                    $response = &$data['response'];
                    if (empty($response['errors'])) {

                        foreach ($response['bins_packed'] as $bin_key => $bin) {
                            if (!isset($array_packages[$bin['bin_data']['id']])) {
                                list($l, $w, $h) = explode('-', $bin['bin_data']['id']);
                                $array_packages[$bin_key] = array('size' => array('l' => $l, 'w' => $w, 'h' => $h), 'weight' => 0);
                            }
                            // read item packed into this bin
                            $current_bin = &$array_packages[$bin_key];

                            foreach ($bin['items'] as $item) {
                                $current_bin['weight'] = $current_bin['weight'] + $arr_weight[$item['id']];
                            }
                        }
                    } else {
                        JError::raiseWarning('500', 'Shipping error.' . implode($response['errors']));
                        return false;
                    }
                }

                return $array_packages;
            } else {

                //vmWarn(500, $q . " " . 'Unable to calculate shipping, Try again later.'.curl_error($ch));
                JError::raiseWarning('500', 'Unable to calculate shipping, Try again later.' . curl_error($ch));
                return false;
            }
            curl_close($ch);
        } else {
            return $array_packages;
        }
    }



    function modify_residential_array(&$arrRes, $arrComm) {
        $flatRate = $this->getPriceInDeliverMethodArray('FEDEX_GROUND', $arrComm);
        // update price
        $arrRes = $this->setPriceInDeliverMethodArray('GROUND_HOME_DELIVERY', $flatRate + 2, $arrRes);
    }

    function setPriceInDeliverMethodArray($code, $price, $delivery_methods) {
        if (is_array($delivery_methods) && count($delivery_methods) > 0)
            foreach ($delivery_methods as &$shipping_methods) {
                if ($shipping_methods['code'] == $code)
                    $shipping_methods['price'] = $price;
            }
        return $delivery_methods;
    }

    function getPriceInDeliverMethodArray($code, $delivery_methods) {
        foreach ($delivery_methods as &$shipping_methods) {
            if ($shipping_methods['code'] == $code)
                return $shipping_methods['price'];
        }
        return 0;
    }

    function get_saved_rates() {

        return $this->methods_rates;
    }



    protected function checkConditions($cart, $method, $cart_prices) {

        $this->convert($method);

        $orderWeight = $this->getOrderWeight($cart, $method->weight_unit);
        $address = (($cart->ST == 0) ? $cart->BT : $cart->ST);

        $countries = array();
        if (!empty($method->countries)) {
            if (!is_array($method->countries)) {
                $countries[0] = $method->countries;
            } else {
                $countries = $method->countries;
            }
        }

        if (!is_array($address)) {

            $address = array();
            $address['Zip'] = 0;
            $address['virtuemart_country_id'] = 0;
        }

        $weight_cond = $this->_weightCond($orderWeight, $method);
        $nbproducts_cond = $this->_nbproductsCond($cart, $method);
        $orderamount_cond = $this->_orderamountCond($cart_prices, $method);

        if (!isset($address['Zip'])) {
            $address['Zip'] = 0;
        }

        $Zip_cond = $this->_zipCond($address['Zip'], $method);

        if (!isset($address['virtuemart_country_id'])) {
            $address['virtuemart_country_id'] = 0;
        }

        if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {

            //vmdebug('checkConditions '.$method->name.' fit ',$weight_cond,(int)$Zip_cond,$nbproducts_cond,$orderamount_cond);

            $allconditions = (int) $weight_cond + (int) $Zip_cond + (int) $nbproducts_cond + (int) $orderamount_cond;
            if ($allconditions === 4) {
                return TRUE;
            } else {
                return FALSE;
            }
        }
        vmdebug('checkConditions ' . $method->name . ' does not fit');
        return FALSE;
    }

    function convert(&$method) {

        //$method->weight_start = (float) $method->weight_start;
        //$method->weight_stop = (float) $method->weight_stop;
        $method->orderamount_start = (float) $method->orderamount_start;
        $method->orderamount_stop = (float) $method->orderamount_stop;
        $method->Zip_start = (int) $method->Zip_start;
        $method->Zip_stop = (int) $method->Zip_stop;
        $method->nbproducts_start = (int) $method->nbproducts_start;
        $method->nbproducts_stop = (int) $method->nbproducts_stop;
        $method->free_shipment = (float) $method->free_shipment;
    }

    private function _weightCond($orderWeight, $method) {

        $weight_cond = (($orderWeight >= $method->weight_start AND $orderWeight <= $method->weight_stop) OR
                ($method->weight_start <= $orderWeight AND $method->weight_stop === ''));

        return $weight_cond;
    }

    private function _nbproductsCond($cart, $method) {

        $nbproducts = 0;
        foreach ($cart->products as $product) {
            $nbproducts += $product->quantity;
        }
        if (!isset($method->nbproducts_start) and !isset($method->nbproducts_stop)) {
            return true;
        }
        if ($nbproducts) {
            $nbproducts_cond = ($nbproducts >= $method->nbproducts_start AND $nbproducts <= $method->nbproducts_stop OR
                    ($method->nbproducts_start <= $nbproducts AND ($method->nbproducts_stop == 0)));
        } else {
            $nbproducts_cond = true;
        }
        return $nbproducts_cond;
    }

    private function _orderamountCond($cart_prices, $method) {

        if (!isset($method->orderamount_start) AND !isset($method->orderamount_stop)) {
            return true;
        }
        if ($cart_prices['salesPrice']) {
            $orderamount_cond = ($cart_prices['salesPrice'] >= $method->orderamount_start AND $cart_prices['salesPrice'] <= $method->orderamount_stop OR
                    ($method->orderamount_start <= $cart_prices['salesPrice'] AND ($method->orderamount_stop == 0)));
        } else {
            $orderamount_cond = true;
        }

        return $orderamount_cond;
    }

    private function _zipCond($Zip, $method) {

        $Zip = (int) $Zip;
        $Zip_cond = true;
        if (!empty($Zip)) {

            if (!empty($method->Zip_start) and !empty($method->Zip_stop)) {
                $Zip_cond = (($Zip >= $method->Zip_start AND $Zip <= $method->Zip_stop));
            } else if (!empty($method->Zip_start)) {
                $Zip_cond = ($Zip >= $method->Zip_start);
            } else if (!empty($method->Zip_stop)) {
                $Zip_cond = ($Zip <= $method->Zip_stop);
            }
        } else if (!empty($method->Zip_start) or !empty($method->Zip_stop)) {
            $Zip_cond = false;
        }

        return $Zip_cond;
    }

    function plgVmOnStoreInstallShipmentPluginTable($jplugin_id) {

        return $this->onStoreInstallPluginTable($jplugin_id);
    }

    public function plgVmOnSelectCheckShipment(VirtueMartCart &$cart) {

        return $this->OnSelectCheck($cart);
    }

    public function plgVmDisplayListFEShipment(VirtueMartCart $cart, $selected = 0, &$htmlIn) {

        return $this->displayListFE($cart, $selected, $htmlIn);
    }

    public function plgVmOnSelectedCalculatePriceShipment(VirtueMartCart $cart, array &$cart_prices, &$cart_prices_name) {

        return $this->onSelectedCalculatePrice($cart, $cart_prices, $cart_prices_name);
    }


    function plgVmOnCheckAutomaticSelectedShipment(VirtueMartCart $cart, array $cart_prices = array(), &$shipCounter) {

        if ($shipCounter > 1) {
            return 0;
        }
        return $this->onCheckAutomaticSelected($cart, $cart_prices, $shipCounter);
    }


    function plgVmonShowOrderPrint($order_number, $method_id) {

        return $this->onShowOrderPrint($order_number, $method_id);
    }

       function plgVmDeclarePluginParamsShipment($name, $id, &$data) {

        return $this->declarePluginParams('shipment', $name, $id, $data);
    }

    function plgVmDeclarePluginParamsShipmentVM3(&$data) {
        return $this->declarePluginParams('shipment', $data);
    }

    function plgVmSetOnTablePluginParamsShipment($name, $id, &$table) {

        return $this->setOnTablePluginParams($name, $id, $table);
    }

    function plgVmGetTablePluginParams($psType, $name, $id, &$xParams, &$varsToPush) {
        return $this->getTablePluginParams($psType, $name, $id, $xParams, $varsToPush);
    }

}

J'ai supprimé certaines fonctions en raison de la longueur du fichier. Aidez-moi à cet égard. Merci

1
urfusion

Vous devez changer les étiquettes de configuration à partir de:

<vmconfig>

à:

<config>

Comme c'est ce que Joomla utilise. Les balises que vous utilisez actuellement doivent appartenir aux propres extensions de VirtueMarts, mais comme vous êtes une tierce partie, elles ne fonctionneront pas.

Il vous manque également le name de la balise fields et la balise réelle fieldset.

Vous devriez utiliser:

<config>
    <fields name="params">
        <fieldset name="basic" addfieldpath="/administrator/components/com_virtuemart/elements">

            <field name="fedex_account_number" type="text" label="FedEx account number" />
            // REST OF FIELDS

        </fieldset>
    </fields>
</config>

Vous devriez également utiliser addfieldpath au lieu de addpath et l'appliquer à votre champs.

1
Lodder