opencart subcategory description on category - opencart

I'm trying to add description on subcategories (refine search) and I fail. What I do is to add the following line in "product/category.tpl"
but the text that is shown is from the parent category. Can anybody help me? 2.3.0.2

open file: catalog/controller/product/category.php
$data['categories'][] = array(
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'thumb' => $image
);
add 'sub_desc' => utf8_substr(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 0) after 'thumb' => $image don't forget the ","
$data['categories'][] = array(
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'thumb' => $image,
'sub_desc' => utf8_substr(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 0)
);
then in: catalog/view/theme/default/template/product/category.tpl
<?php if (!empty($category['sub_desc'])) { ?>
<div class="description"><?php echo $category['sub_desc']; ?></div>
<?php } ?>
and you will get subcategory descripton of each subcategory:)

Related

Prestashop 1.6 Webservices: how to fetch the products' attachments?

http://doc.prestashop.com/display/PS16/Web+service+reference doesn't list any "attachments" or "product_attachments" etc. resource. Moreover, I have tested to fetch the products thanks to the corresponding resource present in the list, but the products don't contain any reference ID to the attachments, nore the attachments object at JSON format.
So how to fetch the products attachments? Is it possible, at least?
It doesn't or at least I could find it.
You can add it by overriding core Product class.
Add new method
public function getWsProductAttachments()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
'SELECT pa.`id_attachment` AS id, a.file, a.file_name
FROM `' . _DB_PREFIX_ . 'product_attachment` pa
LEFT JOIN `' . _DB_PREFIX_ . 'attachment` a ON (a.id_attachment = pa.id_attachment)
' . Shop::addSqlAssociation('attachment', 'a') . '
WHERE pa.`id_product` = ' . (int) $this->id
);
return $result;
}
Add next element to $webserviceParameters['associations'] property:
'attachments' => array(
'resource' => 'product',
'api' => 'products',
'getter' => 'getWsProductAttachments',
'fields' => array(
'id' => array('required' => true),
'file' => array(),
'file_name' => array(),
),
),
Now your products/{id} request will return something like
<attachments nodeType="product" api="products">
<product>
<id><![CDATA[1]]></id>
<file><![CDATA[cc046998a333a9bffaa23ce292f2da43edb37065]]></file>
<file_name><![CDATA[bbb.yml]]></file_name>
</product>
<product>
<id><![CDATA[2]]></id>
<file><![CDATA[b04566afd74cdaa54c921c8907c7efd489a2eec0]]></file>
<file_name><![CDATA[aaa.csv]]></file_name>
</product>
</attachments>
And you can download attachments like my.shop/download/cc046998a333a9bffaa23ce292f2da43edb37065

Compare user ID exactly, not with LIKE

I have this query -
<?php
$post_args = array(
'post_type' => 'tribe_events',
'eventDisplay'=>'custom',
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'compliance',
),
),
'meta_query' => array(
array(
'key' => 'associated_people',
'value' => $current_user,
'compare' => 'LIKE'
)
)
); ?>
At the moment it is fetching events that are associated to a particular person in a custom post type called people. I'm doing this using a relationship advanced custom field called associated_people.
I'm using the 'compare' => 'LIKE' code to do this also, but it's fetching other id's that are like the current one. e.g. If it's looking for ID 117, it's also bringing back 17, 11, 7..etc.
Is there a way to look at just the exact ID?
So far we have tried changing it to 'compare' => '='
Any help would be much appreciated. Thanks!
We solved it by changing the way the value was called -
<?php
$post_args = array(
'post_type' => 'tribe_events',
'eventDisplay'=>'custom',
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'compliance',
),
),
'meta_query' => array(
array(
'key' => 'associated_people',
'value' => '"' . $current_user . '"',
'compare' => 'LIKE'
)
)
); ?>

Calling model_tool_image resize on Confirm Controller

i want get url link of product image
im edit catalog/controller/checkout/confirm.php
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
im try to add
'thumb' => $this->model_tool_image->resize($product['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
after call $product['thumb'] in checkout/confirm.tpl
i got the Fatal Error
Fatal error: Call to a member function resize() on a non-object in /var/www/xxx.dev/public_html/catalog/controller/checkout/confirm.php on line 393
i just add
$this->load->model('tool/image');
after
$this->load->model('tool/upload');
on confirm.php controller

CakePHP 2.x Removing Items from the List

So my application has student users. Each of them has an account and can upload files. In my view, I have 2 fields: A dropdown menu field and a browse file. Below those two fields is a table listing all the files uploaded by that user.
My dropdown menu contains the list of the file types needed to be uploaded (e.g. Application Form, Transcript of Record, Bio-data, etc.). The users have to choose one from the list and upload the file/s.
So what I want to do is once a file type has been uploaded, let's say the Application Form, it will be removed from the dropdown list. Of course, in case they have uploaded a wrong file, inside a table there is a remove button. Clicking the remove will bring the selected file's upload type back to the dropdown list.
How can this be done?
View:
$this->Form->input('type', array(
'class' => 'form-control',
'options' => array(
'Application Form' => 'Application Form',
'Manual' => 'Manual',
'Picture' => 'Picture'
),
'empty' => 'Choose an upload type'
));
$this->Form->input('file.', array(
'class' => 'form-control',
'type' => 'file'
));
Table below the dropdown and file browse:
<?php
foreach ($docs as $docs){
<?php echo $docs['Upload']['type'] ?>
<?php echo $this-Html-link('Remove from Table', array('controller' => 'schools', 'action' => 'remove')); ?>
}
Controller:
public function documents(){
$this-> layout = 'schools';
$this->set('docs', $this-Upload->find('all', array('condition' => array('Upload.iddocs' => $doc['Doc']['id']))));
if($this->request->is('post')){
$file = $this-request->data;
$size = (sizeof($this->request->data['Upload']['file']));
$is = $this->Auth->User('userId');
$school = $this->School->find('first', array('conditions' => array('usersId' => $id)));
if(!is_dir(ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name']))
mkdr(ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name']);
for($i=0; $i<$size; $i++){
$dest_file = ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name'] . DS . $file['Upload']['file'][$i]['name'];
if(move_uploaded_file($file['Upload']['file'][$i]['name']['tmp_name'], $dest_file)){
$this->Upload->create();
$data = array(
'iddocs' => $doc['Doc']['id'],
'dest' => $dest_file,
'type' => $this->request->data['Upload']['type']
);
$this->Upload->save($data);
}
}
}
}
?>

ZF2 + Doctrine 2 : Cli Tool has Access Denied

I have a ZF2 2.1.3 app with Doctrine 2.
I installed using composer:
"zendframework/zendframework": "2.*"
,"doctrine/doctrine-orm-module": "dev-master"
A create a file config/autoload/database.local.php with the following:
return array(
'doctrine' => array(
'connection' => array(
// Default connection name
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'dbname' => 'zf2-experimental',
'user' => 'root',
'password' => '',
),
),
),
),
);
I create my entity Bar under Foo module (src/Business/Entity/Bar.php) and configure it on module.config.php like this:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Business/Entity'),
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Business\Entity' => __NAMESPACE__ . '_driver',
),
),
),
),
Ok! It's exactly at Sam says here!
Then I create a simple Foo entity and run the doctrine cli tool:
c:\wamp\www\zf2-Experimental>.\vendor\bin\doctrine-module.bat orm:validate-schema
[Mapping] OK - The mapping files are correct.
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'username'#'localhost' (using password: YES)
orm:validate-schema
c:\wamp\www\zf2-Experimental>
Looks like the cli tool can get my connection parameters in my config/autoload/database.local.php!
On Application index I tested my config:
$config = $this->getServiceLocator()->get('config');
\Zend\Debug\Debug::dump($config['doctrine']['connection']['orm_default']);
And this returned:
array (size=4)
'configuration' => string 'orm_default' (length=11)
'eventmanager' => string 'orm_default' (length=11)
'params' =>
array (size=5)
'host' => string 'localhost' (length=9)
'port' => string '3306' (length=4)
'user' => string 'root' (length=4)
'password' => string '' (length=0)
'dbname' => string 'zf2-experimental' (length=16)
'driverClass' => string 'Doctrine\DBAL\Driver\PDOMySql\Driver' (length=36)
Someone can, please, help me?! :)
Thanks you all!
Well, I waste a lot of time trying to solve this and finally did.
I forgot to mention that I using ZF1 environment-specific configurations style!
You can see here!
I create my database config file in the following structure (I didn't mention this before, because I thought It wouldn't interfere on the question):
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
// Here! My config path is config/autoload/app_env/development/
'config/autoload/app_env/' . (getenv('APPLICATION_ENV') ?: 'production') . '{,*.}.local.php',
),
So, my database configs actually are in config/autoload/app_env/development/database.local.php!
When I copy-paste the file to config/autoload/database.local.php my CLI Tool works!
But WHY? Why the Cli Tool can't look for the config file inside another directory?
There is a way to work with sub-folders?
Thanks for the help!