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')); }
public function run() { if (!Shop::getCartContent()) { return false; } $this->render('shopping_cart', array('products' => Shop::getCartContent())); return parent::run(); }
public static function getPriceTotal() { $price_total = 0; $tax_total = 0; foreach (Shop::getCartContent() as $product) { $model = Products::model()->findByPk($product['product_id']); $price_total += $model->getPrice(@$product['Variations'], @$product['amount']); $tax_total += $model->getTaxRate(@$product['Variations'], @$product['amount']); } if ($shipping_method = Shop::getShippingMethod()) { $price_total += $shipping_method->price; } $price_total = Shop::t('Price total: {total}', array('{total}' => Shop::priceFormat($price_total))); $price_total .= '<br />'; $price_total .= Shop::t('All prices are including VAT: {vat}', array('{vat}' => Shop::priceFormat($tax_total))) . '<br />'; $price_total .= Shop::t('All prices excluding shipping costs') . '<br />'; return $price_total; }
<?php Shop::register('css/shop.css'); if ($this->id == 'shoppingCart') { $this->renderPartial('/order/waypoint', array('point' => 0)); } if (!isset($products)) { $products = Shop::getCartContent(); } if (!isset($this->breadcrumbs) || $this->breadcrumbs == array()) { $this->breadcrumbs = array(Shop::t('Shop') => array('//shop/products/'), Shop::t('Shopping Cart')); } ?> <h2><?php 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)) {
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'); $order->status = 'new'; 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(); } Shop::mailNotification($order); Shop::flushCart(true); if (Shop::module()->payPalMethod !== false && $order->payment_method == Shop::module()->payPalMethod) { $this->redirect(array(Shop::module()->payPalUrl, 'order_id' => $order->order_id)); } else { $this->redirect(Shop::module()->successAction); } } $this->redirect(Shop::module()->failureAction); } else { Shop::setFlash(Shop::t('Please accept our Terms and Conditions to continue')); $this->redirect(array('//shop/order/create')); } }
<?php $this->renderPartial('/order/waypoint', array('point' => 4)); $this->breadcrumbs = array(Shop::t('Order') => array('index'), Shop::t('New Order')); ?> <?php Shop::renderFlash(); echo CHtml::beginForm(array('//shop/order/confirm')); echo '<h2>' . Shop::t('Confirmation') . '</h2>'; if (Shop::getCartContent() == array()) { return false; } // If the customer is not passed over to the view, we assume the user is // logged in and we fetch the customer data from the customer table if (!isset($customer)) { $customer = Shop::getCustomer(); } $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 />';
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')); }