Jump to content

Edit History

overbags

overbags


RISOLTO

ciao a tutti
ho due moduli che sono in conflitto perchè effettuano l'override della stessa function "public function getTotalWeight()"

come potrei risolvere è possibile unificarle ?

 

    MODULO UNO --------------------------------------------------------
    public function getTotalWeight($products = null)
    {
        $total_weight = parent::getTotalWeight($products);
        if (!Module::isEnabled('dynamicproduct')) {
            return $total_weight;
        }
        
        $module = Module::getInstanceByName('dynamicproduct');
        return $total_weight + $module->calculator->getTotalWeight($this->id);
    }

    MODULO DUE ----------------------------------------
    public function getTotalWeight($products = null, $id_carrier = null)
    {
        if (is_null($id_carrier)) {
            $id_carrier = $this->id_carrier;
        }
        
        include_once(_PS_MODULE_DIR_ . 'dimensionalweight/classes/dimensionalweightcarrierrule.php');
        include_once(_PS_MODULE_DIR_ . 'dimensionalweight/classes/dimensionalweightproductattribute.php');
        
        if (! Module::isEnabled("dimensionalweight")) {
            return parent::getTotalWeight($products);
        }
        
        $carrier_rule = DimensionalWeightCarrierRule::getRuleByIdCarrier($id_carrier);
        
        if (! is_null($products)) {
            $total_weight = 0;
            
            foreach ($products as $product) {
                $dim_attributes = DimensionalWeightProductAttribute::getAttributeCombinationsById($product['id_product_attribute']);
                $real_weight = (! isset($product['weight_attribute']) || is_null($product['weight_attribute']) ? $product['weight'] : $product['weight_attribute']);
                
                if (! empty($carrier_rule) && $carrier_rule['active']) {
                    $dim_weight = (((! isset($dim_attributes[0]['width']) || is_null($dim_attributes[0]['width']) ? $product['width'] : ($product['width'] + $dim_attributes[0]['width'])) * (! isset($dim_attributes[0]['height']) || is_null($dim_attributes[0]['height']) ? $product['height'] : ($product['height'] + $dim_attributes[0]['height'])) * (! isset($dim_attributes[0]['depth']) || is_null($dim_attributes[0]['depth']) ? $product['depth'] : ($product['depth'] + $dim_attributes[0]['depth']))) / $carrier_rule['factor']);
                    
                    $weight = ($dim_weight > $real_weight ? $dim_weight : $real_weight);
                    $total_weight += $weight * $product['cart_quantity'];
                } else {
                    $total_weight += $real_weight * $product['cart_quantity'];
                }
            }
            return $total_weight;
        }
        
        $products = Db::getInstance()->executeS('
        SELECT p.`weight` as weight, pa.`weight` as weight_attribute, p.`width` as width, p.`height` as height, p.`depth` as depth, cp.`quantity` as cart_quantity, dpa.`width` as width_attribute, dpa.`height` as height_attribute, dpa.`depth` as depth_attribute
        FROM `' . _DB_PREFIX_ . 'cart_product` cp
        LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (cp.`id_product` = p.`id_product`)
        LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (cp.`id_product_attribute` = pa.`id_product_attribute`)
        LEFT JOIN `' . _DB_PREFIX_ . 'dimensionalweight_product_attribute` dpa ON (cp.`id_product_attribute` = dpa.`id_product_attribute`)
        WHERE  cp.`id_cart` = ' . (int) $this->id);
        
        $total_weight = 0;
        
        foreach ($products as $product) {
            $real_weight = (! isset($product['weight_attribute']) || is_null($product['weight_attribute']) ? $product['weight'] : ($product['weight'] + $product['weight_attribute']));
            
            if (! empty($carrier_rule)  && $carrier_rule['active']) {
                $dim_weight = (((! isset($product['width_attribute']) || is_null($product['width_attribute']) ? $product['width'] : ($product['width'] + $product['width_attribute'])) * (! isset($product['height_attribute']) || is_null($product['height_attribute']) ? $product['height'] : ($product['height'] + $product['height_attribute'])) * (! isset($product['depth_attribute']) || is_null($product['depth_attribute']) ? $product['depth'] : ($product['depth'] + $product['depth_attribute']))) / $carrier_rule['factor']);
                $weight = ($dim_weight > $real_weight ? $dim_weight : $real_weight);
                $total_weight += $weight * $product['cart_quantity'];
            } else {
                $total_weight += $real_weight * $product['cart_quantity'];
            }
        }
        
        if (version_compare(_PS_VERSION_, '1.6.1.2', '<')) {
            self::$_totalWeight[$this->id] = round((float) $total_weight, 3);
        } else {
            self::$_totalWeight[$this->id] = round((float) $total_weight, 6);
        }
        return self::$_totalWeight[$this->id];
    }

overbags

overbags

ciao a tutti
ho due moduli che sono in conflitto perchè effettuano l'override della stessa function "public function getTotalWeight()"

come potrei risolvere è possibile unificarle ?

 

    MODULO UNO --------------------------------------------------------
    public function getTotalWeight($products = null)
    {
        $total_weight = parent::getTotalWeight($products);
        if (!Module::isEnabled('dynamicproduct')) {
            return $total_weight;
        }
        
        $module = Module::getInstanceByName('dynamicproduct');
        return $total_weight + $module->calculator->getTotalWeight($this->id);
    }

    MODULO DUE ----------------------------------------
    public function getTotalWeight($products = null, $id_carrier = null)
    {
        if (is_null($id_carrier)) {
            $id_carrier = $this->id_carrier;
        }
        
        include_once(_PS_MODULE_DIR_ . 'dimensionalweight/classes/dimensionalweightcarrierrule.php');
        include_once(_PS_MODULE_DIR_ . 'dimensionalweight/classes/dimensionalweightproductattribute.php');
        
        if (! Module::isEnabled("dimensionalweight")) {
            return parent::getTotalWeight($products);
        }
        
        $carrier_rule = DimensionalWeightCarrierRule::getRuleByIdCarrier($id_carrier);
        
        if (! is_null($products)) {
            $total_weight = 0;
            
            foreach ($products as $product) {
                $dim_attributes = DimensionalWeightProductAttribute::getAttributeCombinationsById($product['id_product_attribute']);
                $real_weight = (! isset($product['weight_attribute']) || is_null($product['weight_attribute']) ? $product['weight'] : $product['weight_attribute']);
                
                if (! empty($carrier_rule) && $carrier_rule['active']) {
                    $dim_weight = (((! isset($dim_attributes[0]['width']) || is_null($dim_attributes[0]['width']) ? $product['width'] : ($product['width'] + $dim_attributes[0]['width'])) * (! isset($dim_attributes[0]['height']) || is_null($dim_attributes[0]['height']) ? $product['height'] : ($product['height'] + $dim_attributes[0]['height'])) * (! isset($dim_attributes[0]['depth']) || is_null($dim_attributes[0]['depth']) ? $product['depth'] : ($product['depth'] + $dim_attributes[0]['depth']))) / $carrier_rule['factor']);
                    
                    $weight = ($dim_weight > $real_weight ? $dim_weight : $real_weight);
                    $total_weight += $weight * $product['cart_quantity'];
                } else {
                    $total_weight += $real_weight * $product['cart_quantity'];
                }
            }
            return $total_weight;
        }
        
        $products = Db::getInstance()->executeS('
        SELECT p.`weight` as weight, pa.`weight` as weight_attribute, p.`width` as width, p.`height` as height, p.`depth` as depth, cp.`quantity` as cart_quantity, dpa.`width` as width_attribute, dpa.`height` as height_attribute, dpa.`depth` as depth_attribute
        FROM `' . _DB_PREFIX_ . 'cart_product` cp
        LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (cp.`id_product` = p.`id_product`)
        LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (cp.`id_product_attribute` = pa.`id_product_attribute`)
        LEFT JOIN `' . _DB_PREFIX_ . 'dimensionalweight_product_attribute` dpa ON (cp.`id_product_attribute` = dpa.`id_product_attribute`)
        WHERE  cp.`id_cart` = ' . (int) $this->id);
        
        $total_weight = 0;
        
        foreach ($products as $product) {
            $real_weight = (! isset($product['weight_attribute']) || is_null($product['weight_attribute']) ? $product['weight'] : ($product['weight'] + $product['weight_attribute']));
            
            if (! empty($carrier_rule)  && $carrier_rule['active']) {
                $dim_weight = (((! isset($product['width_attribute']) || is_null($product['width_attribute']) ? $product['width'] : ($product['width'] + $product['width_attribute'])) * (! isset($product['height_attribute']) || is_null($product['height_attribute']) ? $product['height'] : ($product['height'] + $product['height_attribute'])) * (! isset($product['depth_attribute']) || is_null($product['depth_attribute']) ? $product['depth'] : ($product['depth'] + $product['depth_attribute']))) / $carrier_rule['factor']);
                $weight = ($dim_weight > $real_weight ? $dim_weight : $real_weight);
                $total_weight += $weight * $product['cart_quantity'];
            } else {
                $total_weight += $real_weight * $product['cart_quantity'];
            }
        }
        
        if (version_compare(_PS_VERSION_, '1.6.1.2', '<')) {
            self::$_totalWeight[$this->id] = round((float) $total_weight, 3);
        } else {
            self::$_totalWeight[$this->id] = round((float) $total_weight, 6);
        }
        return self::$_totalWeight[$this->id];
    }

×
×
  • Create New...