How add auto update functionality to prestashop plugin - module

I've create my first plugin for prestashop. I want to add autoupdate functionality for autoupdate as do for example eBay module.
I did not found anything about that on documentation.

I've been struggeling to figure out the correct process for this for a while.
I thought the "upgrade it" button was only available for developers, who release their modules through the prestashop addons website (which is true) but if you chose not to publish there, here's how you update your own modules:
In the main file of your model, within the contructor method, you must have this line of code:
$this->version = '1.0.0';
make a subdirectory in your module folder called upgrade
create a new file in this directory called install-1.0.1.php
put this code in the file:
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_0_1($object, $install = false)
{
//your code here, for example changes to the DB...
return true; //if there were no errors
}
?>
In your main file, change it to $this->version = '1.0.1';
Create a zip file of your module folder
Navigate to the Modules page on your stores back end, and say "upload new module"
Upload the zip file
Now you should see 2 messages:
The module was successfully downloaded.
and
The following module(s) were upgraded successfully:
MyModule :
Current version: 1.0.1
1 file upgrade applied

Prestashop Documentation.
You can also add an update file to your module: create an /upgrade folder in your module's folder, and put your update files in it, using the install-1.8.0.php name norm.
<?php
// Sample file for module update
if (!defined('_PS_VERSION_'))
exit;
// object module ($this) available
function upgrade_module_1_8_0($object)
{
// Your code to upgrade from version 1.8.0 of the module
}
?>

Related

How to work with mulitple annotation folder in latest version of darkaonline/l5-swagger?

It was working perfectly with multiple annotation folders in laravel 8.0, forgot the minor version of l5-swagger. Later when I do composer update and darkoline get updated to ^8.3 version. Now, its trying to make documentation(#SchemaRef) out of each file stored inside the folder. I do have following configuration
/*
* Absolute paths to directory containing the swagger annotations are stored.
*/
annotations' => [
base_path('app'),
base_path('Modules'),
]
In my case I do have following error
ErrorException
Skipping unknown \CreateRolesTable
Here CretaetRolesTable is a migration file inside Modules folder, no swagger related annotation exists in CreateRolesTable file and neither this name is being used as #ref.
You should use the anonymous function in CreateRolesTable file.
return new class extends Migration
For more information check the official documentation.(see more)

How do I solve fusionauth php client error 'FusionAuthClient' not found?

when I follow https://github.com/FusionAuth/fusionauth-php-client
I can see error:
PHP Fatal error: Uncaught Error: Class 'FusionAuthClient' not found ... on line 6
My application looks like this:
First application
<?php
require_once 'FusionAuthClient.php';
$apiKey = "7W-yBfeXfniDhu8PR_h0dGkSsPDJlpUYuP9rP2xXd_4";
$client = new FusionAuthClient($apiKey, "http://localhost:9011");
line 6 is last.
composer says all is right
$ composer require fusionauth/fusionauth-client
Using version ^1.6 for fusionauth/fusionauth-client
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing fusionauth/fusionauth-client (1.6.1)
Downloading: 100%
Writing lock file
Generating autoload files
FusionAuthClient.php, ClientResponse.php and RESTClient.php are in the same directory as my test script.
Can you point me into the right direction what is cause of this problem?
Have you looked at the first line of the FusionAuthClient.php file? apparently not.
namespace FusionAuth;
Therefore, the class is not in the global namespace, therefore you need to tell php which namespace it's in:
$client = new FusionAuth\FusionAuthClient($apiKey, "http://localhost:9011");
You're welcome.
That looks the require_once function path is invalid
Do have you same bug when using "require" and not "require_once"?

How to add escpos-php in magento?

I am working with magento 1.9. I want to use the escpos-php driver to print our invoices to the usb thermal printer. I have kept the escpos-php libraries in the root directory of my magento installation. In a custom module of magento, I have overwritten the default invoices which was A4 pdf when rendered and I tried to make a thermal invoice pdf (paper size C7). This file exists at /local/Receipt/Pos/Model/Invoice.php
<?php
class Receipt_Pos_Model_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
{
public function getPdf($invoices = array())
{
// I want to access the libraries from here in this
// function like shown below. where 'vendor' is a directory
// created by myself.
require(Mage::getBaseDir('lib') .'/vendor/mike42/escpos-php/autoload.php'); // this is the autoloader that comes with escpos-php driver.
use Mike42\Escpos\PrintConnectors\FilePrintConnector; // Warning is raised at this line.
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
}
}
?>
What am I trying now is, I want to access the class files of the escpos-php driver from this /local/Receipt/Pos/Model/Invoice.php file. So I have added the absolute path of the escpos-php driver's autoloader to the code in Invoice.php but it results in a warning like the one below
Warning: include(Mike42\Escpos\PrintConnectors\PrintConnector.php): failed to open stream: No such file or directory in /var/www/html/checkout/Gama_V2/shop/lib/Varien/Autoload.php on line 94
I think the autoloader of Magento is also trying to find the class files of the escpos-php driver and fails to load it. But I don't want the magento autoloader work here because, I have already included the autoloader of escpos-php driver which takes care of loading its files. How can I avoid this warning and proceed to print receipts? Please help me!
To make autoload recognize your external library you will have to follow magento file structure.
External Libraries use to be located under /lib/
in your module you may use them as
require_once Mage::getBaseDir('lib') . '/Mike42/Escpos/Whatever.php';

Opencart vqmod 2.3.0.2 $config error

i have just installed opencart 2.3.0.2 and vqmod but i am facing a problem now. In previous version of opencart when i was using the below code in vqmod xml file
global $config;
$variableA = $config->get('field_value');
then in $variableA i got the value which i saved in the db from admin section but now in 2.3.0.2 when i use this code it shows fatal error
Fatal error: Call to a member function get() on null
please tell me how can i get the value in vqmod xml file so i can use this variable further
Thanks
Define the variable in a file controller first:
$data['variableA'] = $this->config->get('variableA');
then (for example) echo the variable in a view file:
<?php echo $variableA; ?>

How can I override a react-beautify setting in VSCode?

I have a React Native project. In Visual Studio Code, I use the react-beautify add-in to beautify my code on the fly. The add-in uses a tool named prettydiff internally.
The only thing it does that I don't like is that it condenses
import { Componentname } from packagename
to
import {Componentname} from packagename
The correct prettydiff setting to change this behaviour is to set brace_style to collapse-preserve-inline.
However, I can't get prettydiff to accept the change.
I tried creating a .jsbeautifyrc file in my project's root directory, and added:
{
"brace_style": "collapse-preserve-inline"
}
but this doesn't seem to work: the behaviour I don't want is still happening.
How do I do this correctly?
I have VS Code in Mac v1.8.1 and if you open a Folder with a .jsbeautifyrc you could override the properties, in your example if you create a folder with 2 files:
index.js
import {code} from 'source';
import {otherCode} from 'source';
.jsbeautifyrc
{
"bracepadding": true
}
you will get the next result after run the beautifier:
import { code } from 'source';
import { otherCode } from 'source';
Yes there is a bug,the .jsbeautifyrc file doesn't seem to be read in the react-beautify add-in.
The settings mentioned during the setup of the addon don't seem to work and also I have tried installing prettydiff in my system and also the esformatter-jsx and changed the configuration but it doesn't read the files
Workaround
You can try the beautify add-in with the following repo here.
and add the file .jsbeautifyrc to your file tree structure ,and the options mentioned in the settings page work in it.
The project has been updated to the latest js-beautify code version 1.6.8 with the support of the jsx support as mentioned in the screen shot
and also the working example