module + modified files + files for importing attributes and data for database/iprintmodule/iprintmodule.php
//On save of the Dynamic Pricing tab, this code runs
On save of the Dynamic Pricing tab, this code runs
On save of the Dynamic Pricing tab this code runs
public function hookActionProductUpdate($params)
    {
        $is_dynamically_priced_product = NULL;
        $does_use_dynamic_pricing = Tools::getValue("does_use_dynamic_pricing");
        $id_of_product;
        if (Tools::getValue('id_product') == null || Tools::getValue('id_product') == "") {
            $id_of_product = $params["id_product"];
        } else {
            $id_of_product = Tools::getValue('id_product');
        }
        if ($does_use_dynamic_pricing == "1") {
            $is_dynamically_priced_product = true;
        } else if ($does_use_dynamic_pricing == "0") {
            $is_dynamically_priced_product = false;
        }
        if ($is_dynamically_priced_product) {
            $val = Tools::getValue("attribute_groups_used");
            if (!empty($val)) {
                Db::getInstance()->update('product',
                    array( 
                        'is_dynamically_priced_product' => true,
                        'pricing_algorithm_attribute_groups' => Db::getInstance()->_escape(Tools::getValue("attribute_groups_used")),
                        'dynamic_pricing_product_quantity' => Db::getInstance()->_escape(Tools::getValue("dp_product_quantity")),
                        'has_custom_quantity_attribute' => intval(Tools::getValue("has_custom_qty_attr")),
                        'custom_quantity_attribute_name' => Tools::getValue("custom_qty_attr_name"),
                        'formula_to_use' => Tools::getValue("formula_to_use"),
                        'has_alias_for_quantity' => true
                    ),
                    'id_product = ' . $id_of_product
                );
                if (is_numeric(Tools::getValue("dp_product_quantity"))) {
                    StockAvailable::updateQuantity($id_of_product, null, 0);
                }
            } else {
                $error = Tools::displayError('No data added to the "Attribute groups to be displayed..." field');
                $this->context->controller->errors[] = $error;
            }
        } else {
            Db::getInstance()->update('product',
                array( 
                    'is_dynamically_priced_product' => false
                ),
                'id_product = '.$id_of_product
            );
        }
    }
public function hookActionProductUpdate ( $ params ) { $ is_dynamically_priced_product = NULL ; $ does_use_dynamic_pricing = Tools :: getValue ( " does_use_dynamic_pricing " ) ; $ id_of_product ; if ( Tools :: getValue ( 'id_product' ) == null || Tools :: getValue ( 'id_product' ) == " " ) { $ id_of_product = $ params [ " id_product " ] ; } else { $ id_of_product = Tools :: getValue ( 'id_product' ) ; } if ( $ does_use_dynamic_pricing == " 1 " ) { $ is_dynamically_priced_product = true ; } else if ( $ does_use_dynamic_pricing == " 0 " ) { $ is_dynamically_priced_product = false ; } if ( $ is_dynamically_priced_product ) { $ val = Tools :: getValue ( " attribute_groups_used " ) ; if ( ! empty ( $ val ) ) { Db :: getInstance ( ) -> update ( 'product' , array ( 'is_dynamically_priced_product' => true , 'pricing_algorithm_attribute_groups' => Db :: getInstance ( ) -> _escape ( Tools :: getValue ( " attribute_groups_used " ) ) , 'dynamic_pricing_product_quantity' => Db :: getInstance ( ) -> _escape ( Tools :: getValue ( " dp_product_quantity " ) ) , 'has_custom_quantity_attribute' => intval ( Tools :: getValue ( " has_custom_qty_attr " ) ) , 'custom_quantity_attribute_name' => Tools :: getValue ( " custom_qty_attr_name " ) , 'formula_to_use' => Tools :: getValue ( " formula_to_use " ) , 'has_alias_for_quantity' => true ) , 'id_product = ' . $ id_of_product ) ; if ( is_numeric ( Tools :: getValue ( " dp_product_quantity " ) ) ) { StockAvailable :: updateQuantity ( $ id_of_product , null , 0 ) ; } } else { $ error = Tools :: displayError ( 'No data added to the "Attribute groups to be displayed..." field' ) ; $ this -> context -> controller -> errors [ ] = $ error ; } } else { Db :: getInstance ( ) -> update ( 'product' , array ( 'is_dynamically_priced_product' => false ) , 'id_product = ' . $ id_of_product ) ; } }
On save of the Dynamic Pricing tab, this code runs
On save of the Dynamic Pricing tab this code runs
//d($params); //str_getcsv returns an array //$attr_group_names = str_getcsv(Tools::getValue("attribute_groups_used")); //json_encode transforms the array into a json string to be decoded when it is retrieved next time //$pricing_algor_attribute_groups = json_encode($attr_group_names); //TODO: add a former_show_price field? so that when product stops being a dynamically priced product, it will keep it's former show_price value //update table // with this data /*'quantity' => Db::getInstance()->_escape(Tools::getValue("dp_product_quantity")),
                        'out_of_stock' =>  ((int)Tools::getValue("dp_product_quantity")) <= 0 ? 1 : 0,*/ /*'specific_quantity_choices' => Tools::getValue("specific_qty_choices")*/ //where //This causes the StockAvailable quantity to align with the dp_product_quantity //TODO: programatically set this product to have setting of "Allow orders" "When out of stock" so that the price doesn't display //update table // with this data /*,
                    'show_price' => true*/ //where /*if hook product update may be triggered many times use this
        if ($this->isSaved)
            return null;

        and do $this->isSaved = true; at end of this method*/ /*Db::getInstance()->update('product', array('custom_field'=> pSQL(Tools::getValue('custom_field_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_product = ' .$id_product );
        $id_product = (int)Tools::getValue('id_product');

        $languages = Language::getLanguages(true);
        foreach ($languages as $lang) {
            if(!Db::getInstance()->update('product_lang', array('custom_field'=> pSQL(Tools::getValue('custom_field_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_product = ' .$id_product ))
                $this->context->controller->_errors[] = Tools::displayError('Error: ').mysql_error();
        }*/ //possibly will need die() at end