function getSpecifications($position) { $string = '<table class="specifications">'; foreach ($position->getSpecifications() as $key => $specification) { if ($model = ProductSpecification::model()->findByPk($key)) { if ($model->input_type == 'textfield') { $title = $model->title; $value = $specification[0]; } else { $title = $model->title; $productvariation = ProductVariation::model()->findByPk($specification[0]); if ($productvariation) { $value = $productvariation->title; } else { $value = ''; } } } else { if ($key == 'image') { $title = Shop::t('Filename'); $value = $specification; } } $string .= sprintf('<tr><td>%s</td><td>%s</td></tr>', @$title, @$value); } $string .= '</table>'; return $string; }
public function getPrice() { $price = $this->product->price; if ($this->specifications) { foreach ($this->getSpecifications() as $key => $spec) { $price += @ProductVariation::model()->findByPk(@$spec[0])->price_adjustion; } } return $this->amount * $price; }
public function getPrice($variations = null, $amount = 1) { if ($this->price === null) { $price = (double) Shop::module()->defaultPrice; } else { $price = (double) $this->price; } if ($this->tax) { $price *= $this->tax->percent / 100 + 1; } if ($variations) { foreach ($variations as $key => $variation) { if (is_numeric($variation)) { $price += @ProductVariation::model()->findByPk($variation)->getPriceAdjustion(); } } } return (double) ($price *= $amount); }
public function getPrice($variations = null, $amount = 1) { $price = (double) $this->price; if ($variations) { foreach ($variations as $key => $variation) { $price += @ProductVariation::model()->findByPk($variation[0])->price_adjustion; } } (double) ($price *= $amount); return $price; }
public function getVariations() { return ProductVariation::model()->findAll('product_id = :pid and specification_id = :sid ', array(':pid' => $this->product_id, ':sid' => $this->specification_id)); }
<?php if ($products) { echo '<table cellpadding="0" cellspacing="0" class="shopping_cart">'; printf('<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th style="width:60px;">%s</th><th style="width:60px;">%s</th><th>%s</th></tr>', Shop::t('Image'), Shop::t('Amount'), Shop::t('Product'), Shop::t('Variation'), Shop::t('Price Single'), Shop::t('Sum'), Shop::t('Actions')); //var_dump($products);die(); foreach ($products as $position => $product) { if ($model = Products::model()->findByPk($product['product_id'])) { $variations = ''; if (isset($product['Variations'])) { foreach ($product['Variations'] as $specification => $variation) { if ($specification = ProductSpecification::model()->findByPk($specification)) { if ($specification->input_type == 'textfield') { $variation = $variation[0]; } else { $variation = ProductVariation::model()->findByPk($variation); } if (Shop::module()->allowPositionLiveChange) { if ($specification->input_type == 'select') { $name = sprintf('variation_%s_%s', $position, $specification->id); $variations .= CHtml::radioButtonList($name, $variation->id, ProductVariation::listData($variation->getVariations(), true)); Yii::app()->clientScript->registerScript($name, "\r\n\t\t\t\t\t\t\t\t\t\t\$('[name=\"" . $name . "\"]').click(function(){\r\n\t\t\t\t\t\t\t\t\t\$.ajax({\r\n\t\t\t\t\t\t\t\t\t\t\t'url' : '" . CController::createUrl('//shop/shoppingCart/updateVariation') . "',\r\n\t\t\t\t\t\t\t\t\t\t\t'type' : 'POST',\r\n\t\t\t\t\t\t\t\t\t\t\t'data' : \$(this),\r\n\t\t\t\t\t\t\t\t\t\t\terror: function() {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('#amount_" . $position . "').css('background-color', 'red');\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\tsuccess: function(result) {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').html(\$('.amount_" . $position . "').val());\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_" . $position . "').html(result);\t\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_single_" . $position . "').load('" . $this->createUrl('//shop/shoppingCart/getPriceSingle?position=' . $position) . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_total').load('" . $this->createUrl('//shop/shoppingCart/getPriceTotal') . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.shipping_costs').load('" . $this->createUrl('//shop/shoppingCart/getShippingCosts') . "');\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\t\t\t\t\t\$('input:checked').trigger('click');\r\n\t\t\t\t\t\t\t\t\t\t"); $variations .= '<br />'; } } else { $variations .= $specification . ': ' . $variation . '<br />'; } } $img = CHtml::image(Yii::app()->baseUrl . '/' . $variation, '', array('width' => Shop::module()->imageWidthThumb)); } }
/** * Обновляем информацию о наличии товаров на складе * @param array $one - один товар * @param string $storehouseGuid - GUID склада в 1С откуда получаем остатки */ public function updateProductAvailability($one, $orderCarrierGuid, $storehouseGuid) { //проверяем документ "Перемещение Товаров" или "Приходный Ордер На Товары" $docProduct = $one['@attributes']['type'] == "StandardODATA.Document_ПеремещениеТоваров_Товары_RowType" ? ['type' => false, 'docName' => 'Перемещение Товаров'] : ['type' => true, 'docName' => 'Приходный Ордер На Товары']; $pvar = ProductVariation::model()->find('id_1c = :id_1c', [':id_1c' => $one['d:Номенклатура_Key']]); if (!$pvar) { $this->log1c("При обработке документа '" . $docProduct['docName'] . "', не найден товар с id_1c = {" . $one['d:Ref_Key'] . "}"); continue; } // count balance for pvar $pvarBalance = app()->to1c->productBalance($one['d:Номенклатура_Key'], $one['d:Характеристика_Key'], $orderCarrierGuid, $storehouseGuid); /** * уменьшаем баланс если документ является Перемещением Товаров * прибавляем баланс если документ является Приходным Ордером На Товары */ $in_stock = $pvar->in_stock + ($docProduct['type'] ? (int) $pvarBalance : -(int) $pvarBalance); //update balance in product variation $pvar->edit(['in_stock' => $in_stock], false); // count balance for product $productBalance = $pvar->bproduct->countBalance(); $pvar->bproduct->edit(['in_stock' => $productBalance], false); }