Calculate a price rule
@param int $total
@param array $data
@param array $components
@param array $price_rule
191175
public function calculate(&$total, $data, &$components, array $price_rule)
    {
        try {
            $callback = Handler::get($this->getTypes(), $price_rule['value_type'], 'calculate');
            call_user_func_array($callback, array(&$total, &$components, $price_rule, $data));
        } catch (Exception $ex) {
            trigger_error($ex->getMessage());
        }
    }
857859
public function percent(&$amount, array &$components, array $price_rule)
    {
        $value = $amount * ($price_rule['value'] / 100);
        $components[$price_rule['price_rule_id']] = array('rule' => $price_rule, 'price' => $value);
        return $amount += $value;
    }
677697
protected function updatePriceRule($price_rule_id)
    {
        if (!$this->isError() && !$this->price_rule->update($price_rule_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
423054
protected function updatePriceRule()
    {
        $this->controlAccess('price_rule_edit');

        if ($this->price_rule->update($this->data_rule['price_rule_id'], $this->getSubmitted())) {
            $this->redirect('admin/sale/price', $this->text('Price rule has been updated'), 'success');
        }

        $this->redirect('', $this->text('Price rule has not been updated'), 'warning');
    }
282946
public function prepareComponentDataProperty($property_name, &$property_info, &$component_data) {
    // Set options.
    $this->prepareComponentDataPropertyCreateOptions($property_name, $property_info);

    // Set a default value.
    $this->setComponentDataPropertyDefault($property_name, $property_info, $component_data);
  }
1130240
protected function setTitleEditPriceRule()
    {
        if (isset($this->data_rule['price_rule_id'])) {
            $title = $this->text('Edit %name', array('%name' => $this->data_rule['name']));
        } else {
            $title = $this->text('Add price rule');
        }

        $this->setTitle($title);
    }
940794
private function validateData($rules, $data) {
		$errors = [];
		foreach ($rules as $field => $rule) {
			$valid = $this->validateField($field, $data, $rule);
			if ($valid !== true) {
				$errors[ $field ] = $valid;
			}
		}
		if (!empty($errors)) {
			throw new ValidateException($errors);
		}

		return true;
	}
475214
protected function prepareComponents(array &$order)
    {
        if (!empty($order['cart']['items'])) {
            foreach ($order['cart']['items'] as $sku => $item) {
                $price = isset($item['total']) ? $item['total'] : null;
                $order['data']['components']['cart']['items'][$sku]['price'] = $price;
            }
        }
    }
1155717
private function setTerminator($dataValue, $dataCounter, $dataBits, $totalDataBits, $maxDataBits)
    {
        if ( $totalDataBits <= ($maxDataBits - 4) ) {
            $dataValue[$dataCounter]  = 0;
            $dataBits[$dataCounter]   = 4;
        }
        else {
            if ( $totalDataBits < $maxDataBits ) {
                $dataValue[$dataCounter]  = 0;
                $dataBits[$dataCounter]   = $maxDataBits - $totalDataBits;
            }
            else {
                if ( $totalDataBits > $maxDataBits ) {
                    throw new OverflowException('QRCode : Overflow error');
                }
            }
        }
        return array($dataValue, $dataBits);
    }
98048
public function total(array $condition, array $data)
    {
        if (!isset($data['cart']['total']) || empty($data['cart']['currency'])) {
            return false;
        }

        $condition_value = explode('|', reset($condition['value']), 2);
        $condition_currency = $data['cart']['currency'];

        if (!empty($condition_value[1])) {
            $condition_currency = $condition_value[1];
        }

        $condition_value[0] = $this->price->amount($condition_value[0], $condition_currency);
        $value = $this->currency->convert($condition_value[0], $condition_currency, $data['cart']['currency']);

        return $this->compare($data['cart']['total'], $value, $condition['operator']);
    }
347848
public static function getValorParcela($total, $parcela, $taxa) {
        if (!is_numeric($total) || $total <= 0) {
            return (false);
        }
        if ((int) $parcela != $parcela) {
            return (false);
        }
        if (!is_numeric($taxa) || $taxa < 0) {
            return (false);
        }

        $taxa = $taxa / 100;

        $denominador = 0;
        if ($parcela > 1) {
            for ($i = 1; $i <= $parcela; $i++) {
                $denominador += 1 / pow(1 + $taxa, $i);
            }
        } else {
            $denominador = 1;
        }

        //echo "<br>";
        return ($total / $denominador);
    }
508464
protected function sumTotalWeight(&$total, array &$item, array $order)
    {
        $product = &$item['product'];

        if ($product['weight_unit'] !== $order['weight_unit']) {

            try {
                $product['weight'] = $this->convertor->convert($product['weight'], $product['weight_unit'], $order['weight_unit']);
            } catch (Exception $ex) {
                return null;
            }

            $product['weight_unit'] = $order['weight_unit'];
        }

        $total += (float) ($product['weight'] * $item['quantity']);
        return null;
    }
1121137
public function setData($totalItems, $currentPage, $itemsPerPage = 12, $maxPages = 10)
    {
        $this->totalItems = $totalItems;
        $this->currentPage = $currentPage;
        $this->itemsPerPage = $itemsPerPage;

//        if ($maxPages < 3) {
//            throw new \InvalidArgumentException('Max pages has to be more than 3.');
//        }
        $this->maxPages = $maxPages;

        $this->numPages = (int) ceil($this->totalItems/$this->itemsPerPage);
    }
199138
public static function make(array $data, array $rules, array $userMessages = [])
    {
        self::$validatorFacade = new ValidatorFacade($userMessages);

        $data = self::prepareData($data);
        $rules = self::prepareRules($rules);

        foreach ($rules as $fieldName => $fieldRules) {
            $fieldName = trim($fieldName);
            $fieldRules = trim($fieldRules);

            if (!$fieldRules) {
                //no rules
                continue;
            }

            $groupedRules = explode('|', $fieldRules);

            foreach ($groupedRules as $concreteRule) {
                $ruleNameParam = explode(':', $concreteRule);
                $ruleName = $ruleNameParam[0];

                //for date/time validators
                if (count($ruleNameParam) >= 2) {
                    $ruleValue = implode(':', array_slice($ruleNameParam, 1));

                    //for other params
                } else {
                    $ruleValue = isset($ruleNameParam[1]) ? $ruleNameParam[1] : '';
                }

                self::$config[BaseRule::CONFIG_DATA] = $data;
                self::$config[BaseRule::CONFIG_FIELD_RULES] = $fieldRules;

                $ruleInstance = RulesFactory::createRule($ruleName, self::$config, [
                    $fieldName,                                        // The field name
                    isset($data[$fieldName]) ? $data[$fieldName] : '', // The provided value
                    $ruleValue,                                        // The rule's value
                ]);

                if (!$ruleInstance->isValid()) {
                    self::$validatorFacade->chooseErrorMessage($ruleInstance);
                }
            }
        }

        return self::$validatorFacade;
    }
1129528
public function startComponent($name, array $data = [], array $more = [])
    {
        if (ob_start()) {
            $this->componentStack[] = $name;
            $this->componentData[$this->currentComponent()] = array_merge($more, $data);
            $this->slots[$this->currentComponent()] = [];
        }
    }
361408
protected function setDataPanelComponentsIndexOrder()
    {
        if (!empty($this->data_order['data']['components'])) {

            $this->setItemOrderCartComponent($this->data_order, $this->price);
            $this->setItemOrderPriceRuleComponent($this->data_order, $this->price, $this->pricerule);
            $this->setItemOrderPaymentComponent($this->data_order, $this->price, $this->payment, $this->order);
            $this->setItemOrderShippingComponent($this->data_order, $this->price, $this->shipping, $this->order);

            ksort($this->data_order['data']['components']);
        }

        $this->setData('pane_components', $this->render('sale/order/panes/components', array('order' => $this->data_order)));
    }
348706
protected function setPrice(array &$data)
    {
        if (!empty($data['price']) && !empty($data['currency'])) {
            $data['price'] = $this->price->amount($data['price'], $data['currency']);
        }
    }