PrestaShop | universal open-source software platform | Ecommerce library
kandi X-RAY | PrestaShop Summary
Support
Quality
Security
License
Reuse
- Import one product
- Validate an order
- Sends an email .
- Show Kpi
- Change order state
- Returns the neutral value for a cart item .
- Remove a product .
- Map LocaleData to a LocaleData object .
- Return the shipping cost for the package .
- Initialize form back
PrestaShop Key Features
PrestaShop Examples and Code Snippets
Trending Discussions on PrestaShop
Trending Discussions on PrestaShop
QUESTION
I find in internet a CRUD module (create, read, update, delete) and it works very well in backoffice of Prestashop 1.7.7.6
And now I want to select data from module table and display in front office prestashop product page tpl file
How can i do ?
please help me
Thanks You very much in advance
structure of crud module moduletest :
- Classes / Moduletesttabletest.php
- Controllers / Admin / Adminmoduletest.php
- moduletest.php
Display Data from database table of module to Prestashop Product Page - Prestashop 1.7.7.6
ANSWER
Answered 2022-Apr-03 at 17:03You need to select hook there data will be displayed
Than add this hook to your moduletest.php file in two places.
For example to show data on product page near price block you can use hook ProductPriceBlock
There is public function install() in yor module. It will register hook, so prestashop knows that it`s function need to be called
public function install()
{ ....
$this->registerHook('header') &&
$this->registerHook('backOfficeHeader') &&
++$this->registerHook('displayProductPriceBlock');
}
At the end of file before closing code block "}" add code to retrive and display data to according function:
public function hookdisplayProductPriceBlock($params)
{ // your code goes here }
Reset module in modules Modules manager - this will actualy register hook after you make changes to source code
To use template you need according tpl file in /views/templates/front/ subdirectory of module and call it by
$this->display(__FILE__, 'my-template.tpl');
QUESTION
Has anyone had any issue with using Prestashop's Product class updateCategories() before for updating lots of products categories at once? We're using this to map supplier categories to our own categories and we need to change 100's-1000's of products categories. The problem we're running into is that updateCategories usually slows down to a crawl when updating larger amounts of products 100+ and will take hours to do it.
I've checked the timings of it running on 50 products and sometimes it updates them fine and sometimes it starts slowing down immensely after 30-40.
One other thread suggested it might be an action hook triggering on updateCategories(), but even after disabling / overriding the modules with this hook (ps_mainmenu, ps_facetedsearch) it still didn't fix it.
Our shop currently has ~150 000 products and 300+ categories, the server hardware shouldn't be a problem, checked the metrics and nothing was bottlenecking it.
Would love to hear any suggestions on where the problem could be originating from, or a way to find out what's causing it myself.
Attaching an example script for bulk updating categories.
$productIds = Db::getInstance()->executeS('SELECT id_product FROM `' . _DB_PREFIX_ . 'product` ORDER BY id_product LIMIT 60');
$categoryId = 1;
$time_pre_total = microtime(true);
foreach ($productIds as $id) {
echo '------------------------------------------';
var_dump($id);
echo '
';
$time_pre = microtime(true);
$product = new Product((int)$id['id_product'], null, null, (int)Context::getContext()->shop->id);
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;
var_dump($exec_time);
echo '
';
$time_pre = microtime(true);
$product->updateCategories([(int)$categoryId]);
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;
var_dump($exec_time);
echo '
';
$time_pre = microtime(true);
$product->id_category_default = $categoryId;
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;
var_dump($exec_time);
echo '
';
$time_pre = microtime(true);
$product->update();
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;
var_dump($exec_time);
echo '
';
echo '------------------------------------------';
}
echo '------------------------------------------';
echo '------------------------------------------';
echo '
';
$time_post_total = microtime(true);
$exec_time_total = $time_post_total - $time_pre_total;
var_dump($exec_time_total);
echo '
';
echo 'cycle ended';
ANSWER
Answered 2022-Mar-22 at 10:50The issue was with the cleanPositions() method in Products class, it was recalculating positions as @user3256843 mentioned in the comments, I'll be looking to override / write a different method for myself to use.
QUESTION
I'm trying to get a sql select inside an update, but always return null.
UPDATE ps_stock_available sa
SET sa.reserved_quantity = (
SELECT IFNULL(SUM(od.product_quantity - od.product_quantity_refunded),0)
FROM ps_orders o
INNER JOIN ps_order_detail od ON od.id_order = o.id_order
INNER JOIN ps_order_state os ON os.id_order_state = o.current_state
WHERE o.id_shop = 1 AND
os.shipped != 1 AND (
o.valid = 1 OR (
os.id_order_state NOT IN ('6,28,59') AND
os.id_order_state NOT IN ('8')
)
) AND sa.id_product = od.product_id AND
sa.id_product_attribute = od.product_attribute_id
GROUP BY od.product_id, od.product_attribute_id
)
WHERE sa.id_shop = 1 AND sa.id_product = 3374;
If the sum is null, the subquery has to return 0. I get this query update from prestashop class (StockManager.php, method: updateReservedProductQuantity).
This is the original code:
$updateReservedQuantityQuery = '
UPDATE {table_prefix}stock_available sa
SET sa.reserved_quantity = (
SELECT SUM(od.product_quantity - od.product_quantity_refunded)
FROM {table_prefix}orders o
INNER JOIN {table_prefix}order_detail od ON od.id_order = o.id_order
INNER JOIN {table_prefix}order_state os ON os.id_order_state = o.current_state
WHERE o.id_shop = :shop_id AND
os.shipped != 1 AND (
o.valid = 1 OR (
os.id_order_state != :error_state AND
os.id_order_state != :cancellation_state
)
) AND sa.id_product = od.product_id AND
sa.id_product_attribute = od.product_attribute_id
GROUP BY od.product_id, od.product_attribute_id
)
WHERE sa.id_shop = :shop_id
';
$strParams = array(
'{table_prefix}' => _DB_PREFIX_,
':shop_id' => (int) $shopId,
':error_state' => (int) $errorState,
':cancellation_state' => (int) $cancellationState,
);
if ($idProduct) {
$updateReservedQuantityQuery .= ' AND sa.id_product = :product_id';
$strParams[':product_id'] = (int) $idProduct;
}
if ($idOrder) {
$updateReservedQuantityQuery .= ' AND sa.id_product IN (SELECT product_id FROM {table_prefix}order_detail WHERE id_order = :order_id)';
$strParams[':order_id'] = (int) $idOrder;
}
$updateReservedQuantityQuery = strtr($updateReservedQuantityQuery, $strParams);
Why always return null ?
ANSWER
Answered 2022-Mar-14 at 11:03You need to put the ifnull check on the outer query, not the inner, which can return no rows.
You can use coalesce here, such as:
UPDATE ps_stock_available sa
SET sa.reserved_quantity = coalesce((
SELECT SUM(od.product_quantity - od.product_quantity_refunded)
FROM ps_orders o
INNER JOIN ps_order_detail od ON od.id_order = o.id_order
INNER JOIN ps_order_state os ON os.id_order_state = o.current_state
WHERE o.id_shop = 1 AND
os.shipped != 1 AND (
o.valid = 1 OR (
os.id_order_state NOT IN ('6,28,59') AND
os.id_order_state NOT IN ('8')
)
) AND sa.id_product = od.product_id AND
sa.id_product_attribute = od.product_attribute_id
GROUP BY od.product_id, od.product_attribute_id
), 0)
WHERE sa.id_shop = 1 AND sa.id_product = 3374;
QUESTION
at prestashop 1.7 how could I access Configuration::get('PS_LAST_QTIES') at core.js?
Thank you, Miguel Gibert
ANSWER
Answered 2022-Mar-03 at 09:30I've sorted it out by passing the variable through the ProductController.php
at $this->ajaxRender(Tools::jsonEncode([
I added: 'ps_last_qties' => Configuration::get('PS_LAST_QTIES')
and then I received it at core.js: o.default.on("updatedProduct", function (e) {
and was able to use it as e.ps_last_qties
QUESTION
I am creating a module in Prestashop with Symfony but when I try to access my routes I get this error:
The controller for URI "/modules/youtuber/list" is not callable: Class "Myyoutubemc\Controller\YoutubeController"
Below is my controller it's located in: /modules/myyotubemc/src/controllers/youtubeController.php
render('@Modules/your-module/templates/admin/demo.html.twig');
}
public function listAction()
{
$em = $this->getDoctrine()->getManager();
$data = $em->getRepository(YoutubeComment::class)->findAll();
return $this->render(
'@Modules/myyoutubemc/templates/admin/list.html.twig',
[
'data' => $data
]
);
}
below is my routes located at my_module/config/routes.yml
youtube-list:
path: youtuber/list
methods: [GET]
defaults:
_controller: 'Myyoutubemc\Controller\YoutubeController::listAction'
ANSWER
Answered 2022-Mar-01 at 10:55You have to install composer or just dump autoload classes.
QUESTION
I build a site on prestashop with a child theme based on the classic theme. For my needs i've got a page for main categories with an hero section where i display the main category name, the cover image of the category, the sub-categories and a description. (see on the attached image)
Now i need to keep this section like that when i go to the sub-category page. Keep the title, image, sub-categories, etc. Just the content must change.
For now there is my code to display this hero section, located in the layout-left-column.tpl (to be before all the main content and after the header) :
{block name="hero_content"}
{if Tools::getValue('id_category') == 11 || 19 || 20 || 21 || 22 || 23}
{if $listing.pagination.items_shown_from == 1}
{$category.name}
{include file='catalog/_partials/subcategories.tpl'}
{$category.description nofilter}
{/if}
{/if}
{/block}
But as i expected when i go to a sub-category this section change with the informations of this sub-category.
How can i keep this section with the parent category informations ?
Ps: I tried to hit the function Category::getParentsCategories(), but nothing. And i'm working with Prestashop 1.7.8.3
Thank's for your time.
ANSWER
Answered 2022-Feb-28 at 14:42[UPDATE] Problem Solved
I finaly solved my problème with this topic : Prestashop subcategory parent
And with adaptations :
In a custom module class where i create a function :
public function hookDisplayHeaderCategory($params) {
if (isset($params['current_category']) && !empty($params['current_category'])) {
$id_lang = $this->context->language->id;
$parent_category = new Category((int) $params['current_category']);
$sub_categories = Category::getChildren((int) $params['current_category'], $id_lang);
if (Validate::isLoadedObject($parent_category)) {
$this->context->smarty->assign(array(
"parent_category" => $parent_category,
"parent_category_name" => $parent_category->name,
"parent_category_description" => $parent_category->description,
"sub_categories" => $sub_categories,
));
}
}
return $this->display(__FILE__, 'category_hero.tpl');
}
Create a view in this module with the hero section :
{$parent_category_name[1]}
{include file='catalog/_partials/subcategories.tpl' subcategories=$sub_categories}
{$parent_category_description[1] nofilter}
If it can help somebody in the same case.
QUESTION
I have a prestashop shop that uses social login. And a few days ago when the customer tries to log in this message appears.
You cannot login to this application because it does not comply with Google's OAuth 2.0 policy.
If you are the developer of the app, please register the redirect URI in the Google Cloud Console.
I have edited the redirect address, as I didn't have a secure link, I had the same address, but http instead of https.
I changed the address a few days ago, but I still get the same message and the old, unsecured address.
The message when changing the url indicated that it could take minutes or hours, but it has been several days and the address has not been updated.
Any idea? Thanks!
ANSWER
Answered 2022-Feb-21 at 10:59While using Google OAuth for OpenID login, you have 2 levels of configuring your redirect URI.
- Configure the allowed redirect URIs in your OAuth credentials screen in the Google cloud console.
- Configure the same redirect URI in your application which sends the authorization request. Your authorization request should comprise of the same redirect URI.
As you mentioned, you might have updated your OAuth credential redirect URIs in console, but your app might be sending authorization response with the old URL itself. So, it will get rejected.
And yes, make sure the URI is an exact match. AFAIK, even a trailing slash can create problems.
QUESTION
I'm new in prestashop and there is a thing that i don't understand.
I need to add a function that get a file CSV and stock all in a array. This function will be added in a exixsting Class in this path "/modules/sdevmanomano/classes/MyClass.php" Now i have to test the new function, and it the end of the class (out of the {}), i did a var_dump of my object.method(). When i go at the adress of file in my browser, i get nothing. (i m in the correct path). Why? Exemple:
/modules/sdevmanomano/classes/MyClass.php
if (!defined('_PS_VERSION_')) {
exit;
}
include_once(dirname(__FILE__) . '/OtherClass.php');
class MyClass
{
...
//Before execute the code i want check if he has open correctly the CSV in tmpName
private function getDeliveryPrices(){
$tmpName = fopen(dirname(dirname(__FILE__)) . '/prices/prezzi_spedizione_francia.csv', 'r');
if ($tmpName){
$csvAsArray = 'ok';
} else {
$csvAsArray = 'errore';
}
return $csvAsArray;
}
}
// end of class
$test = new MyClass();
$res = $test->getDeliveryPrice();
var_dump($res);
Normally at this point, at the adresse https:/.../modules/sdevmanomano/classes/MyClass.php i have to see my dump, but didn' happen. Why ?
ANSWER
Answered 2022-Feb-16 at 12:37Assuming you would want to use your php script outside a PrestaShop session within the module context, here is how you could require the PrestaShop configuration when on a stand-alone php script:
// /modules/sdevmanomano/classes/MyClass.php
/*
* Require the PrestaShop configuration
* relative to the location of this script
*/
reqire_once(dirname(__FILE__) . '../../../config/config.inc.php';
// Then you have access to _PS_VERSION_
if (!defined('_PS_VERSION_')) {
exit;
}
QUESTION
Any method to read Prestashop Cookies from Javascript ?
Context::getContext()->cookie
I try with
document.cookie
But can't acces to the prestashop Cookies, any idea please ?
ANSWER
Answered 2022-Feb-15 at 17:56You can get Cookie content in PHP and set into a template as JS variable.
You assign with PHP
$context->smarty->assign('yourData', $dataFromCookie);
and receive in your template file:
{addJsDef name=yourDataVar}{$yourData}{/addJsDef}
QUESTION
What I want to accomplish is for the form to change as the user changes the form type from the radio.
Standard basically has 2 selects (one classic and a fancier one, made with ng-select) and custom has a simple classic text input.
I am trying to change the form's functionality dynamically as the form type changes using the radio.
Besides trying to use formBuilder.group, I also tried using .setValidators on the individual inputs, but the result is the same: when I change the radio and the custom_channel_name input is shown i get this console error "Error: Cannot find control with name: 'custom_channel_name'"
What am I doing wrong and how do I properly handle reactive forms in this fashion?
What I have so far looks like this: https://i.imgur.com/n24mKs7.png , https://i.imgur.com/FfCgXFX.png
[ component.html ]
Channel
{{ channel }}
Countries
Custom Channel
Channel Type
Standard
Custom
Assign Channel
[ component.ts ]
export class OrganizationChannelsComponent implements OnInit {
selectChannelsSources: Array = ["eMag Marketplace", "Vtex", "Shopify", "Magento1", "Magento2", "WooCommerce", "Prestashop", "TeamShare", "Gomag", "Opencart", "MerchantPro", "Cscart", "Allegro", "Idosell", "ChannelAdvisor", "Shoprenter", "Transfer", "Defecte/Defects", "Manual Order"];
selectCountriesSources: Array = [];
icons = {
close: faTimes,
plus: faPlus
}
organizationChannelForm!: FormGroup;
selectedCountries: Array = [];
selectedChannel: Channel | undefined;
isChannelTypeStandard: boolean = true;
@Input() organizationId!: ID;
organizationChannels$: Observable = new BehaviorSubject([]);
channels$: Observable = new BehaviorSubject([]);
constructor(
private organizationChannelsService: OrganizationsChannelsService,
private organizationChannelsQuery: OrganizationChannelsQuery,
private countriesService: CountriesService,
private toasterService: ToasterService,
private formBuilder: FormBuilder,
) { }
ngOnInit(): void {
this.organizationChannelForm = this.formBuilder.group({
channel_id: ['', Validators.required],
});
this.organizationChannelsService.getOrganizationChannels(this.organizationId).subscribe();
this.organizationChannels$ = this.organizationChannelsQuery.selectOrganizationChannels(this.organizationId as number);
this.countriesService.get().subscribe(countries => this.selectCountriesSources = countries);
}
updateOrganizationChannelForm() {
if (this.isChannelTypeStandard) {
this.organizationChannelForm = this.formBuilder.group({
channel_id: ['', Validators.required],
});
}
else {
this.organizationChannelForm = this.formBuilder.group({
custom_channel_name: [Validators.required, Validators.minLength(8)]
});
}
}
}
ANSWER
Answered 2022-Jan-27 at 18:25Documentation to the rescue! here is the official link to creating dynamic forms: https://angular.io/guide/reactive-forms#creating-dynamic-forms
basically you need formArray instead of formGroup for all the controls that are going to be conditionally visible on UI, read the docs and if it becomes difficult to understand then let me know I'll create a demo.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PrestaShop
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page