Question

I'm trying to create an article in magento to based on a dataset from an erp system. So far creating works with only one remaining glitch. I can't set group nor tear prices.

Here's my code:

protected function updatePrices(){
        $groups = Mage::getModel('customer/group')->getCollection()->getAllIds();
        if((float)$this->erpdata['grundpreis'] > 0.00){
            $this->product->setPrice((float)$this->erpdata['grundpreis']);
        }
        if((float)$this->erpdata['shop']['art']['products_pseudoprices'] > 0.00){
            $this->product->setMsrp((float)$this->erpdata['shop']['art']['products_pseudoprices']);
        }
        //preapre the price data for ranges
        $prepareDatas = array();
        if(count($this->erpdata['preisgruppen'])){
            foreach($this->erpdata['preisgruppen'] as $group){
                $dset = array('gruppe'=>0,'gp'=>0,'range'=>array());
                foreach($group as $key=>$value){
                    if($key ===  'gruppe'){
                        $dset['gruppe']= ((int)$value - (int)250);
                    }else if($key === 'grundpreis'){
                        $dset['gp'] = $value;
                    }else if(strpos($key,'preis_gruppe')!==false){
                        $ident = (int)str_replace('preis_gruppe','',$key);
                        if(!isset($dset['range'][$ident]) || !is_array($dset['range'][$ident])){
                            $dset['range'][$ident] = array();
                        }
                        $dset['range'][$ident]['price'] = $value;
                    }else if(strpos($key,'preis_range')!==false){
                        $ident = (int)str_replace('preis_range','',$key);
                        if(!isset($dset['range'][$ident]) || !is_array($dset['range'][$ident])){
                            $dset['range'][$ident] = array();
                        }
                        $dset['range'][$ident]['quantity'] = $value;
                    }
                }
                $prepareDatas[] = $dset;
            }
        }
        //now process the stuff for each pricegroup to add it to the main article
        $storeid = Mage::app()->getStore()->getWebsiteId();
        $pricegroupdata = array();
        $tiergroupdata = array();
        foreach($prepareDatas as $prepareData){
            //first set the Grundpreis
            $pricegroupdata[] = array(
                'website_id'=>$storeid,
                'cust_group'=>$prepareData['gruppe'],
                'price'=>(float)$prepareData['gp']
            );
            //now run through the groups if available
            if(count($prepareData['range'])>0){
                foreach($prepareData['range'] as $range){
                    $tiergroupdata[] = array(
                        'website_id'=>$storeid,
                        'cust_group'=>$prepareData['gruppe'],
                        'price'=>(float)$range['price'],
                        'price_qty'=>number_format((float)$range['quantity'], 4, '.','')
                    );
                }
            }
        }
        if(count($pricegroupdata)>0){
            $this->product->group_price = $pricegroupdata;
        }
        if(count($tiergroupdata)>0){
            $this->product->tier_price = $tiergroupdata;
        }
    }

The Article Price is set. Also the cost value. But neither tier nor group prices are set or updated. What am I doing wrong? Where am I mistakin?

every help is appreceated.

Was it helpful?

Solution

Found the solution by just simply storing the fresh created product. After that it worked without a problem, although I had to extend the object that was stored quite a bit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top