public
getPriceItemsChangedByAttributes
(mixed &$priceP, mixed $attributes, mixed $price, mixed &$item, mixed $ajax = 0)
public function getPriceItemsChangedByAttributes(&$priceP, $attributes, $price, &$item, $ajax = 0)
{
$paramsC = PhocacartUtils::getComponentParameters();
$display_unit_price = $paramsC->get('display_unit_price', 1);
$fullAttributes = array();
// Array of integers only
$thinAttributes = array();
// Array of full objects (full options object)
if ($ajax == 1) {
$fullAttributes = PhocacartAttribute::getAttributeFullValues($attributes);
$thinAttributes = $attributes;
} else {
$fullAttributes = $attributes;
$thinAttributes = PhocacartAttribute::getAttributesSelectedOnly($attributes);
}
// Stock Calculation
// 0 ... Main Product
// 1 ... Product Variations
// 2 ... Advanced Stock Management
// 3 ... Advanced Stock and Price Management
if ($item->stock_calculation == 0 || $item->stock_calculation == 1) {
// Price changes even when stock calculation = main product
if (!empty($fullAttributes)) {
foreach ($fullAttributes as $k => $v) {
if (!empty($v->options)) {
foreach ($v->options as $k2 => $v2) {
// Options:
// a) STANDARD LOAD - we search for default values only to count them
// b) AJAX LOAD - we search for selected values only (in this case attribute array only includes selected)
// so if standard load - at start - we count only default values but when ajax reloads - e.g. some
// options were selected/deselected - we get only array with selected value so we count them all
// EXAMPLE
// Product A has option 1 and it is set as default at standard load - se we count only default_value
// But when user add some new option, e.g. option 2 - we get this array (option1, option2) per ajax
// and we count all the items in this array
// STANDARD LOAD happens at rendering the page (including default values)
// AJAX LOAD happens when user select or deselect attributes of options and ajax will be called
// See: administrator\components\com_phocacart\libraries\phocacart\stock\stock.php
// function getStockItemsChangedByAttributes - similar behaviour
if ($ajax == 1 || $ajax == 0 && isset($v2->default_value) && $v2->default_value == 1) {
if (isset($v2->title) && isset($v2->amount) && isset($v2->operator)) {
$priceA = $price->getPriceItems($v2->amount, $item->taxid, $item->taxrate, $item->taxcalculationtype, $item->taxtitle);
if ($v2->operator == '-') {
$priceP['netto'] -= $priceA['netto'];
$priceP['brutto'] -= $priceA['brutto'];
$priceP['tax'] -= $priceA['tax'];
//$this->correctMinusPrice($priceP);
} else {
if ($v2->operator == '+') {
$priceP['netto'] += $priceA['netto'];
$priceP['brutto'] += $priceA['brutto'];
$priceP['tax'] += $priceA['tax'];
}
}
}
}
}
}
}
}
} else {
if ($item->stock_calculation == 3) {
// Advanced Stock Management
$k = PhocacartProduct::getProductKey((int) $item->id, $thinAttributes);
$dataASM = PhocacartAttribute::getCombinationsDataByKey($k);
if (isset($dataASM['price']) && $dataASM['price'] > 0) {
$priceP = $price->getPriceItems($dataASM['price'], $item->taxid, $item->taxrate, $item->taxcalculationtype, $item->taxtitle);
}
}
}
// Standard Price - changed - we need to update it but only in case the price is not zero
$priceP['nettoformat'] = isset($priceP['netto']) ? $price->getPriceFormat($priceP['netto']) : '';
$priceP['bruttoformat'] = isset($priceP['brutto']) ? $price->getPriceFormat($priceP['brutto']) : '';
$priceP['taxformat'] = isset($priceP['tax']) ? $price->getPriceFormat($priceP['tax']) : '';
// Unit price
$priceP['base'] = '';
$priceP['baseformat'] = '';
if (isset($item->unit_amount) && $item->unit_amount > 0 && isset($item->unit_unit) && (int) $display_unit_price > 0) {
$priceP['base'] = $priceP['brutto'] / $item->unit_amount;
$priceP['baseformat'] = $price->getPriceFormat($priceP['base']) . '/' . $item->unit_unit;
}
}