示例#1
0
 public function __construct($name = null, Context $context = null)
 {
     $this->name = 'pproperties';
     $this->tab = 'administration';
     $this->version = '2.14';
     $this->author = 'psandmore';
     $this->module_key = 'a78315086f12ede793183c113b223617';
     $this->need_instance = 1;
     $this->ps_versions_compliancy = array('min' => '1.6.0.14', 'max' => '1.6.0.14');
     $this->bootstrap = true;
     parent::__construct($name, $context);
     $this->displayName = $this->l('Product Properties Extension');
     $this->description = $this->l('Extends product properties and add support for products with fractional units of measurements (for example: weight, length, volume)');
     $this->confirmUninstall = $this->l('When you uninstall this module the user data is not lost and remains in the database. It will be available next time you install the module. Are you sure you want to remove the Product Properties Extension module?');
     $this->secure_key = Tools::encrypt($this->name);
     if (Module::isInstalled($this->name)) {
         require_once dirname(__FILE__) . '/psm_helper.php';
         $this->integrated = Configuration::get('PP_INTEGRATION') == $this->integrationKey();
         if (PP::multidimensionalEnabled()) {
             $this->multidimensional_plugin = PSM::getPlugin('ppropertiesmultidimensional');
         }
     } else {
         static $done;
         if (!$done) {
             $done = true;
             require_once dirname(__FILE__) . '/psm_helper_integrate.php';
             psmHelperIntegrate(array($this->name));
             $filename = _PS_ROOT_DIR_ . '/classes/module/Module.php';
             $content = Tools::file_get_contents($filename);
             $content = str_replace(array('?(?:php)?\\s#', 'array(\' \','), array('?php#', 'array(\'\','), $content, $count);
             if ($count > 0) {
                 @file_put_contents($filename, $content);
             }
             require_once dirname(__FILE__) . '/psm_helper.php';
             psmIntegrateCore($this, dirname(__FILE__) . '/psm.php', $this->_errors);
         }
     }
 }
示例#2
0
    public function deleteProduct($id_product, $id_product_attribute = null, $id_customization = null, $id_address_delivery = 0, $id_cart_product = 0)
    {
        if (isset(self::$_nbProducts[$this->id])) {
            unset(self::$_nbProducts[$this->id]);
        }
        if (isset(self::$_totalWeight[$this->id])) {
            unset(self::$_totalWeight[$this->id]);
        }
        /*
        if ((int)$id_customization)
        {
        	$product_total_quantity = (int)Db::getInstance()->getValue(
        		'SELECT `quantity`
        		FROM `'._DB_PREFIX_.'cart_product`
        		WHERE `id_product` = '.(int)$id_product.'
        		AND `id_cart` = '.(int)$this->id.'
        		AND `id_product_attribute` = '.(int)$id_product_attribute);
        
        	$customization_quantity = (int)Db::getInstance()->getValue('
        	SELECT `quantity`
        	FROM `'._DB_PREFIX_.'customization`
        	WHERE `id_cart` = '.(int)$this->id.'
        	AND `id_product` = '.(int)$id_product.'
        	AND `id_product_attribute` = '.(int)$id_product_attribute.'
        	'.((int)$id_address_delivery ? 'AND `id_address_delivery` = '.(int)$id_address_delivery : ''));
        
        	if (!$this->_deleteCustomization((int)$id_customization, (int)$id_product, (int)$id_product_attribute, (int)$id_address_delivery))
        		return false;
        
        	// refresh cache of self::_products
        	$this->_products = $this->getProducts(true);
        	return ($customization_quantity == $product_total_quantity && $this->deleteProduct((int)$id_product, (int)$id_product_attribute, null, (int)$id_address_delivery));
        }
        
        // Get customization quantity
        $result = Db::getInstance()->getRow('
        	SELECT SUM(`quantity`) AS \'quantity\'
        	FROM `'._DB_PREFIX_.'customization`
        	WHERE `id_cart` = '.(int)$this->id.'
        	AND `id_product` = '.(int)$id_product.'
        	AND `id_product_attribute` = '.(int)$id_product_attribute);
        
        if ($result === false)
        	return false;
        
        // If the product still possesses customization it does not have to be deleted
        if (Db::getInstance()->NumRows() && (int)$result['quantity'])
        	return Db::getInstance()->execute('
        		UPDATE `'._DB_PREFIX_.'cart_product`
        		SET `quantity` = '.(int)$result['quantity'].'
        		WHERE `id_cart` = '.(int)$this->id.'
        		AND `id_product` = '.(int)$id_product.
        		($id_product_attribute != null ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '')
        	);
        */
        if (($id_cart_product = PP::resolveIcp($id_cart_product)) <= 0) {
            return false;
        }
        $sql_icp = PP::sqlIcp($id_cart_product);
        $id_customization = (int) Db::getInstance()->getValue('
			SELECT `id_customization`
			FROM `' . _DB_PREFIX_ . 'customization`
			WHERE `id_cart_product` = ' . (int) $id_cart_product);
        if ((int) $id_customization && !$this->_deleteCustomization((int) $id_customization, (int) $id_product, (int) $id_product_attribute, (int) $id_address_delivery)) {
            return false;
        }
        /* Product deletion */
        $result = Db::getInstance()->execute('
		DELETE FROM `' . _DB_PREFIX_ . 'cart_product`
		WHERE `id_product` = ' . (int) $id_product . '
		' . (!is_null($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
		AND `id_cart` = ' . (int) $this->id . '
		' . ((int) $id_address_delivery ? 'AND `id_address_delivery` = ' . (int) $id_address_delivery : '') . $sql_icp);
        if (PP::multidimensionalEnabled()) {
            Db::getInstance()->execute('
			DELETE FROM `' . _DB_PREFIX_ . 'pp_product_ext`
			WHERE `id_cart_product` = ' . (int) $id_cart_product);
        }
        if ($result) {
            $return = $this->update();
            // refresh cache of self::_products
            $this->_products = $this->getProducts(true);
            CartRule::autoRemoveFromCart();
            CartRule::autoAddToCart();
            return $return;
        }
        return false;
    }