Jump to content
Fórum Script Brasil
  • 0

Problema com soma do "valor total"


Raissa

Question

Olá! Estou utilizando um script de compra coletiva que contém um arquivo de tradução para pt_br, inclusive a moeda e formato decimal. Exemplo, a compra é no valor de R$12,99. No carrinho de compras ele demonstra R$12,99 mas ao selecionar 2 itens ao invés de somar R$25,98 ele soma R$2,598. A página que estou testando que está com erro http://cuponss.com/deal/purchase/id/2

Acredito que seja algum problema aqui:

return array (
  'version' => '4123',
  'numberSymbols' => 
  array (
    'decimal' => ',',
    'group' => '.',
    'list' => ';',
    'percentSign' => '%',
    'nativeZeroDigit' => '0',
    'patternDigit' => 'nº',
    'plusSign' => '+',
    'minusSign' => '-',
    'exponential' => 'E',
    'perMille' => '‰',
    'infinity' => '∞',
    'nan' => 'NaN',
  ),
  'decimalFormat' => '#,##0.####',
  'scientificFormat' => '#E0',
  'percentFormat' => '#,##0%',
  'currencyFormat' => '¤#,##0.00;(¤#,##0.00)',
No "shopping cart" está esse codigo:
<?php
class WPaymentCart extends UListWorklet
{
    public $addCheckBoxColumn=false;
    public $addButtonColumn=false;
    public $addMassButton=false;
    
    private $_cart = array();
    
    public function accessRules()
    {
        return array(
            array('deny', 'users'=>array('?'))
        );
    }
    
    public function title()
    {
        return $this->t('Your Purchase');
    }
    
    public function form()
    {
        return 'payment.checkout';
    }
    
    public function taskConfig()
    {
        $this->options = array(
            'selectableRows' => 0,
            'rowCssClassExpression' => '$row==count($this->dataProvider->data)-1
                ? "cartTotal" : $this->rowCssClass[$row%count($this->dataProvider->data)]',
        );
        return parent::taskConfig();
    }
    
    /**
     * Puts an item into the cart.
     * @param string module name
     * @param string item id
     * @param string item description
     * @param integer quantity
     * @param integer price
     */
    public function taskPut($module,$id,$description,$quantity,$price)
    {
        $key = $module.$id;
        // if item already exists - increase quantity
        if(isset($this->_cart[$key]))
            $this->_cart[$key]['quantity']+= $quantity;
        else
            $this->_cart[$key] = array(
                'id' => $id,
                'module' => $module,
                'description' => $description,
                'quantity' => $quantity,
                'price' => $price,
            );
    }
    
    /**
     * Removes item from the cart.
     * @param string module name
     * @param string item ID
     */
    public function taskRemove($module,$id)
    {
        if(isset($this->_cart[$module.$id]))
            unset($this->_cart[$module.$id]);
    }
    
    public function taskQuantityField($data)
    {
        echo CHtml::textField('items['.$data['module'].']['.$data['id'].']', $data['quantity'],
            array('class'=>'quantityField'));
    }
    
    public function columns()
    {
        return array(
            array('header' => $this->t('Description'), 'name' => 'description'),
            array('header' => $this->t('Quantity'),
                'value' => '$data["quantity"]!==null
                    ? wm()->get("payment.cart")->quantityField($data)
                    : NULL',
                'type' => 'raw'),
            array('header' => $this->t('Price'), 'value' => '$data["price"]
                    ? m("payment")->param("cSymbol")
                        . "<span class=\'price\'>".app()->numberFormatter->formatDecimal($data["price"])."</span>"
                    : NULL',
                'type' => 'raw'),
            array('header' => $this->t('Total'),
                'value' => 'm("payment")->param("cSymbol") . "<span class=\'total\'>"
                    . app()->numberFormatter->formatDecimal(isset($data["total"])?$data["total"]:$data["quantity"]*$data["price"])."</span>"',
                'type' => 'raw'),
        );
    }
    
    public function dataProvider()
    {
        $credit = wm()->get('payment.helper')->credit();
        if($credit)
            $this->put('payment',0,$this->t('Use my {site} credit: {credit}',
                array('{site}'=>app()->name,'{credit}' => m('payment')->format($credit))),
                0, -1);
                
        $data = array_values($this->_cart);
        
        $total = 0;
        foreach($data as $d)
            $total+= $d['price']*$d['quantity'];
        $data[] = array(
            'id' => 'total',
            'module' => 'payment',
            'description' => $this->t('My Price'),
            'quantity' => NULL,
            'price' => NULL,
            'total' => $total,
        );
        return new CArrayDataProvider($data);
    }
    
    public function taskRenderOutput()
    {
        cs()->registerScript(__CLASS__,'jQuery("#'.$this->getDOMId().'").uPaymentCart();');
        return parent::taskRenderOutput();
    }
}

O que pode estar causando esse problema com as casas decimais?? Desculpe se não fui clara, procurei no fórum e não achei nada que arrumasse! Vlw

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...