/** * Rate product * @param integer $id product id */ public function actionRateProduct($id) { $request = Yii::app()->request; if ($request->isAjaxRequest) { $model = ShopProduct::model()->active()->findByPk($id); $mod = 'product'; $rating = (int) $_GET['rating']; if ($model && in_array($rating, array(1, 2, 3, 4, 5))) { $model->votes += 1; $model->rating += $rating; $model->save(); $new = time(); $ratingModel = new RatingModel(); $ratingModel->mid = $id; $ratingModel->modul = $mod; $ratingModel->time = $new; $ratingModel->user_id = Yii::app()->user->getId(); $ratingModel->host = '127.0.0.1'; $ratingModel->save(); $cookie = new CHttpCookie($mod . "-" . $id, $id); $cookie->expire = time() + 60 * 60 * 24 * 60; Yii::app()->request->cookies[$mod . "-" . $id] = $cookie; return $this->widget('ext.rating.Rating', array('pid' => $id, 'rating' => $model->rating, 'votes' => $model->votes)); /* if($model->saveCounters(array( 'votes' => 1, 'rating' => $rating ))){ die('sss'); }else{ die($rating); } */ } } }
/** * Display products by manufacturer * * @param $seo_alias * @throws CHttpException */ public function actionIndex($seo_alias) { $this->model = ShopManufacturer::model()->findByAttributes(array('seo_alias' => $seo_alias)); if (!$this->model) { throw new CHttpException(404, Yii::t('ShopModule.admin', 'NO_FOUND_BRAND')); } $this->pageTitle = $this->model->seo_title ? $this->model->seo_title : $this->model->name; $this->pageKeywords = $this->model->seo_keywords; $this->pageDescription = $this->model->seo_description; $query = new ShopProduct(null); $query->attachBehaviors($query->behaviors()); $query->active(); $query->applyManufacturers($this->model->id); $provider = new ActiveDataProvider($query, array('id' => false, 'pagination' => array('pageSize' => $this->allowedPageLimit[0]))); $this->render('index', array('provider' => $provider)); }
public function testProductDuplicate() { $model = ShopProduct::model()->find(); $duplicator = new SProductsDuplicator(); $clone = $duplicator->duplicateProduct($model); $this->assertEquals($clone->name, $model->name . $duplicator->getSuffix()); }
public function actionIndex() { header('Content-Type: application/json'); $json = array(); $product = ShopProduct::model()->findByPk(Yii::app()->request->getPost('product_id')); if (!$product) { throw new CHttpException(404); } $record = new ProductNotifications(); if (isset($_POST['ProductNotifications'])) { $record->attributes = array('email' => $_POST['ProductNotifications']['email']); $record->product_id = $product->id; if ($record->validate() && $record->hasEmail() === false) { $record->save(); $json['message'] = 'Мы сообщим вам когда товар появится в наличии'; $json['status'] = 'OK'; } else { $json['message'] = 'Ошибка'; $json['status'] = 'ERROR'; } } $json['data'] = $this->renderPartial('_form', array('model' => $record, 'product' => $product), true); echo CJSON::encode($json); // $this->render('_form', array('model' => $record, 'product' => $product)); }
public function testSWishlist() { Yii::import('application.modules.shop.components.SWishList'); $product = ShopProduct::model()->active()->find(); $user = User::model()->find(); $this->assertTrue($user instanceof User); $this->assertTrue($product instanceof $product); $model = new SWishList($user->id); $this->assertTrue(is_array($model->getIds())); // Add right product if $this->assertTrue($model->add($product->id)); // Add wrong product id $this->assertFalse($model->add(time())); // Check if product added $this->assertNotEmpty($model->getIds()); $this->assertTrue($model->count() >= 1); // Check products loading and we have at least one product $products = $model->getProducts(); $this->assertNotEmpty($products); $this->assertTrue($products[0] instanceof ShopProduct); // Clear all $model->clear(); $this->assertEmpty($model->getIds()); // Removing $this->assertTrue($model->add($product->id)); $model->remove($product->id); $this->assertEmpty($model->getIds()); }
public function run() { $cart = Yii::app()->cart; $currency = Yii::app()->currency->active; $items = $cart->getDataWithModels(); $total = ShopProduct::formatPrice(Yii::app()->currency->convert($cart->getTotalPrice())); $this->render($this->skin, array('count' => $cart->countItems(), 'currency' => $currency, 'total' => $total, 'items' => $items)); }
/** * Sum orders total price * * @return string */ public function getOrdersTotalPrice() { $total = 0; foreach ($this->getTodayOrders()->getData() as $order) { $total += $order->full_price; } return ShopProduct::formatPrice($total); }
public function actionRefreshViews() { $model = ShopProduct::model()->updateAll(array('views' => 0), 'views > 1'); if ($model) { $this->redirect(array('index')); } else { $this->redirect(array('index')); } }
/** * @return boolean */ public function afterSave() { $this->order->updateTotalPrice(); $this->order->updateDeliveryPrice(); if ($this->isNewRecord) { $product = ShopProduct::model()->findByPk($this->product_id); $product->decreaseQuantity(); } return parent::afterSave(); }
public function run() { $session = Yii::app()->session->get('views'); if (!empty($session)) { $list = ShopProduct::model()->findAllByPk(array_values($session)); } else { $list = array(); } $this->render($this->skin, array('list' => $list, 'session' => $session)); }
public function run() { $criteria = new CDbCriteria(); // $criteria->condition = '`t`.`manufacturer_id`=67'; $criteria->order = '`t`.`date_create` DESC'; $criteria->scopes = array('active'); $criteria->limit = $this->limit; $provider = new ActiveDataProvider(ShopProduct::model()->cache(Yii::app()->controller->cacheTime), array('criteria' => $criteria, 'pagination' => array('totalItemCount' => $this->limit, 'pageSize' => $this->limit))); $this->render('view', array('provider' => $provider)); }
public function testTitle() { Yii::app()->settings->set('core', array('site_name' => microtime())); $this->open('/'); $this->assertEquals(Yii::app()->settings->get('core', 'site_name'), $this->getTitle()); // Find any active product $product = ShopProduct::model()->active()->find(); $this->assertTrue($product instanceof ShopProduct); // Open product page $this->open(Yii::app()->createUrl('/shop/product/view', array('seo_alias' => $product->seo_alias))); $this->assertEquals($product->name . ' / ' . Yii::app()->settings->get('core', 'site_name'), $this->getTitle()); }
public static function getInstance($id, PDO $pdo) { $stmt = $pdo->prepare("select * from products where id=?"); $result = $stmt->execute(array($id)); $row = $stmt->fetch(); if (empty($row)) { return null; } if ($row['type'] == "book") { $product = new BookProduct($row['title'], $row['firstname'], $row['mainname'], $row['price'], $row['numpages']); } else { if ($row['type'] == "cd") { $product = new CdProduct($row['title'], $row['firstname'], $row['mainname'], $row['price'], $row['playlength']); } else { $product = new ShopProduct($row['title'], $row['firstname'], $row['mainname'], $row['price']); } } $product->setId($row['id']); $product->setDiscount($row['discount']); return $product; }
public function testCompareIsWorkingOk() { $product = ShopProduct::model()->active()->find(); $this->assertTrue($product instanceof ShopProduct); $this->open(Yii::app()->createUrl('/shop/Product/view', array('url' => $product->url))); $this->clickAndWait('css=div.silver_clean.silver_button > button'); $this->assertTrue($this->isTextPresent('Продукт успешно добавлен в список сравнения')); $this->clickAndWait('xpath=//a[contains(.,"Товары на сравнение")]'); $this->assertTrue($this->isTextPresent(str_replace(' ', ' ', $product->name))); $this->clickAndWait('link=Удалить'); $this->assertTrue($this->isTextPresent('Нет результатов')); }
function shop_bk_products_show($options) { include_once XOOPS_ROOT_PATH . '/modules/shop/class/shopproduct.class.php'; include_once XOOPS_ROOT_PATH . '/modules/shop/class/shopfunctions.php'; $db = XoopsDatabaseFactory::getDatabaseConnection(); $limit = $options[2] > 0 ? $options[2] : 5; $ord = $options[0] <= 0 ? ' `created` DESC' : 'RAND()'; $mc = RMUtilities::module_config('shop', 'format'); if ($options[1] != '') { $tp = $db->prefix("shop_products"); $tc = $db->prefix("shop_categories"); $tcp = $db->prefix("shop_catprods"); $sql = "SELECT p.* FROM {$tp} as p, {$tcp} as r WHERE r.cat={$options['1']} AND p.id_product=r.product GROUP BY r.product"; } else { $sql = "SELECT * FROM " . $db->prefix("shop_products"); } $sql .= " ORDER BY {$ord} LIMIT 0,{$limit}"; $result = $db->query($sql); $products = array(); while ($row = $db->fetchArray($result)) { $prod = new ShopProduct(); $prod->assignVars($row); $products[] = array('id' => $prod->id(), 'name' => $prod->getVar('name'), 'link' => $prod->permalink(), 'price' => sprintf($mc, number_format($prod->getVar('price'), 2)), 'type' => $prod->getVar('type') ? __('Digital', 'shop') : 'Product', 'stock' => $prod->getVar('available'), 'image' => $prod->getVar('image')); } $block['products'] = $products; unset($prod, $products, $sql, $result, $row, $ord, $limit, $db); $block['show_image'] = $options[3]; $block['width'] = $options[4]; $block['height'] = $options[5]; $block['display'] = $options[6]; $block['name'] = in_array("name", $options); $block['price'] = in_array("price", $options); $block['type'] = in_array("type", $options); $block['stock'] = in_array("stock", $options); $block['lang_stock'] = __('In stock', 'shop'); $block['lang_nostock'] = __('Out of stock', 'shop'); // Add styles RMTemplate::get()->add_style('blocks.css', 'shop'); return $block; }
public function actionXml() { header('Content-type: application/xml'); $products = ShopProduct::model()->findAll(); $productsList = array(); $productsList['products'] = array(); foreach ($products as $obj) { $productsList['products']['product'][] = array('@attributes' => array('id' => $obj->id), 'name' => $obj->name, 'price' => $obj->price); } $xml = Array2XML::createXML('shop', $productsList); echo $xml->saveXML(); Yii::app()->end(); }
public function afterUninstall() { Yii::app()->settings->clear('shop'); Yii::app()->unintallComponent('currency'); $db = Yii::app()->db; $tablesArray = array(ShopTypeAttribute::model()->tableName(), ShopAttribute::model()->tableName(), ShopAttributeOption::model()->tableName(), ShopAttributeOptionTranslate::model()->tableName(), ShopAttributeTranslate::model()->tableName(), ShopCategory::model()->tableName(), ShopCategoryTranslate::model()->tableName(), ShopCurrency::model()->tableName(), ShopManufacturer::model()->tableName(), ShopManufacturerTranslate::model()->tableName(), ShopProduct::model()->tableName(), ShopProductCategoryRef::model()->tableName(), ShopProductImage::model()->tableName(), ShopProductTranslate::model()->tableName(), ShopProductType::model()->tableName(), ShopProductVariant::model()->tableName(), ShopRelatedProduct::model()->tableName(), ShopSuppliers::model()->tableName(), $db->tablePrefix . 'shop_product_attribute_eav', $db->tablePrefix . 'shop_product_configurable_attributes', $db->tablePrefix . 'shop_product_configurations'); foreach ($tablesArray as $table) { $db->createCommand()->dropTable($table); } CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.product'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.categories'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.manufacturer'), array('traverseSymlinks' => true)); return parent::afterUninstall(); }
/** * @param array $attributes */ public function export(array $attributes) { $limit = 10; $total = ceil(ShopProduct::model()->count() / $limit); $offset = 0; $row = array(); for ($i = 0; $i <= $total; ++$i) { $products = ShopProduct::model()->findAll(array('limit' => $limit, 'offset' => $offset)); foreach ($products as $pid => $p) { foreach ($attributes as $k => $attr) { if ($attr === 'category') { $value = $this->getCategory($p); } elseif ($attr === 'manufacturer') { $value = $this->getManufacturer($p); } elseif ($attr === 'images') { $images = array(); foreach ($p->images as $k => $image) { if ($image->is_main) { $images['image'][] = array('@value' => $image->name, '@attributes' => array('is_main' => true)); } else { $images['image'][] = array('@value' => $image->name); } } $value = $images; } elseif ($attr === 'additionalCategories') { $value = $this->getAdditionalCategories($p); } else { if (substr($attr, 0, 4) === 'eav_') { $v = substr($attr, 4); $row['product'][$pid]['attributes']['attribute'][] = array('@attributes' => array('name' => $v), '@value' => $p->{$attr}); } $value = $p->{$attr}; } if (substr($attr, 0, 4) !== 'eav_') { $row['product'][$pid][$attr] = $value; } } array_push($this->rows, $row); } $offset += $limit; } // print_r($row);die; header('Content-Type: text/html;charset=UTF-8'); header('Content-type: application/xml'); $xml = Array2XML::createXML('products', $row); echo $xml->saveXML(); Yii::app()->end(); $this->proccessOutput(); }
protected function replace($model, $content) { if ($model instanceof Order) { $array['%ORDER_ID%'] = $model->id; $array['%ORDER_KEY%'] = $model->secret_key; $array['%TOTAL_PRICE%'] = ShopProduct::formatPrice(Yii::app()->currency->convert($model->full_price)); $array['%USER_NAME%'] = $model->user_name; $array['%USER_PHONE%'] = $model->user_phone; $array['%USER_EMAIL%'] = $model->user_email; $array['%USER_ADDRESS%'] = $model->user_address; $array['%ORDER_URL%'] = $model->getAbsoluteUrl(); } $array['%CURRENT_CURRENCY%'] = Yii::app()->currency->active->symbol; return CMS::textReplace($content, $array); }
public function applyPricesFilter() { $minPrice = Yii::app()->request->getQuery('min_price'); $maxPrice = Yii::app()->request->getQuery('max_price'); $cm = Yii::app()->currency; if ($cm->active->id !== $cm->main->id && ($minPrice > 0 || $maxPrice > 0)) { $minPrice = $cm->activeToMain($minPrice); $maxPrice = $cm->activeToMain($maxPrice); } if ($minPrice > 0) { $this->query->applyMinPrice($minPrice); } if ($maxPrice > 0) { $this->query->applyMaxPrice($maxPrice); } }
/** * Check creating new comment */ public function testCreateComment() { // Find any active product $product = ShopProduct::model()->active()->find(); $this->assertTrue($product instanceof ShopProduct); $email = '*****@*****.**'; $text = 'this is test comment' . microtime(); // Open product page and post comment $this->open(Yii::app()->createAbsoluteUrl('/shop/product/view', array('seo_alias' => $product->seo_alias))); $this->type('id=Comment_name', 'tester'); $this->type('id=Comment_email', $email); $this->type('id=Comment_text', $text); $this->clickAndWait("//input[@value='Отправить']"); $this->open(Yii::app()->createAbsoluteUrl('/shop/product/view', array('seo_alias' => $product->seo_alias))); $this->assertTrue($this->isTextPresent('Ваш комментарий успешно добавлен. Он будет опубликован после проверки администратором.')); $this->adminLogin(); $this->open('/admin/shop/products/update?id=' . $product->id); $this->click('xpath=//a[contains(.,"Отзывы")]'); $this->assertTrue($this->isTextPresent($email)); $this->assertTrue($this->isTextPresent($text)); }
/** * @static * @param $type * @param $externalId * @param bool $loadModel */ public static function getObject($type, $externalId, $loadModel = true) { $query = Yii::app()->db->createCommand()->select("*")->from('{{exchange1c}}')->where('object_type=:type AND external_id=:externalId', array(':type' => $type, ':externalId' => $externalId))->limit(1)->queryRow(); if ($query === false) { return false; } if ($loadModel === true && $query['object_id']) { switch ($type) { case self::OBJECT_TYPE_CATEGORY: return ShopCategory::model()->findByPk($query['object_id']); break; case self::OBJECT_TYPE_ATTRIBUTE: return ShopAttribute::model()->findByPk($query['object_id']); break; case self::OBJECT_TYPE_PRODUCT: return ShopProduct::model()->findByPk($query['object_id']); break; } } return $query['object_id']; }
public function testCompare() { Yii::import('application.modules.shop.components.SCompareProducts'); $product = ShopProduct::model()->active()->find(); $model = new SCompareProducts(); $this->assertTrue($model->session instanceof ArrayAccess); $this->assertTrue(is_array($model->getIds())); $this->assertTrue($model->add($product->id)); $this->assertFalse($model->add(time())); $this->assertNotEmpty($model->getIds()); $this->assertTrue($model->count() === 1); $products = $model->getProducts(); $this->assertNotEmpty($products); $this->assertTrue($products[0] instanceof ShopProduct); $this->assertTrue(is_array($model->getAttributes())); $model->clear(); $this->assertEmpty($model->getIds()); // Removing $this->assertTrue($model->add($product->id)); $model->remove($product->id); $this->assertEmpty($model->getIds()); }
public function testWishlist() { Yii::import('application.modules.shop.models.wishlist.*'); $wishlist = ShopWishlist::model()->find(); $product = ShopProduct::model()->active()->find(); $this->assertTrue($product instanceof ShopProduct); $this->open(Yii::app()->createUrl('/shop/Product/view', array('url' => $product->url))); $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]'); $this->assertTrue($this->isTextPresent('Авторизация')); $this->type('id=UserLoginForm_username', 'admin'); $this->type('id=UserLoginForm_password', 'admin'); // Click on login button $this->clickAndWait('css=input.blue_button'); $this->open(Yii::app()->createUrl('/shop/Product/view', array('url' => $product->url))); $this->assertTrue($this->isTextPresent('Список желаний')); $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]'); $this->assertTrue($this->isTextPresent('Продукт успешно добавлен в список желаний.')); $this->assertTrue($this->isTextPresent(str_replace(' ', ' ', $product->name))); // View wishlist view $this->open(Yii::app()->createAbsoluteUrl('/shop/wishlist/view', array('key' => $wishlist->key))); $this->assertTrue($this->isTextPresent('Список желаний')); $this->assertTrue($this->isTextPresent($product->name)); }
/** * @param array $attributes */ public function export(array $attributes) { $this->rows[0] = $attributes; foreach ($this->rows[0] as &$v) { if (substr($v, 0, 4) === 'eav_') { $v = substr($v, 4); } } $limit = 10; $total = ceil(ShopProduct::model()->count() / $limit); $offset = 0; for ($i = 0; $i <= $total; ++$i) { $products = ShopProduct::model()->findAll(array('limit' => $limit, 'offset' => $offset)); foreach ($products as $p) { $row = array(); foreach ($attributes as $attr) { if ($attr === 'category') { $value = $this->getCategory($p); } elseif ($attr === 'manufacturer') { $value = $this->getManufacturer($p); } elseif ($attr === 'image') { $value = $p->mainImage ? $p->mainImage->name : ''; } elseif ($attr === 'additionalCategories') { $value = $this->getAdditionalCategories($p); } else { $value = $p->{$attr}; } $row[$attr] = iconv('utf-8', 'cp1251', $value); //append iconv by panix } array_push($this->rows, $row); } $offset += $limit; } $this->proccessOutput(); }
function getSummaryLine() { $base = parent::getSummaryLine(); $base .= " Time:{$this->playLength}"; return $base; }
public function getSummaryLine() { $base = parent::getSummaryLine(); $base .= ": playing time - {$this->getPlayLength()}"; return $base; }
?> </p> <p><?php echo $payment->renderPaymentForm($model); ?> </p> <?php } ?> <?php echo Yii::t('CartModule.default', 'TOTAL_PAY'); ?> : <span class="label label-success"><?php echo ShopProduct::formatPrice(Yii::app()->currency->convert($model->full_price)); ?> </span> <?php echo Yii::app()->currency->active->symbol; ?> </div> </div> </div> <div class="col-md-4"> <div class="panel panel-default"> <div class="panel-heading"><h4><?php echo Yii::t('CartModule.default', 'Состояние заказа'); ?> <span class="label fr label-default" style=""><?php
function getSummaryLine() { $base = parent::getSummaryLine(); $base .= ": page count - {$this->numPages}"; return $base; }
public function ajaxRecount($data) { if (!is_array($data) || empty($data)) { return; } $currentData = $this->getData(); foreach ($data as $index => $quantity) { if ((int) $quantity < 1) { $quantity = 1; } if (isset($currentData[$index])) { $currentData[$index]['quantity'] = (int) $quantity; $data = $currentData[$index]; //print_r($currentData[$index]);die; if ($data['configurable_id']) { $productModel = ShopProduct::model()->findByPk($index); $rowTotal = $data['quantity'] * ShopProduct::calculatePrices($productModel, $data['variants'], $data['configurable_id']); } else { if (Yii::app()->settings->get('shop', 'wholesale')) { $rowTotal = $data['quantity'] * $data['pcs'] * $data['price']; } else { $rowTotal = $data['quantity'] * $data['price']; } } } } $this->session['cart_data'] = $currentData; echo CJSON::encode(array('rowTotal' => ShopProduct::formatPrice(Yii::app()->currency->convert($rowTotal)), 'totalPrice' => ShopProduct::formatPrice(Yii::app()->currency->convert(Yii::app()->cart->getTotalPrice())))); }