=============================================================================
 Admin actions
=============================================================================
 GET /admin/products/:id/variants/group
430026
def admin_group_variants
      @product = Product.find(params[:id])
      
      return if !user_is_allowed('variants', 'edit')
      
      joins  = []
      where  = []
      values = []
      
      if params[:category_ids]
        joins  << [:category_memberships]
        where  << 'store_category_memberships.category_id IN (?)'
        values << params[:category_ids]
      end
      
      if params[:vendor_ids]
        joins  << [:vendor]
        where  << 'store_vendors.id IN (?)'
        values << params[:vendor_ids]
      end
      
      if params[:title]
        where  << 'LOWER(store_products.title) LIKE ?'
        values << "%#{params[:title].downcase}%"
      end
      
      # Query for all relevant products
      products = values.any? ? Product.joins(joins).where([where.join(' AND ')].concat(values)) : []
      
      # Grab variants for each product
      @variants = products.collect { |product| product.variants }.flatten
      
      # Grab all categories; except for "all" and "uncategorized"
      @categories = Category.where('parent_id IS NOT NULL AND name IS NOT NULL').order(:url)
      
      # Grab all vendors
      @vendors = Vendor.where('name IS NOT NULL').order(:name)
      
      render :layout => 'caboose/admin'
    end
1198433
function doProductPage(product) {
	let res = http.get(product.url);
	check(res, {
		"title is correct": (res) => res.html("title").text() == product.title,
	});
	if (Math.random() <= product.chance) {
		let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
		let formID = res.body.match('name="form_id" value="(.*)"')[1];
		let formToken = res.body.match('name="form_token" value="(.*)"')[1];
		let productID = res.body.match('name="product_id" value="(.*)"')[1];
		group("add to cart", function() { 
			addProductToCart(product.url, productID, formID, formBuildID, formToken)
		});
	}
}
149459
public function getPermissionActions()
    {
        $actions = [];

        /**
         * @var $route \Symfony\Component\Routing\Route
         */
        foreach ($this->router->getRouteCollection()->all() as $name => $route) {
            if ($route->hasOption('require_admin_permission')) {
                $options = explode('.', $route->getOption('require_admin_permission'));
                if (!array_key_exists($options[0], $actions))
                    $actions[$options[0]] = [];
                if (!in_array($options[1], $actions[$options[0]]))
                    $actions[$options[0]][] = $options[1];
            }
        }

        ksort($actions);

        return $actions;
    }
334684
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
		if ( ( 'plugin_information' != $_action ) || ! isset( $_args->slug ) || ( $_args->slug != $this->product->get_slug() ) ) {
			return $_data;
		}
		$api_response = $this->api_request();
		if ( false !== $api_response ) {
			$_data = $api_response;
		}

		return $_data;
	}
596246
public function getProductVariationJsonData()
    {
        $jsonData = [];
        $lists = ProductAttributeIntegerValue::whereIn(
            'product_id',
            $this->productVariations->pluck('variation_id')
        )->get();
        
        foreach ($lists as $list) {
            $variationModel = self::find($list->product_id);
            if (array_has($jsonData, $list->product_id)) {
                $data = array_get($jsonData, $list->product_id);
                $data[$list->attribute_id] = [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]
                ];
                $jsonData[$list->product_id] = $data;
            } else {
                $jsonData[$list->product_id] = [$list->attribute_id => [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]]
                ];
            }
        }
        return $jsonData;
    }
957717
public function actionView()
    {
        $model = $this->model;
        $id = $model->name;
        $model = $this->findModel($id);
        $authManager = Yii::$app->getAuthManager();
        $avaliable = $assigned = [
            'Roles' => [],
            'Permission' => [],
            'Routes' => [],
        ];
        $children = array_keys($authManager->getChildren($id));
        $children[] = $id;
        foreach ($authManager->getRoles() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }
            $avaliable['Roles'][$name] = $name . ' — ' . $role->description;
        }
        foreach ($authManager->getPermissions() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }

            if (isset($name[0])) {
                $avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $role->description;
            }
        }
        foreach ($authManager->getChildren($id) as $name => $child) {
            if ($child->type == Item::TYPE_ROLE) {
                $assigned['Roles'][$name] = $name . ' — ' . $child->description;
            } else {
                if (isset($name[0])) {
                    $assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $child->description;
                } else {
                    $assigned['Permission'][$name] = $name . ' — ' . $child->description;
                }
            }
        }
        $avaliable = array_filter($avaliable);
        $assigned = array_filter($assigned);
        return $this->render('view', ['model' => $model, 'avaliable' => $avaliable, 'assigned' => $assigned]);
    }
501038
protected function overrideAction($action, $id = null) {
        $overrides = Configure::read('Admin.actionOverrides');
        $model = $this->Model->qualifiedName;

        if (empty($overrides[$model][$action])) {
            return false;
        }

        $url = (array) $overrides[$model][$action];
        $url[] = $id;

        $response = $this->requestAction($url, array(
            'autoRender' => true,
            'bare' => false,
            'return' => true,
            'override' => true,
            'data' => $this->request->data
        ));

        $this->autoRender = false;
        $this->response->body($response);

        return true;
    }
336271
public function index()
    {
        $this->requireAdmin();

        $groups = array();
        $groupList = $this->groupStore->getWhere(array(), 100, 0, array(), array('title' => 'ASC'));

        foreach ($groupList['items'] as $group) {
            $thisGroup = array(
                'title' => $group->getTitle(),
                'id' => $group->getId(),
            );
            $projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId());
            $thisGroup['projects'] = $projects['items'];
            $groups[] = $thisGroup;
        }

        $this->view->groups = $groups;
    }
633810
def admin_edit
      return if !user_is_allowed('products', 'edit')
      @product = Product.find(params[:product_id])
      @modification = Modification.find(params[:mod_id])
      @modification_value_input_field = ModificationValueInputField.find(params[:id])
      render :layout => 'caboose/modal'
    end
944499
public function listAction()
	{
		$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page !');
		
		$postManager = $this->get('asf_document.post.manager');
		
		// Define DataGrid Source
		$source = new Entity($postManager->getClassName());
		
		// Get datagrid
		$grid = $this->get('grid');
		$grid instanceof Grid;
		$grid->setSource($source);
		$tableAlias = $source->getTableAlias();
		$postClassName = $postManager->getShortClassName();
		
		$source->manipulateQuery(function($query) use ($tableAlias, $postClassName) {
			$query instanceof QueryBuilder;
			
			// Get all original version of each posts
			$query2 = $query->getEntityManager()->createQueryBuilder();
			$query2->select('post.id')
				->from($postClassName, 'post')
				->where('post.original IS NULL');
			$result = $query2->getQuery()->getResult();
			
			// Search versions for each original posts
			if (count($result)) {
				$ids = array();
				foreach($result as $original) {
					$qb = $query->getEntityManager()->createQueryBuilder();
					$qb->select('p')->from($postClassName, 'p')
						->where('p.original=:original_id')
						->orderBy('p.createdAt', 'DESC')
						->setParameter('original_id', $original['id']);
					$r = $qb->getQuery()->setMaxResults(1)->getResult();
					
					if ( count($r) ) {
						$ids[] = $r[0]->getId();
					} else {
						$ids[] = $original['id'];
					}
				}
				
				// Create query for datagird
				$query->add('where', $query->expr()->in($tableAlias.'.id', $ids));
			}
			
			if ( count($query->getDQLPart('orderBy')) == 0) {
				$query->orderBy($tableAlias.'.createdAt', 'DESC');
			}
		});
		
		// Grid Columns configuration
		$this->get('event_dispatcher')->dispatch(DocumentEvents::POST_GRID_CONFIG, new PostGridEvent($grid, $source));
		
		$grid->getColumn('id')->setVisible(false);
		$grid->getColumn('title')->setTitle($this->get('translator')->trans('Post title', array(), 'asf_document'));
		$grid->getColumn('content')->setVisible(false);
		$grid->getColumn('slug')->setTitle($this->get('translator')->trans('Slug', array(), 'asf_document'));
		$grid->getColumn('state')->setTitle($this->get('translator')->trans('State', array(), 'asf_document'))
			->setFilterType('select')->setSelectFrom('values')->setOperatorsVisible(false)
			->setDefaultOperator('eq')->setValues(array(
				DocumentModel::STATE_DRAFT => $this->get('translator')->trans('Draft', array(), 'asf_document'),
				DocumentModel::STATE_WAITING => $this->get('translator')->trans('Waiting', array(), 'asf_document'),
				DocumentModel::STATE_PUBLISHED => $this->get('translator')->trans('Published', array(), 'asf_document')
			));
		$grid->getColumn('createdAt')->setTitle($this->get('translator')->trans('Created at', array(), 'asf_document'));
		$grid->getColumn('updatedAt')->setTitle($this->get('translator')->trans('Updated at', array(), 'asf_document'));
		
		$edit_action = new RowAction('btn_edit', 'asf_document_post_edit');
		$edit_action->setRouteParameters(array('id'));
		$grid->addRowAction($edit_action);
		
		$delete_action = new RowAction('btn_delete', 'asf_document_post_delete', true);
		$delete_action->setRouteParameters(array('id'))
			->setConfirmMessage($this->get('translator')->trans('Do you want to delete this post?', array(), 'asf_document'));
		$grid->addRowAction($delete_action);
		
		$grid->setNoDataMessage($this->get('translator')->trans('No post was found.', array(), 'asf_document'));
		
		return $grid->getGridResponse('ASFDocumentBundle:Post:list.html.twig', array('grid' => $grid));
	}
11102
public function listAction()
	{
		if ( false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN') )
			throw new AccessDeniedException();
	
		// Set Datagrid source
		$source = new Entity($this->get('asf_website.config.manager')->getClassName());
		$tableAlias = $source->getTableAlias();
		$source->manipulateQuery(function($query) use ($tableAlias){
			$query instanceof QueryBuilder;

			if ( count($query->getDQLPart('orderBy')) == 0) {
				$query->orderBy($tableAlias . '.name', 'ASC');
			}
		});

		// Get Grid instance
		$grid = $this->get('grid');
		$grid instanceof Grid;

		// Attach the source to the grid
		$grid->setSource($source);
		$grid->setId('asf_website_config_list');

		// Columns configuration
		$grid->hideColumns(array('id'));
	
		$grid->getColumn('name')->setTitle($this->get('translator')->trans('Config name', array(), 'asf_website'))
			->setDefaultOperator('like')
			->setOperatorsVisible(false);

		$editAction = new RowAction('btn_edit', 'asf_website_config_edit');
		$editAction->setRouteParameters(array('id'));
		$grid->addRowAction($editAction);

		$deleteAction = new RowAction('btn_delete', 'asf_website_config_delete', true);
		$deleteAction->setRouteParameters(array('id'))
			->setConfirmMessage($this->get('translator')->trans('Do you want to delete this config?', array(), 'asf_website'));
		$grid->addRowAction($deleteAction);
	
		$grid->setNoDataMessage($this->get('translator')->trans('No config was found.', array(), 'asf_website'));
	
		return $grid->getGridResponse('ASFWebsiteBundle:Config:list.html.twig');
	}
1092207
public function actionMods($id = null)
    {
        $mod = null;
        $moderators = User::find()->where(['role' => User::ROLE_MODERATOR])->indexBy('id')->all();
        if (is_numeric($id) && $id > 0) {
            if (isset($moderators[$id])) {
                $mod = $moderators[$id];
            }
        } else {
            reset($moderators);
            $mod = current($moderators);
        }
        $searchModel = new ForumSearch();
        $dataProvider = $searchModel->searchForMods(Yii::$app->request->get());
        $postData = Yii::$app->request->post();
        if ($postData) {
            if (!User::can(Rbac::PERM_PROMOTE_USER)) {
                $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
            } else {
                $mod_id = !empty($postData['mod_id']) && is_numeric($postData['mod_id']) && $postData['mod_id'] > 0 ? $postData['mod_id'] : 0;
                $selection = !empty($postData['selection']) ? $postData['selection'] : [];
                $pre = !empty($postData['pre']) ? $postData['pre'] : [];
                if ($mod_id == $mod->id) {
                    if ($mod->updateModeratorForMany($selection, $pre)) {
                        $this->success(Yii::t('podium/flash', 'Moderation list has been saved.'));
                    } else {
                        $this->error(Yii::t('podium/flash', 'Sorry! There was an error while saving the moderation list.'));
                    }
                    return $this->refresh();
                }
                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while selecting the moderator ID.'));
            }
        }
        return $this->render('mods', [
            'moderators' => $moderators,
            'mod' => $mod,
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
1116686
private function adminUpdateGroup()
    {
        $item = $this->dbItem('groups', arg('id', 'int'));

        $item['title'] = arg('title', 'dbsafe');
        $item['description'] = arg('description', 'dbsafe');

        $this->dbUpdate('groups', $item);

        $url = arg('submitURL');
        if (strpos($url, '=group') === false)
        {
            $url .= '&action=group';
        }

        HTTP::redirect($url);
    }
1028951
public function index()
    {
        $models = $this->repository->all([], true);
        app('JavaScript')->put('models', $models);

        return view('attributes::admin.index-groups');
    }
485411
public function getAttributeValuesAction(/** @noinspection PhpUnusedParameterInspection */ $productId, $attributeId)
    {
        $result = array();

        // Get attribute for this product
        $attribute = AttributeQuery::create()->findPk($attributeId);

        if ($attribute !== null) {
            $values = AttributeAvQuery::create()
                ->joinWithI18n($this->getCurrentEditionLocale())
                ->filterByAttribute($attribute)
                ->find();
            ;

            if ($values !== null) {
                /** @var AttributeAv $value */
                foreach ($values as $value) {
                    $result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
                }
            }
        }

        return $this->jsonResponse(json_encode($result));
    }
828216
def find_products(params)
      raise ArgumentError unless params[:CategoryID] or params[:ProductID] or params[:QueryKeywords] or
        (params[:'ProductID.Value'] && params[:'ProductID.type'])
      response = get_json_response(build_request_url('FindProducts', params))
      if response.response.has_key?('Product')
        response.results = response.response['Product']
      end
      return response
    end
1072344
public function indexAction()
    {
        $configSectionManager = $this->container->get('admin.configuration.configsection_manager');
        $sections = $configSectionManager->getRepository()->findAllWithConfigGroups();
        $group = null;
        if ( count($sections) ) {
            $groups = $this->container->get('admin.configuration.configgroup_manager')->getRepository()->findByConfigGroupId($sections[0]->getId());
            if ( count($groups) ) {
                $group = $groups[0];
            }
        }

        return $this->renderTemplate($group);
    }