function renderVariation($variation, $i) { if (!ProductSpecification::model()->findByPk(1)) { return false; } if (!$variation) { $variation = new ProductVariation(); $variation->specification_id = 1; } $str = '<tr> <td>'; $str .= CHtml::dropDownList("Variations[{$i}][specification_id]", $variation->specification_id, CHtml::listData(ProductSpecification::model()->findall(), "id", "title"), array('empty' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][title]", $variation->title); $str .= '</td> <td>'; // Price adjustion $str .= CHtml::dropDownList("Variations[{$i}][sign_price]", $variation->price_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][price_adjustion]", abs($variation->price_adjustion), array('size' => 5)); // Weight adjustion $str .= '</td> <td>'; $str .= CHtml::dropDownList("Variations[{$i}][sign_weight]", $variation->weight_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][weight_adjustion]", abs($variation->weight_adjustion), array('size' => 5)); $str .= '</td> <td>'; for ($j = -10; $j <= 10; $j++) { $positions[$j] = $j; } $str .= CHtml::dropDownList("Variations[{$i}][position]", $variation->position, $positions); $str .= '</td></tr>'; return $str; }
public function actionCreate() { if (!is_numeric($_POST['amount']) || $_POST['amount'] <= 0) { Shop::setFlash(Shop::t('Illegal amount given')); $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id'])); } if (isset($_POST['Variations'])) { foreach ($_POST['Variations'] as $key => $variation) { $specification = ProductSpecification::model()->findByPk($key); if ($specification->required && $variation[0] == '') { Shop::setFlash(Shop::t('Please select a {specification}', array('{specification}' => $specification->title))); $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id'])); } } } $cart = Shop::getCartContent(); // remove potential clutter if (isset($_POST['yt0'])) { unset($_POST['yt0']); } if (isset($_POST['yt1'])) { unset($_POST['yt1']); } $cart[] = $_POST; Shop::setCartcontent($cart); Shop::setFlash(Shop::t('The product has been added to the shopping cart')); $this->redirect(array('//shop/products/index')); }
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 listSpecifications() { if (!($specs = $this->getSpecifications())) { return ''; } $str = '('; foreach ($specs as $key => $specification) { if ($model = ProductSpecification::model()->findByPk($key)) { if ($model->input_type == 'textfield') { $value = $specification[0]; } else { $value = @ProductVariation::model()->findByPk($specification[0])->title; } } $str .= $model->title . ': ' . $value . ', '; } $str = substr($str, 0, -2); $str .= ')'; return $str; }
public function actionCreate() { if (!is_numeric($_POST['amount']) || $_POST['amount'] <= 0) { Shop::setFlash(Shop::t('Illegal amount given')); $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id'])); } if (isset($_POST['Variations'])) { foreach ($_POST['Variations'] as $key => $variation) { $specification = ProductSpecification::model()->findByPk($key); if ($specification->required && $variation[0] == '') { Shop::setFlash(Shop::t('Please select a {specification}', array('{specification}' => $specification->title))); $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id'])); } } } if (isset($_FILES)) { foreach ($_FILES as $variation) { $target = Shop::module()->uploadedImagesFolder . '/' . $variation['name']; if ($variation['tmp_name'] == '') { Shop::setFlash(Shop::t('Please select a image from your hard drive')); $this->redirect(array('//shop/shoppingCart/view')); } if (move_uploaded_file($variation['tmp_name'], $target)) { $_POST['Variations']['image'] = $target; } } } $cart = Shop::getCartContent(); // remove potential clutter if (isset($_POST['yt0'])) { unset($_POST['yt0']); } if (isset($_POST['yt1'])) { unset($_POST['yt1']); } $cart[] = $_POST; Shop::setCartcontent($cart); Shop::setFlash(Shop::t('The product has been added to the shopping cart')); $this->redirect(array('//shop/shoppingCart/view')); }
public function getWeight($variations = null, $amount = 1) { $spec = ProductSpecification::model()->findByPk(Shop::module()->weightSpecificationId); $weight = 0; if ($spec) { $specs = json_decode($this->specifications, true); if (isset($specs[$spec->title])) { $weight += $specs[$spec->title]; } } if ($variations) { foreach ($variations as $key => $variation) { if (is_array($variation)) { $variation = $variation[0]; } if (is_numeric($variation)) { $weight += @ProductVariation::model()->findByPk($variation)->getWeightAdjustion(); } } } return (double) ($weight *= $amount); }
echo Shop::t('Shopping cart'); ?> </h2> <?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 />'; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = ProductSpecification::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }