How to add escpos-php in magento? - magento-1.9.1

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';

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"?

Can't find static assets from express/npm module

tldr;
My project is an NPM module that is used by an ExpressJS server. The server needs to specify an endpoint and my module will do the rest. How do I get my module to load the correct html page and grab the correct js/css files from the correct path?
The Problem
I'm running into a problem where I can see the directory structure of the site, using the serveIndex library, and all the files are in their correct directories but for some reason when I try to load any of the files, whether from the serveIndex view or from the actual endpoint where it should load, I get nothing but 404 errors.
Here's an example if someone wanted to use this NPM module from their project.
app.js (their server)
const express = require('express')
const { adminAreaConfig } = require('express-admin-area')
const app = express()
const adminArea = adminAreaConfig(express) // my module being passed the "express" library
app.use('/admin', adminArea) // specify a URL to use my module
app.listen(3000, () => console.log('\n\nServer Online\n\n'))
Here's an image of my projects dir structure after it's been built.
Going off of a console.log(__dirname), which returns <long path string>/express-admin-area/build/src, I then tell my module, using the express reference passed by the actual server in the code above, to look in the views directory with
... import libraries etc ...
const adminAreaConfig = express => {
const adminArea = express.Router()
adminArea.use('/', express.static(__dirname + '/views') // sets my modules views to the "http://localhost:3000/admin" path
adminArea.use('/dirs', serveIndex(__dirname)) // will get into this later
... some other stuff like exports etc ...
This then attempts to load the index.html file in the express-admin-area/build/src/views directory but fails because it can't locate the CSS and JS files inside express-admin-area/build/src/views/static/css or .../js.
First, I know it fails because instead of looking for http://localhost:3000/admin/static/css/styles.css it looks for http://localhost:3000/static/css/styles.css, so that's another problem I need to solve entirely.
Second, looking back at the small code sample above, adminArea.use('/dirs', serveIndex(__dirname)), I'm using the serveIndex library in an attempt to view the directory structure. If I go to http://localhost:3000/admin/dirs I get the correct directories and files in the browser
But now, if I try to view an actual file I'm met with the error Cannot GET /admin/dir/main.js for example if I were to go to http://localhost:3000/admin/dir/main.js, but I can continue going deeper in the directories if I wanted such as the controllers or routes directories from the image.
What I want
I need a way to get these static assets to load. If I point my module to a basic html page with a simple <h1>Hello, World!</h1> then that's what Ill get but trying to load any outside scripts/stylesheets is when I get the 404 errors and nothing loads.
I'll be answering my own question.
The solution is actually pretty simple. The view layer of this module is handled by React, CRA to be specific. CRA will look for some specific environment variables, one of them being PUBLIC_URL. All I had to do was
Create a .env file in the root directory of my CRA
add PUBLIC_URL="/admin"
Afterward, it's just rebuilding the project, yarn build, and reset the server. CRA will then look at http://localhost:3000/admin/static/... instead of http://localhost:3000/static/... for static assets.

How add auto update functionality to prestashop plugin

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
}
?>

Ploblem including a file- Titanium

I get an error while i try to include the js file which is in the same folder. I tried cleaning my project but was of no use.
The console says "error loading path".
Please help.
var db={}
Titanium.include('windows/gallery');
var displayButton= Ti.UI.createButton({
title:'Display',
onClick:function(){
db.gallery.open();
}
});
I have used open function which opens the file. The open file works has no problem.
usually, we use require('files/myFile'), where :
Resources/files/myFile.js is the path (note that require doesn't use the .js)
The js file is NOT at the same level that app.js, but included in Resource folder.
So here, you should do
Titanium.require('windows/gallery');
instead of
Titanium.include('windows/gallery');
By the way, the previous method was Titanium.include('windows/gallery.js');
Note the .js at the end of the include version.
Is it a mobile or desktop version ?