public function execute() { $this->setLayout(new shopFrontendLayout()); $product_model = new shopProductModel(); $product = $product_model->getByField('url', waRequest::param('product_url')); if (!$product) { throw new waException('Product not found', 404); } $product = new shopProduct($product); $this->getBreadcrumbs($product, true); $reviews_model = new shopProductReviewsModel(); $reviews = $reviews_model->getFullTree($product['id'], 0, null, 'datetime DESC', array('escape' => true)); $config = wa()->getConfig(); $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'reviews_count' => $reviews_model->count($product['id']), 'reply_allowed' => true, 'auth_adapters' => $adapters = wa()->getAuthAdapters(), 'request_captcha' => $config->getGeneralSettings('require_captcha'), 'require_authorization' => $config->getGeneralSettings('require_authorization'))); $storage = wa()->getStorage(); $current_auth = $storage->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : shopProductReviewsModel::AUTH_GUEST; $this->view->assign('current_auth_source', $current_auth_source); $this->view->assign('current_auth', $current_auth, true); /** * @event frontend_product * @param shopProduct $product * @return array[string][string]string $return[%plugin_id%]['menu'] html output * @return array[string][string]string $return[%plugin_id%]['cart'] html output * @return array[string][string]string $return[%plugin_id%]['block_aux'] html output * @return array[string][string]string $return[%plugin_id%]['block'] html output */ $this->view->assign('frontend_product', wa()->event('frontend_product', $product, array('menu', 'cart', 'block_aux', 'block'))); $this->setThemeTemplate('reviews.html'); }
private function getData($product_id) { $parent_id = $this->getParentId(); $rate = waRequest::post('rate', null, waRequest::TYPE_INT); if (!$product_id) { $parent_comment = $this->model->getById($parent_id); $product_id = $parent_comment['product_id']; } $text = waRequest::post('text', null, waRequest::TYPE_STRING_TRIM); $title = waRequest::post('title', null, waRequest::TYPE_STRING_TRIM); return array('product_id' => $product_id, 'parent_id' => $parent_id, 'text' => $text, 'title' => $title, 'rate' => $rate && !$parent_id ? $rate : null, 'datetime' => date('Y-m-d H:i:s'), 'status' => shopProductReviewsModel::STATUS_PUBLISHED) + $this->getContactData(); }
public function execute() { $review_id = waRequest::post('review_id', null, waRequest::TYPE_INT); if (!$review_id) { throw new waException("Unknown review id"); } $status = waRequest::post('status', '', waRequest::TYPE_STRING_TRIM); if ($status == shopProductReviewsModel::STATUS_DELETED || $status == shopProductReviewsModel::STATUS_PUBLISHED) { $product_reviews_model = new shopProductReviewsModel(); $product_reviews_model->changeStatus($review_id, $status); } }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); $product_model = new shopProductModel(); $product = $product_model->getById($id); if (!$product) { throw new waException(_w("Unkown product")); } $offset = waRequest::get('offset', 0, waRequest::TYPE_INT); $total_count = waRequest::get('total_count', null, waRequest::TYPE_INT); $lazy = waRequest::get('lazy'); $order = waRequest::get('order', 'default', waRequest::TYPE_STRING_TRIM); $order = isset($this->orders[$order]) ? $order : 'default'; $product_reviews_model = new shopProductReviewsModel(); $reviews = $product_reviews_model->getFullTree($id, $offset, $this->getConfig()->getOption('reviews_per_page_product'), $this->orders[$order], array('is_new' => true)); $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'offset' => $offset, 'total_count' => $total_count ? $total_count : $product_reviews_model->count($id), 'reply_allowed' => true, 'lazy' => $lazy, 'current_author' => shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()), 'count' => count($reviews), 'id' => $id, 'order' => $order, 'sidebar_counters' => array('new' => $product_reviews_model->countNew()))); }
/** * @param array $params deleted contact_id * @return array|void */ public function execute(&$params) { waLocale::loadByDomain('shop'); // TODO: take a look to other models related with contacts $links = array(); $product_reviews_model = new shopProductReviewsModel(); $order_model = new shopOrderModel(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $product_reviews_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('shop', 'Reviews author'), 'links_number' => $count); } if ($count = $order_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('shop', 'Order customer'), 'links_number' => $count); } } return $links; }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute(&$params) { $contact_ids = $params; // We need some info about (not yet) deleted contacts to save into order params. // The idea is to pretend that orders were created by guests with no auth. $c = new waContactsCollection('id/' . implode(',', $contact_ids)); $contacts = $c->getContacts('name,phone,email'); foreach ($contacts as &$contact) { if (is_array($contact['phone'])) { $phone = reset($contact['phone']); if (is_array($phone)) { if (isset($phone['value'])) { $phone = $phone['value']; } else { $phone = ''; } } $contact['phone'] = $phone; } if (is_array($contact['email'])) { $email = reset($contact['email']); $contact['email'] = $email; } } $order_model = new shopOrderModel(); $order_params_model = new shopOrderParamsModel(); $product_reviews_model = new shopProductReviewsModel(); foreach ($contacts as $contact) { // Insert customer info into params of their orders $order_ids = array_keys($order_model->select('id')->where('contact_id=:contact_id', array('contact_id' => $contact['id']))->fetchAll('id')); $order_params_model->set($order_ids, $this->extractContactInfo($contact), false); // Insert contact name into their reviews $product_reviews_model->updateByField('contact_id', $contact['id'], array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null)); } // Update orders as if they were created by guests with no auth $order_model->updateByField('contact_id', $contact_ids, array('contact_id' => null)); // Forget the customer $scm = new shopCustomerModel(); $scm->deleteById($contact_ids); // Forget that this user created coupons $coupm = new shopCouponModel(); $coupm->updateByField('create_contact_id', $contact_ids, array('create_contact_id' => 0)); // !!! TODO: take a look to other models related with contacts }
protected function getReqiestData() { $product_id = waRequest::post('product_id', null, waRequest::TYPE_INT); $parent_id = waRequest::post('parent_id', 0, waRequest::TYPE_INT); $rate = 0; if (wa()->getEnv() == 'backend' && !$parent_id) { throw new waException(_w("Writing a review to product is available just on frontend")); } if (!$product_id && !$parent_id) { throw new waException("Can't add comment: unknown product for review or review for reply"); } if (!$product_id) { $parent_comment = $this->product_reviews_model->getById($parent_id); $product_id = $parent_comment['product_id']; $rate = waRequest::post('rate', 0, waRequest::TYPE_INT); } $text = waRequest::post('text', null, waRequest::TYPE_STRING_TRIM); $title = waRequest::post('title', null, waRequest::TYPE_STRING_TRIM); return array('product_id' => $product_id, 'parent_id' => $parent_id, 'title' => $title, 'text' => $text, 'rate' => $rate, 'contact_id' => $this->author->getId(), 'auth_provider' => shopProductReviewsModel::AUTH_USER, 'datetime' => date('Y-m-d H:i:s'), 'status' => shopProductReviewsModel::STATUS_PUBLISHED); }
public function execute() { $product_id = $this->get('product_id', true); $product_model = new shopProductModel(); $product = $product_model->getById($product_id); if (!$product) { throw new waAPIException('invalid_param', 'Product not found', 404); } $parent_id = waRequest::get('parent_id'); $reviews_model = new shopProductReviewsModel(); $reviews = $reviews_model->getTree($parent_id, waRequest::get('depth', null, 'int'), 'product_id = ' . (int) $product_id); $stack = array(); $result = array(); foreach ($reviews as $r) { $r['comments'] = array(); // Number of stack items $l = count($stack); // Check if we're dealing with different levels while ($l > 0 && $stack[$l - 1]['depth'] >= $r['depth']) { array_pop($stack); $l--; } // Stack is empty (we are inspecting the root) if ($l == 0) { // Assigning the root node $i = count($result); $result[$i] = $r; $stack[] =& $result[$i]; } else { // Add node to parent $i = count($stack[$l - 1]['comments']); $stack[$l - 1]['comments'][$i] = $r; $stack[] =& $stack[$l - 1]['comments'][$i]; } } $this->response = $result; $this->response['_element'] = 'review'; }
public function execute() { if (!$this->getUser()->isAdmin('shop') && !wa()->getUser()->getRights('shop', 'type.%')) { throw new waRightsException('Access denied'); } $this->setLayout(new shopBackendLayout()); $this->getResponse()->setTitle(_w('Products')); $this->view->assign('categories', new shopCategories()); $tag_model = new shopTagModel(); $this->view->assign('cloud', $tag_model->getCloud()); $set_model = new shopSetModel(); $this->view->assign('sets', $set_model->getAll()); $collapse_types = wa()->getUser()->getSettings('shop', 'collapse_types'); if (empty($collapse_types)) { $type_model = new shopTypeModel(); $this->view->assign('types', $type_model->getTypes()); } else { $this->view->assign('types', false); } $product_model = new shopProductModel(); $this->view->assign('count_all', $product_model->countAll()); $review_model = new shopProductReviewsModel(); $this->view->assign('count_reviews', array('all' => $review_model->count(null, false), 'new' => $review_model->countNew(true))); $product_services = new shopServiceModel(); $this->view->assign('count_services', $product_services->countAll()); $config = $this->getConfig(); $this->view->assign('default_view', $config->getOption('products_default_view')); /* * @event backend_products * @return array[string]array $return[%plugin_id%] array of html output * @return array[string][string]string $return[%plugin_id%]['sidebar_top_li'] html output * @return array[string][string]string $return[%plugin_id%]['sidebar_section'] html output */ $this->view->assign('backend_products', wa()->event('backend_products')); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('lang', substr(wa()->getLocale(), 0, 2)); }
public function execute() { $offset = waRequest::get('offset', 0, waRequest::TYPE_INT); $total_count = waRequest::get('total_count', null, waRequest::TYPE_INT); $lazy = waRequest::get('lazy', false, waRequest::TYPE_INT); $product_reivews_model = new shopProductReviewsModel(); $reviews_per_page = $this->getConfig()->getOption('reviews_per_page_total'); /* $reviews = $product_reivews_model->getList( $offset, $reviews_per_page, array('is_new' => true) ); */ $reviews = $product_reivews_model->getList('*,is_new,contact,product', array('offset' => $offset, 'limit' => $reviews_per_page)); // TODO: move to model $product_ids = array(); foreach ($reviews as $review) { $product_ids[] = $review['product_id']; } $product_ids = array_unique($product_ids); $product_model = new shopProductModel(); $products = $product_model->getByField('id', $product_ids, 'id'); $image_size = wa()->getConfig()->getImageSize('crop_small'); foreach ($reviews as &$review) { if (isset($products[$review['product_id']])) { $product = $products[$review['product_id']]; $review['product_name'] = $product['name']; if ($product['image_id']) { $review['product_url_crop_small'] = shopImage::getUrl(array('id' => $product['image_id'], 'product_id' => $product['id'], 'ext' => $product['ext']), $image_size); } else { $review['product_url_crop_small'] = null; } } } $this->view->assign(array('total_count' => $total_count ? $total_count : $product_reivews_model->countAll(), 'count' => count($reviews), 'offset' => $offset, 'reviews' => $reviews, 'current_author' => shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()), 'reply_allowed' => true, 'lazy' => $lazy, 'sidebar_counters' => array('new' => $product_reivews_model->countNew(!$offset)))); }
public function execute() { $id = waRequest::request('id', null, waRequest::TYPE_INT); $scm = new shopCustomerModel(); $customer = $scm->getById($id); try { $contact = new waContact($id); $contact->getName(); } catch (waException $e) { // !!! What to do when shop_customer exists, but no wa_contact found? throw $e; } $ccsm = new waContactCategoriesModel(); $contact_categories = $ccsm->getContactCategories($id); $contacts_url = wa()->getAppUrl('contacts'); // Info above tabs $top = array(); foreach (array('email', 'phone', 'im') as $f) { if ($v = $contact->get($f, 'top,html')) { $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v); } } // Get photo $photo = $contact->get('photo'); $config = $this->getConfig(); $use_gravatar = $config->getGeneralSettings('use_gravatar'); $gravatar_default = $config->getGeneralSettings('gravatar_default'); if (!$photo && $use_gravatar) { $photo = shopHelper::getGravatar($contact->get('email', 'default'), 96, $gravatar_default); } else { $photo = $contact->getPhoto(96); } $contact['photo'] = $photo; // Customer orders $im = new shopOrderItemsModel(); $orders_collection = new shopOrdersCollection('search/contact_id=' . $id); $total_count = $orders_collection->count(); $orders = $orders_collection->getOrders('*,items,params', 0, $total_count); shopHelper::workupOrders($orders); foreach ($orders as &$o) { $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']); $o['shipping_name'] = ifset($o['params']['shipping_name'], ''); $o['payment_name'] = ifset($o['params']['payment_name'], ''); // !!! TODO: shipping and payment icons } // Customer reviews $prm = new shopProductReviewsModel(); $reviews = $prm->getList('*,is_new,product', array('escape' => false, 'where' => array('contact_id' => $id), 'limit' => false)); // Customer affiliate transactions history $atm = new shopAffiliateTransactionModel(); $affiliate_history = $atm->getByContact($id); $this->view->assign('top', $top); $this->view->assign('orders', $orders); $this->view->assign('reviews', $reviews); $this->view->assign('contact', $contact); $this->view->assign('customer', $customer); $this->view->assign('contacts_url', $contacts_url); $this->view->assign('affiliate_history', $affiliate_history); $this->view->assign('contact_categories', $contact_categories); $this->view->assign('def_cur_tmpl', str_replace('0', '%s', waCurrency::format('%{s}', 0, wa()->getConfig()->getCurrency()))); $this->view->assign('point_rate', str_replace(',', '.', (double) str_replace(',', '.', wa()->getSetting('affiliate_usage_rate')))); $fields = waContactFields::getAll('person'); if (isset($fields['name'])) { unset($fields['name']); } $this->view->assign('fields', $fields); $this->view->assign('orders_default_view', $config->getOption('orders_default_view')); /* * @event backend_customer * @return array[string]array $return[%plugin_id%] array of html output * @return array[string][string]string $return[%plugin_id%]['info_section'] html output * @return array[string][string]string $return[%plugin_id%]['name_suffix'] html output * @return array[string][string]string $return[%plugin_id%]['header'] html output * @return array[string][string]string $return[%plugin_id%]['action_link'] html output */ $this->view->assign('backend_customer', wa()->event('backend_customer', $customer)); }
protected function getReviewsTotalCount($product_id) { return $this->reviews_model->count($product_id, true); }
public function execute() { $product = new shopProduct(waRequest::get('id', 0, waRequest::TYPE_INT)); if (!$product->id) { if (waRequest::get('id') == 'new') { $product->name = ''; $product->id = 'new'; $product->status = 1; } else { throw new waException("Product not found", 404); } } $counters = array('reviews' => 0, 'images' => 0, 'pages' => 0, 'services' => 0); $sidebar_counters = array(); $config = $this->getConfig(); /** * @var shopConfig $config */ #load product types $type_model = new shopTypeModel(); $product_types = $type_model->getTypes(true); $product_types_count = count($product_types); if (intval($product->id)) { # 1 fill extra product data # 1.1 fill product reviews $product_reviews_model = new shopProductReviewsModel(); $product['reviews'] = $product_reviews_model->getReviews($product->id, 0, $config->getOption('reviews_per_page_product'), 'datetime DESC', array('is_new' => true)); $counters['reviews'] = $product_reviews_model->count($product->id); $sidebar_counters['reviews'] = array('new' => $product_reviews_model->countNew()); $counters['images'] = count($product['images']); $product_pages_model = new shopProductPagesModel(); $counters['pages'] = $product_pages_model->count($product->id); $product_services_model = new shopProductServicesModel(); $counters['services'] = $product_services_model->countServices($product->id); $product_stocks_log_model = new shopProductStocksLogModel(); $counters['stocks_log'] = $product_stocks_log_model->countByField('product_id', $product->id); $this->view->assign('edit_rights', $product->checkRights()); } else { $counters += array_fill_keys(array('images', 'services', 'pages', 'reviews'), 0); $product['images'] = array(); reset($product_types); $product->type_id = 0; if ($product_types_count) { if (!$product_types) { throw new waRightsException(_w("Access denied")); } else { reset($product_types); $product->type_id = key($product_types); } } elseif (!$product->checkRights()) { throw new waRightsException(_w("Access denied")); } $this->view->assign('edit_rights', true); $product['skus'] = array('-1' => array('id' => -1, 'sku' => '', 'available' => 1, 'name' => '', 'price' => 0.0, 'purchase_price' => 0.0, 'count' => null, 'stock' => array(), 'virtual' => 0)); $product->currency = $config->getCurrency(); } $this->assignReportsData($product); $stock_model = new shopStockModel(); $taxes_mode = new shopTaxModel(); $this->view->assign('stocks', $stock_model->getAll('id')); $this->view->assign(array('use_product_currency' => wa()->getSetting('use_product_currency'), 'currencies' => $this->getCurrencies(), 'primary_currency' => $config->getCurrency(), 'taxes' => $taxes_mode->getAll())); $category_model = new shopCategoryModel(); $categories = $category_model->getFullTree('id, name, depth, url, full_url, parent_id', true); $frontend_urls = array(); if (intval($product->id)) { $routing = wa()->getRouting(); $domain_routes = $routing->getByApp($this->getAppId()); foreach ($domain_routes as $domain => $routes) { foreach ($routes as $r) { if (!empty($r['private'])) { continue; } if (empty($r['type_id']) || in_array($product->type_id, (array) $r['type_id'])) { $routing->setRoute($r, $domain); $params = array('product_url' => $product->url); if ($product->category_id && isset($categories[$product->category_id])) { if (!empty($r['url_type']) && $r['url_type'] == 1) { $params['category_url'] = $categories[$product->category_id]['url']; } else { $params['category_url'] = $categories[$product->category_id]['full_url']; } } $frontend_url = $routing->getUrl('/frontend/product', $params, true); $frontend_urls[] = array('url' => $frontend_url); } } } } else { $frontend_urls[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => '%product_url%'), true)); } $stuff = intval($product->id) ? $product->url : '%product_url%'; foreach ($frontend_urls as &$frontend_url) { $pos = strrpos($frontend_url['url'], $stuff); $frontend_url['base'] = $pos !== false ? rtrim(substr($frontend_url['url'], 0, $pos), '/') . '/' : $frontend_url['url']; } unset($frontend_url); $product_model = new shopProductModel(); $this->view->assign('storefront_map', $product_model->getStorefrontMap($product->id)); /** * Backend product profile page * UI hook allow extends product profile page * @event backend_product * @param shopProduct $entry * @return array[string][string]string $return[%plugin_id%]['title_suffix'] html output * @return array[string][string]string $return[%plugin_id%]['action_button'] html output * @return array[string][string]string $return[%plugin_id%]['toolbar_section'] html output * @return array[string][string]string $return[%plugin_id%]['image_li'] html output */ $this->view->assign('backend_product', wa()->event('backend_product', $product)); /** * @event backend_product_edit */ $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product)); $this->view->assign('categories', $categories); $this->view->assign('counters', $counters); $this->view->assign('product', $product); $this->view->assign('current_author', shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId())); $this->view->assign('reply_allowed', true); $this->view->assign('review_allowed', true); $this->view->assign('sidebar_counters', $sidebar_counters); $this->view->assign('lang', substr(wa()->getLocale(), 0, 2)); $this->view->assign('frontend_urls', $frontend_urls); $tag_model = new shopTagModel(); $this->view->assign('popular_tags', $tag_model->popularTags()); $counts = array(); // Selectable features $features_selectable = $product->features_selectable; if (is_array($features_selectable)) { foreach ($features_selectable as $f) { if ($f['selected']) { $counts[] = $f['selected']; } } } $feature_model = new shopTypeFeaturesModel(); $features_selectable_types = $feature_model->getSkuTypeSelectableTypes(); foreach ($product_types as $type_id => &$type) { $type['sku_type'] = empty($features_selectable_types[$type_id]) ? shopProductModel::SKU_TYPE_FLAT : shopProductModel::SKU_TYPE_SELECTABLE; } $this->view->assign('features', $features_selectable); $this->view->assign('duble', '???'); $this->view->assign('features_counts', $counts); #load product types $this->view->assign('product_types', $product_types); $this->view->assign('sidebar_width', $config->getSidebarWidth()); }