public function relations() { $relations = array('customer' => array(self::BELONGS_TO, 'Customer', 'customer_id'), 'positions' => array(self::HAS_MANY, 'OrderPosition', 'order_id'), 'address' => array(self::BELONGS_TO, 'Address', 'address_id'), 'billingAddress' => array(self::BELONGS_TO, 'BillingAddress', 'billing_address_id'), 'deliveryAddress' => array(self::BELONGS_TO, 'DeliveryAddress', 'delivery_address_id'), 'paymentMethod' => array(self::BELONGS_TO, 'PaymentMethod', 'payment_method'), 'shippingMethod' => array(self::BELONGS_TO, 'ShippingMethod', 'shipping_method')); if (Shop::module()->useWithYum) { $relations['user'] = array(self::HAS_ONE, 'YumUser', 'user_id', 'through' => 'customer'); } return $relations; }
public function actionCreate() { // if some data has been entered before or the user is already logged in, // take the already existing data and prefill the input form if ($model = Shop::getCustomer()) { $address = $model->address; } else { $model = new Customer(); } if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if (isset($_POST['Address'])) { $address = new Address(); $address->attributes = $_POST['Address']; if ($address->save()) { $model->address_id = $address->id; } } if (!Yii::app()->user->isGuest) { $model->user_id = Yii::app()->user->id; } $model->validate(); if (Shop::module()->useWithYum && isset($_POST['register']) && ($_POST['register'] = true)) { if (isset($_POST['Customer']['password']) && isset($_POST['Customer']['passwordRepeat'])) { if ($_POST['Customer']['password'] != $_POST['Customer']['passwordRepeat']) { $model->addError('password', Shop::t('Passwords do not match')); } else { if ($_POST['Customer']['password'] == '') { $model->addError('password', Shop::t('Password is empty')); } else { $user = new YumUser(); $profile = new YumProfile(); $profile->attributes = $_POST['Customer']; $profile->attributes = $_POST['Address']; if ($user->register(strtr($model->email, array('@' => '_', '.' => '_')), $_POST['Customer']['password'], $profile)) { $user->status = YumUser::STATUS_ACTIVE; $user->save(false, array('status')); $model->user_id = $user->id; Shop::setFlash(Shop::t('Successfully registered user')); } else { $model->addErrors($user->getErrors()); $model->addErrors($profile->getErrors()); Shop::setFlash(Shop::t('Error while registering user')); } } } } } if (!$model->hasErrors()) { if ($model->save()) { Yii::app()->user->setState('customer_id', $model->customer_id); $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id)); } } } $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address())); }
public static function priceFormat($price) { $price = sprintf('%.2f', $price); if (Yii::app()->language == 'de') { $price = str_replace('.', ',', $price); } $price .= ' ' . Shop::module()->currencySymbol; return $price; }
/** * Manages all models. */ public function actionAdmin() { $this->layout = Shop::module()->adminLayout; $model = new ShippingMethod('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['ShippingMethod'])) { $model->attributes = $_GET['ShippingMethod']; } $this->render('admin', array('model' => $model)); }
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(''); $pdf->SetTitle(''); $pdf->SetSubject(''); $pdf->SetKeywords(''); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 006', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- // set font $pdf->SetFont('dejavusans', '', 14); // add a page $pdf->AddPage(); $html = $this->renderPartial(Shop::module()->slipView, array('model' => $model), true, false); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->lastPage(); $pdf->Output('slip.pdf', 'I');
$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)); } } printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td class="text-right price_single_' . $position . '">%s</td><td class="text-right price_' . $position . '">%s</td><td>%s</td></tr>', $img, CHtml::textField('amount_' . $position, $product['amount'], array('size' => 4, 'class' => 'amount_' . $position)), $model->title, $variations, Shop::priceFormat($model->getPrice($product['Variations'])), Shop::priceFormat($model->getPrice($product['Variations'], $product['amount'])), CHtml::link(Shop::t('Remove'), array('//shop/shoppingCart/delete', 'id' => $position), array('confirm' => Shop::t('Are you sure?')))); Yii::app()->clientScript->registerScript('amount_' . $position, "\r\n\t\t\t\t\t\$('.amount_" . $position . "').keyup(function() {\r\n\t\t\t\t\t\t\$.ajax({\r\n\t\t\t\t\t\t\turl:'" . $this->createUrl('//shop/shoppingCart/updateAmount') . "',\r\n\t\t\t\t\t\t\tdata: \$('#amount_" . $position . "'),\r\n\t\t\t\t\t\t\tsuccess: function(result) {\r\n\t\t\t\t\t\t\t\$('.amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').html(\$('.amount_" . $position . "').val());\r\n\t\t\t\t\t\t\t\$('.price_" . $position . "').html(result);\t\r\n\t\t\t\t\t\t\t\$('.price_total').load('" . $this->createUrl('//shop/shoppingCart/getPriceTotal') . "');\r\n\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},\r\n\t\t\t\t\t\t\terror: function() {\r\n\t\t\t\t\t\t\t\$('#amount_" . $position . "').css('background-color', 'red');\r\n\t\t\t\t\t\t\t},\r\n\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t\t\t"); } } if ($shippingMethod = Shop::getShippingMethod()) { printf('<tr> <td></td> <td>1</td> <td>%s</td> <td></td> <td class="text-right shipping_costs">%s</td> <td class="text-right shipping_costs">%s</td> <td>%s</td></tr>', Shop::t('Shipping costs'), Shop::priceFormat($shippingMethod->getPrice()), Shop::priceFormat($shippingMethod->getPrice()), CHtml::link(Shop::t('edit'), array('//shop/shippingMethod/choose')));
$positions[$j] = $j; } $str .= CHtml::dropDownList("Variations[{$i}][position]", $variation->position, $positions); $str .= '</td></tr>'; return $str; } ?> <div class="form"> <?php if (Shop::module()->rtepath !== false) { Yii::app()->clientScript->registerScriptFile(Shop::module()->rtepath, CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript("ckeditor", "\$('#Products_description').ckeditor();"); } if (Shop::module()->rteadapter !== false) { Yii::app()->clientScript->registerScriptFile(Shop::module()->rteadapter, CClientScript::POS_HEAD); } $form = $this->beginWidget('CActiveForm', array('id' => 'products-form', 'enableAjaxValidation' => true, 'htmlOptions' => array('enctype' => $model->hasUpload() ? 'multipart/form-data' : 'x-www-form-urlencoded'))); ?> <?php echo $form->errorSummary($model); ?> <fieldset> <legend> <?php echo Shop::t('Article Information'); ?> </legend> <div class="row">
<?php if (!isset($this->breadcrumbs)) { $this->breadcrumbs = array(Shop::t('Shop'), Shop::t('already registered')); } ?> <?php echo CHtml::link(Shop::t('I am a new customer'), array('//shop/order/create', 'customer' => 'new')); echo '<br />'; echo CHtml::link(Shop::t('I am a customer already'), Shop::module()->loginUrl);
<p> <?php echo Shop::t('Choose your delivery date'); ?> </p> <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'Order[delivery_date]', 'value' => date(Shop::module()->dateFormat, time() + 3 * 86400), 'language' => Yii::app()->language, 'options' => array('showAnim' => 'fold', 'changeYear' => true, 'changeMonth' => true, 'closeText' => Shop::t('Apply'), 'minDate' => +3))); ?> <p> <?php echo Shop::t('Choose your preferred time'); ?> </p> <?php echo CHtml::dropDownList('Order[delivery_time]', 0, Shop::module()->deliveryTimes); ?> <?php } ?> <?php Yii::app()->clientScript->registerScript('toggle', "\r\n\t\tif(\$('#toggle_delivery').attr('checked'))\r\n\t\t\$('#delivery_information').show();\r\n\t\t\$('#toggle_delivery').click(function() { \r\n\t\t\t\$('#delivery_information').toggle(500);\r\n\t\t\t});\r\n\t\t"); ?> <div class="row buttons"> <?php echo CHtml::submitButton(Shop::t('Continue'), array('id' => 'next')); ?> </div>
echo $form->textField($address, 'city', array('size' => 32, 'maxlength' => 45)); ?> <?php echo $form->error($address, 'city'); ?> </div> <div class="row"> <?php echo Shop::getCountryChooser($form, $address); ?> </div> <?php if (Shop::module()->useWithYum && $customer->isNewRecord) { ?> <?php echo CHtml::label(Shop::t('Register an account'), 'register'); ?> <?php echo CHtml::checkbox('register', true); ?> <div class="registration"> <?php echo Shop::t('Enter a password to create an user account'); ?> <div class="row"> <?php
<h2> <?php echo Shop::t('Order'); ?> #<?php echo $model->order_id; ?> </h2> <h3> <?php echo Shop::t('Ordering Info'); ?> </h3> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('order_id', 'customer_id', 'comment', array('label' => Shop::t('Ordering Date'), 'value' => date('d. m. Y G:i', $model->ordering_date)), array('label' => Shop::t('Status'), 'value' => Shop::t($model->status))))); if (Shop::module()->useWithYum && Yii::app()->user->isAdmin() || Yii::app()->user->id == 1) { echo CHtml::link(Shop::t('Update order status'), array('//shop/order/update', 'id' => $model->order_id)); } ?> <h3> <?php echo Shop::t('Customer Info'); ?> </h3> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model->customer, 'attributes' => array('email'))); ?> <div class="summary_delivery_address"> <h3> <?php
} $this->breadcrumbs = array(Yii::t('ShopModule.shop', 'Customers') => array('index'), Yii::t('ShopModule.shop', 'Register as a new Customer')); ?> <h2> <?php echo Shop::t('Please enter your Customer information'); ?> </h2> <h3> <?php echo Shop::t('I am a registered customer'); ?> </h3> <p> <?php echo Shop::t('Click {link} if you are already registered', array('{link}' => CHtml::link(Shop::t('here'), Shop::module()->loginUrl))); ?> </p> <hr /> <h3><?php echo Shop::t('I am a new customer'); ?> </h3> <p><?php echo Shop::t('Registration information'); ?> </p> <p><strong> <?php echo Shop::t('Please enter your Customer information'); ?>
$this->renderPartial('application.modules.shop.views.customer.view', array('model' => $customer, 'hideAddress' => true, 'hideEmail' => true)); echo '<br />'; echo '<hr />'; echo '<p>'; $shipping = ShippingMethod::model()->find('id = :id', array(':id' => Yii::app()->user->getState('shipping_method'))); echo '<strong>' . Shop::t('Shipping Method') . ': </strong>' . ' ' . $shipping->title . ' (' . $shipping->description . ')'; echo '<br />'; echo CHtml::link(Shop::t('Edit shipping method'), array('//shop/shippingMethod/choose', 'order' => true)); echo '</p>'; echo '<p>'; $payment = PaymentMethod::model()->findByPk(Yii::app()->user->getState('payment_method')); echo '<strong>' . Shop::t('Payment method') . ': </strong>' . ' ' . $payment->title . ' (' . $payment->description . ')'; echo '<br />'; echo CHtml::link(Shop::t('Edit payment method'), array('//shop/paymentMethod/choose', 'order' => true)); echo '</p>'; echo '<hr />'; $this->renderPartial('application.modules.shop.views.shoppingCart.view'); echo '<h3>' . Shop::t('Please add additional comments to the order here') . '</h3>'; echo CHtml::textArea('Order[Comment]', @Yii::app()->user->getState('order_comment'), array('class' => 'order_comment')); echo '<br /><br />'; echo '<hr />'; $this->renderPartial(Shop::module()->termsView); ?> <div class="row buttons"> <?php echo CHtml::submitButton(Shop::t('Confirm Order'), array('id' => 'next'), array('//shop/order/confirm')); ?> </div> <?php echo CHtml::endForm();
<?php if ($this->breadcrumbs) { $this->breadcrumbs = array(Shop::t('Orders') => array('admin'), Shop::t('Manage')); } ?> <h2> <?php echo Shop::t('Orders'); ?> </h2> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'order-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('order_id', 'customer.address.firstname', 'customer.address.lastname', array('name' => 'ordering_date', 'value' => 'date(Shop::module()->dateFormat, $data->ordering_date)', 'filter' => false), array('name' => 'delivery_date', 'value' => 'date(Shop::module()->dateFormat, $data->delivery_date)', 'filter' => false, 'visible' => Shop::module()->deliveryTimes !== false), array('name' => 'delivery_time', 'value' => '$data->getDeliveryTime()', 'filter' => Shop::module()->deliveryTimes, 'visible' => Shop::module()->deliveryTimes !== false), array('name' => 'status', 'value' => 'Shop::t($data->status)', 'filter' => Order::statusOptions()), array('class' => 'CButtonColumn', 'template' => '{view}'))));
public function beforeAction($action) { $this->layout = Shop::module()->layout; return parent::beforeAction($action); }
?> </table> </td> </tr> </table> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td nowrap> <table width="100%" border="0" cellpadding="3" cellspacing="0"> <tr> <td nowrap width="100%" style="border-right: 2px solid; border-bottom: 2px solid; border-color: #ffffff;"><div align="right"><font size="1" face="Arial, Helvetica, sans-serif"><?php echo Shop::t('Total value'); ?> <?php echo Shop::priceFormat($model->getTotalPrice()); ?> </font></div></td> </tr> </table></td> </tr> </table> <br /> <br /> <br /> <?php $this->renderPartial(Shop::module()->footerView); ?> </div>
public function actionConfirm() { Yii::app()->user->setState('order_comment', @$_POST['Order']['Comment']); if (isset($_POST['accept_terms']) && $_POST['accept_terms'] == 1) { $order = new Order(); $customer = Shop::getCustomer(); $cart = Shop::getCartContent(); $order->customer_id = $customer->customer_id; $address = new DeliveryAddress(); if ($customer->deliveryAddress) { $address->attributes = $customer->deliveryAddress->attributes; } else { $address->attributes = $customer->address->attributes; } $address->save(); $order->delivery_address_id = $address->id; $address = new BillingAddress(); if ($customer->billingAddress) { $address->attributes = $customer->billingAddress->attributes; } else { $address->attributes = $customer->address->attributes; } $address->save(); $order->billing_address_id = $address->id; $order->ordering_date = time(); $order->payment_method = Yii::app()->user->getState('payment_method'); $order->shipping_method = Yii::app()->user->getState('shipping_method'); $order->comment = Yii::app()->user->getState('order_comment'); if ($order->save()) { foreach ($cart as $position => $product) { $position = new OrderPosition(); $position->order_id = $order->order_id; $position->product_id = $product['product_id']; $position->amount = $product['amount']; $position->specifications = @json_encode($product['Variations']); $position->save(); Yii::app()->user->setState('cart', array()); Yii::app()->user->setState('shipping_method', null); Yii::app()->user->setState('payment_method', null); Yii::app()->user->setState('order_comment', null); } Shop::mailNotification($order); $this->redirect(Shop::module()->successAction); } else { $this->redirect(Shop::module()->failureAction); } } else { Shop::setFlash(Shop::t('Please accept our Terms and Conditions to continue')); $this->redirect(array('//shop/order/create')); } }
public function tableName() { return Shop::module()->productsTable; }
/** * Manages all models. */ public function actionAdmin() { $this->layout = Shop::module()->adminLayout; $model = new Products('search'); if (isset($_GET['Products'])) { $model->attributes = $_GET['Products']; } $this->render('admin', array('model' => $model)); }
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 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')); }