prestashop category / subcategory make cms 404 error - prestashop-1.6

I am working with prestashop in a local environment and then set up a store, the problem that I have emerged is the following.
Buy the module to remove the IDs of URLs: Module Pretty URLs and works perfect.
then I want to show the URL of the subcategories the category parent, example: example.com/women/jeans
that achieve it using the following code, modifying the file override/classes/dispatcher.php
'category_rule' => array(
'controller' => 'category',
'rule' => 'categories:/}{rewrite}',
'keywords' => array(
'id' => array('regexp' => '[0-9]+'),
'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'category_rewrite'),
'categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
),
),
In the Prestashop admin adding {categories:/}{rewrite} to the SEO/URLs of the categories.
file override/classes/Link.php
public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false)
{
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, null, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
if (!is_object($category)) {
$category = new Category($category, $id_lang);
}
$params = array();
$params['id'] = $category->id;
$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
$params['meta_keywords'] = #Tools::str2url($category->meta_keywords);
$params['meta_title'] = #Tools::str2url($category->meta_title);
$selected_filters = is_null($selected_filters) ? '' : $selected_filters;
if (empty($selected_filters)) {
$rule = 'category_rule';
} else {
$rule = 'layered_rule';
$params['selected_filters'] = $selected_filters;
}
$cats = array();
foreach ($category->getParentsCategories() as $cat){
if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
{
$cats[] = $cat['link_rewrite'];
$params['categories'] = implode('/', array_reverse($cats));
}
}
$r_url = $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop);
return $r_url;
}
But to do this all the pages CMS throw me a 404, not that it can be.

Related

The Date stored in my database is like '2018-09-15 10:34:09',i want result of search in '15-09-2018' Format.I'm using Kartik datepicker to select date

I'm new in programming and I'm confused at one point. I'm using kartik datepicker to search date from table.In my table the date is stored in '2018-09-15 10:34:09' format. I'm using a stored procedure here and when I enter date (in format: 15-9-2018), I want to show some results.
My controller:
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Functions;
use backend\models\Meetmelicence;
use backend\models\MeetmelicenceSearch;
class MeetmelicenceController extends BackendController
{
public function actionIndex($redirect = '')
{
$searchModel = new MeetmelicenceSearch();
$model = new Meetmelicence();
if(isset($_GET['MeetmelicenceSearch']))
{
$searchModel->attributes = $_GET['MeetmelicenceSearch'];
}
if($redirect == 'success')
{
Yii::$app->session->setFlash('success', 'Import data processed
successfully.');
}
$transaction_id = $searchModel->transaction_id;
$transactionmodel = $this->findModeltransactionmodel($transaction_id);
return $this->render('index', [
'searchModel' => $searchModel,
'model' => $model,
'transactionmodel' =>$transactionmodel,
]);
}
protected function findModeltransactionmodel($id)
{
if (($model = Payment::findOne(['transaction_id' => $id])) !== null) {
return $model;
}
else {
return false;
}
}
}
Model:
<?php
namespace backend\models;
use Yii;
use backend\models\Backendcommon;
class Meetmelicence extends Backendcommon
{
public $transaction_id;
public $transaction_date;
public $new_expiry_date;
public static function tableName()
{
return 'meet_me_licence_master';
}
public function rules()
{
return [
[['created_on', 'updated_on','unit_id','unit_user_id','isEmail','recieve_calls','transaction_id','transaction_date','new_expiry_date','user_licence_status','remarks'], 'safe'],
[['licence_number','status'],'required'],//,'licence_password'
[['transaction_id'],'required'],
];
}
}
Search model:
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\StaffCategory;
use yii\data\SpDataProvider;
class MeetmelicenceSearch extends Meetmelicence
{
public function rules()
{
return [
[['new_expiry_date','transaction_id','new_expiry_date','transaction_date',], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search()
{
$arrParams = array();
$arrParams['v_private_key'] = \Yii::$app->params['private_db_key'];
$object_xml_array['transaction_date'] = $this->transaction_date;
$object_xml_array['new_expiry_date']=$this->new_expiry_date;
$xml = new \SimpleXMLElement('<CustomXML/>');
$this->function_model->_array_to_xml($object_xml_array, $xml, 0);
$object_xml_array = $xml->asXML();
$final_array_xml = urldecode($object_xml_array);
$arrParams['v_object_xml'] = $final_array_xml;
$dataProvider = new SpDataProvider([
'spName' => 'meet_me_licence_list',
'params' => $arrParams,
'sort' => [
'attributes' => [
'transaction_date' => [
'asc' => ['transaction_date' => SORT_ASC, 'transaction_date' => SORT_ASC],
'desc' => ['transaction_date' => SORT_DESC, 'transaction_date' => SORT_DESC],
'default' => SORT_ASC,
'label' => 'Transaction Date',
],
'new_expiry_date' => [
'asc' => ['new_expiry_date' => SORT_ASC, 'new_expiry_date' => SORT_ASC],
'desc' => ['new_expiry_date' => SORT_DESC, 'new_expiry_date' => SORT_DESC],
'default' => SORT_ASC,
'label' => 'New Transaction Expiry Date',
],
],
'pagination' => [
'pageSize' => 20,
],
]);
return $dataProvider;
}
}
My index file:
<?php
<div class="container">
<div class="panel panel-default">
<div class="panel-body" style="padding:0px">
<?php Pjax::begin(['timeout' => 500000,'enablePushState'=>false]); ?>
<?= GridView::widget([
'dataProvider' => $searchModel->search(),
'filterModel' => $searchModel,
// 'layout' => '{items}{pager}',
'layout' => '{items}{pager}{summary}',
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last'
],
'columns' =>
[
'attribute'=> 'transaction_date',
'filter'=>DatePicker::widget([
'attribute'=> 'transaction_date',
'model' => $searchModel,
'type' => DatePicker::TYPE_COMPONENT_APPEND,
// 'type' => DatePicker::TYPE_COMPONENT_PREPEND,
// 'type' => DatePicker::TYPE_INPUT,
// 'type' => DatePicker::TYPE_BUTTON,
'options' => ['id'=> 'searchmodel_transaction_date',],
// 'value'=>'23-Feb-1982',
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy',
'todayHighlight' => true,
]
]),
'contentOptions' => [ 'style' => 'width: 80%;' ],
],
[
'attribute'=> 'new_expiry_date',
'filter'=>DatePicker::widget([
'attribute'=> 'new_expiry_date',
'model' => $searchModel,
'type' => DatePicker::TYPE_COMPONENT_APPEND,
'options' => ['id'=> 'searchmodel_new_expiry_date',],
'value'=>'10/05/2022',
'pluginOptions' => [
'autoclose' => false,
'format' => 'dd-M-yyyy',
'todayHighlight' => true,
]
]),
'contentOptions' => [ 'style' => 'width: 80%;' ],
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
</div>
</div>
My stored procedure:
DELIMITER $$
USE `fermax_crm_local_4_31`$$
DROP PROCEDURE IF EXISTS `meet_me_licence_list`$$
CREATE DEFINER=`dbfermaxcrm`#`%` PROCEDURE `meet_me_licence_list`(
IN v_private_key VARCHAR(100),
IN v_licence_number VARCHAR(255),
IN v_object_xml TEXT,
IN v_Sort TEXT,
IN v_limit INT,
IN v_pageIndex INT)
BEGIN
/*
*/
DECLARE v_Select TEXT DEFAULT "";
DECLARE v_Where TEXT DEFAULT " WHERE 1";
DECLARE v_From TEXT DEFAULT "";
DECLARE v_OrderBy TEXT DEFAULT "";
DECLARE v_QueryLimit TEXT DEFAULT "";
DECLARE v_group_by TEXT DEFAULT "";
DECLARE v_having TEXT DEFAULT "";
DECLARE
v_transaction_date,v_new_expiry_date DEFAULT "";
DECLARE v_transaction_id INT DEFAULT 0;
SET SESSION group_concat_max_len = 1000000000;
SET v_transaction_date = EXTRACTVALUE(v_object_xml, '//transaction_date[$#1]');
SET v_new_expiry_date = EXTRACTVALUE(v_object_xml, '//new_expiry_date[$#1]');
SET v_transaction_id = EXTRACTVALUE(v_object_xml, '//v_transaction_id[$#1]');
CALL add_query_log(0,0,'meet_me_licence_list',CONCAT("CALL meet_me_licence_list('"
,IFNULL(v_private_key,''),"','"
,IFNULL(v_licence_number,''),"','"
,IFNULL(v_object_xml,''),"','"
,IFNULL(v_Sort,''),"','"
,IFNULL(v_limit,''),"','"
,IFNULL(v_pageIndex,''),"',"
,");"
));
SET v_Select = CONCAT(" SELECT
mmlm.meet_me_licence_id
,mmlm.most_recent_audit_log
,get_date_string(mmlt.transaction_date,1,1, ' %d %b %Y %h:%i %p ') AS transaction_date
,get_date_string(mmlt.new_expiry_date ,1,1, ' %d %b %Y %h:%i %p ') AS new_expiry_date
");
SET v_From = CONCAT(" FROM meet_me_licence_master AS mmlm
LEFT JOIN meet_me_licence_transaction mmlt
ON mmlm.meet_me_licence_id= mmlt.meet_me_licence_id
LEFT JOIN unit un
ON CAST(un.unit_id AS CHAR) = CAST(mmll.unit_id AS CHAR)
");
SET v_Where = CONCAT(v_Where," AND mmlm.status != 3 ");
IF (IFNULL(v_transaction_date,'') != '') THEN
SET v_Where = CONCAT(v_Where," AND mmlt.transaction_date ='", v_transaction_date,"' ");
END IF;
IF (IFNULL(v_new_expiry_date,'') != '') THEN
SET v_Where = CONCAT(v_Where," AND mmlt.new_expiry_date = '",v_new_expiry_date,"' ");
END IF;
-- IF (v_sort_order != '') THEN
-- SET v_Where = CONCAT(v_Where," AND lower(c.sort_order) LIKE '%",v_sort_order,"%' ");
-- END IF;
SET v_group_by = CONCAT(" GROUP BY mmlm.meet_me_licence_id ");
SET #rec_Query = CONCAT(v_Select
,v_From
,v_Where
,v_group_by
,v_having
);
-- SET #cnt_Query = CONCAT("Select Count(*) INTO #o_RecCount FROM (",#rec_Query,") AS tmp");
SET #cnt_Query = CONCAT("Select Count(*) as o_RecCount FROM (",#rec_Query,") AS tmp");
-- IF(v_Sort != "") THEN
/*SET v_OrderBy = CONCAT("
ORDER BY CASE WHEN IFNULL(mmlm.updated_on,'0000-00-00 00:00:00') != '0000-00-00 00:00:00' then mmlm.updated_on
ELSE mmlm.`created_on` END DESC
");*/
-- END IF;
IF(v_Sort != "") THEN
SET v_OrderBy = CONCAT(" ORDER BY ",v_Sort);
ELSE
SET v_OrderBy = CONCAT("
ORDER BY CASE WHEN IFNULL(mmlm.updated_on,'0000-00-00 00:00:00') != '0000-00-00 00:00:00' then mmlm.updated_on
ELSE mmlm.`created_on` END DESC
");
END IF;
IF (v_PageIndex) > 0 THEN
SET v_QueryLimit = CONCAT(" LIMIT ", v_limit, "," , v_pageIndex);
END IF;
SET #vv_Query= CONCAT(v_Select
,v_From
,v_Where
,v_group_by
,v_OrderBy
,v_QueryLimit);
SELECT #vv_Query;
PREPARE s1 FROM #vv_Query;
EXECUTE s1;
PREPARE c2 FROM #cnt_Query;
EXECUTE c2;
-- select #cnt_Query;
END$$
DELIMITER ;

Linq GroupBy Query Timeout

My query with group by always gives timeout error. How can i make it work properly?
var result = products.Join(_Context.Barcode, firstTable => firstTable.ProductId, barcode => barcode.B_ProductId, (resultTable, resultProduct) => new
{
product = resultTable,
barcode = resultProduct
}).Join(_Context.Stock, secondTable => secondTable.barcode.Barcode, stock => stock.Barcode, (finalResult, finalStock) => new
{
Product = finalResult.product,
Stock = finalStock,
Barcode = finalResult.barcode
}).GroupBy(x => x.Product.ProductId).Select(I => new ProductDTO()
{
InStock = I.Sum(x => x.Stock.StockCount) > 0 ? true : false,
Url = I.Select(x => x.Product.Url).FirstOrDefault(),
Name= I.Select(x => x.Product.Name).FirstOrDefault(),
ImagePath = I.Select(x => x.Product.ImagePath).FirstOrDefault(),
Tax = I.Select(x => x.Product.Tax).FirstOrDefault(),
Price = I.Select(x => x.Product.Price).FirstOrDefault(),
Id = I.Select(x => x.Product.ProductId).FirstOrDefault(),
});
return result.ToList();
Thank you.
_Context.Database.CommandTimeout = 600;
use time out function before the result.

Cakephp 3 - Create full url

What I like to do is creating a full url.
Controller = 'A'
Action = 'doSomething'
param1 = $id
param2 = $id2
What I currently get is:
mydomain.com/A/doSomething?param1=X&param2=XX
What I want is:
mydomain.com/A/doSomething/X/XX
Code:
$message = 'Test: '. Router::url([
"controller" => "A",
"action" => "doSomthing",
"param1" => $id,
"param2" => $id2,
'_full' => true
]);
$id1 = 'id1';
$id2 = 'id2';
$url= Router::url([
"controller" => "A",
"action" => "doSomething",
$id1,
$id2,
'_full' => true
]);
debug($url);
Outputs:
'http://host/a/do-something/id1/id2'
Try:
public function doSomthing($param1, $param2)
{
#your code here
}

Adwords API CampaignCriterionService IpBlock empty IpAddress issue

We've experienced issue with CampaignCriterionService while getting IpAddress value for IpBlock criterion.
https://developers.google.com/adwords/api/docs/reference/v201502/CampaignCriterionService.IpBlock
It is impossible to get IpAddress value. If you use it in selector - you get error [SelectorError.INVALID_FIELD_NAME # serviceSelector; trigger:'IpAddress'].
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'IpAddress');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
After hours of struggle we found that you should use "KeywordText" instead of "IpAddress" to get proper value. This is not obvious at all. Hope this hint saves somebody time and efforts. Such things should be definitely in documentation. So, working code looks like following:
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
If you want to use IpAddress as predicate to search by it you should use the same "KeywordText", there is an example:
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->predicates[] = new Predicate('KeywordText', 'EQUALS', '192.168.0.1/32');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
print_r($page);
Produces output:
CampaignCriterionPage Object
(
[entries] => Array
(
[0] => NegativeCampaignCriterion Object
(
[campaignId] => 167195728
[isNegative] => 1
[criterion] => IpBlock Object
(
[ipAddress] => 192.168.0.1/32
[id] => 23078300211
[type] => IP_BLOCK
[CriterionType] => IpBlock
[_parameterMap:Criterion:private] => Array
(
[Criterion.Type] => CriterionType
)
)
[bidModifier] =>
[forwardCompatibilityMap] =>
[CampaignCriterionType] => NegativeCampaignCriterion
[_parameterMap:CampaignCriterion:private] => Array
(
[CampaignCriterion.Type] => CampaignCriterionType
)
)
)
[totalNumEntries] => 1
[PageType] => CampaignCriterionPage
[_parameterMap:Page:private] => Array
(
[Page.Type] => PageType
)
)

ZF2 - Form creation missing validators

I am having a little trouble adding validators to a ZF2 form object. I an building a form from a schema set in a database so I can validate a set of user input quickly.
This is the code that generates the form object
//initialise the form
$form = new Form();
//need to loop through the schema to create the form
for($i=0; $i < count($schema); $i++)
{
$form_options = array();
//add the basics to the form
$form_options['name'] = $schema[$i]['field_name'];
$form_options['type'] = $schema[$i]['field_type'];
//check if this is a required field
if($schema[$i]['is_required'] == 'true')
{
$form_options['required'] = true;
}
//add functions to filter the input form
$function_filters = explode(',', $schema[$i]['function_filter']);
if(!empty($function_filters))
{
$filters = array();
for($j=0; $j < count($function_filters); $j++)
{
$filters = array('name' => $function_filters[$j]);
}
$form_options['filters'] = $filters;
}
//add validators to the field array
$validators = array();
if(!is_null($schema[$i]['min_length']) && !is_null($schema[$i]['max_length']))
{
$validators[] = array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => (int) $schema[$i]['min_length'],
'max' => (int) $schema[$i]['max_length'],
)
);
}
//our regex validator if it exists
if(!is_null($schema[$i]['regex_filter']) || strlen($schema[$i]['regex_filter']) != 0)
{
$validators[] = array(
'name' => 'regex',
'options' => array(
'pattern' => $schema[$i]['regex_filter'],
'messages' => array(
\Zend\Validator\Regex::INVALID => $schema[$i]['regex_invalid'],
\Zend\Validator\Regex::NOT_MATCH => $schema[$i]['regex_not_match'],
\Zend\Validator\Regex::ERROROUS => $schema[$i]['regex_errorus'],
)
)
);
}
//only add the validators if theres something in there
if(!empty($validators))
{
$form_options['validators'] = $validators;
}
$form->add($form_options);
}
//return our form object
return $form;
The block of code behaves the way I expect it, the output of $form_option after it's performed the above code looks like this:-
Array
(
[name] => username
[type] => Text
[required] => 1
[filters] => Array
(
[name] => StripTags
)
[validators] => Array
(
[0] => Array
(
[name] => StringLength
[options] => Array
(
[encoding] => UTF-8
[min] => 3
[max] => 50
)
)
[1] => Array
(
[name] => regex
[options] => Array
(
[pattern] => /^[a-zA-Z0-9_]{3,50}$/
[messages] => Array
(
[regexInvalid] => L_REGEX_INVALID
[regexNotMatch] => L_REGEX_USERNAME
[regexErrorous] => L_REGEX_ERRORUS
)
)
)
)
)
When I came to test it, it ignores the StringLength & Regex validators entirely, and only pay attention to the required validator for the last form element.
Anyone have any idea what's gone wrong?

Resources