Error when I run compile in Magento 2 - magento2

I have a problem when I run compile
I get this error
Errors during compilation:
Ortho\Theme\Block\Html\Custommenu
Incorrect dependency in class Ortho\Theme\Block\Html\Custommenu in /var/www/vhosts/domux.eu/dmx/app/code/Ortho/Theme/Block/Html/Custommenu.php
\Magento\Store\Model\StoreManagerInterface already exists in context object
Total Errors Count: 1
Can someone please tell me what code I have to remove or modify from this php file ?
public function __construct(
Template\Context $context,
NodeFactory $nodeFactory,
TreeFactory $treeFactory,
CategoryFactory $categoryFactory,
\Magento\Cms\Model\Template\FilterProvider $filterProvider,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Cms\Model\BlockFactory $blockFactory,
Registry $registry,
\Ortho\Theme\Helper\Data $dataHelper,
array $data = []
) {
parent::__construct($context,$nodeFactory,$treeFactory, $data);
$this->categoryFactory = $categoryFactory;
$this->_filterProvider = $filterProvider;
$this->_storeManager = $storeManager;
$this->_blockFactory = $blockFactory;
$this->coreRegistry = $registry;
// $this->dataHelper = $dataHelper;
//$this->_menu = $this->getMenu();
$this->nodeFactory = $nodeFactory;
$this->treeFactory = $treeFactory;
}
/**
* Get block cache life time
*
* #return int
*/
protected function getCacheLifetime()
{
return parent::getCacheLifetime() ?: 3600;
}
Thank you a lot.
best regards

Please see https://magento.stackexchange.com/questions/172655/magento-2-1-errors-during-compilation-incorrect-dependency-in-class.
You have here all explanation and how to solve it.

Related

Magento2 Custom Quote PDF Incorect Currency Symbol Need to add Quote currency code?

I have Created a save quote extension for one of my clients every thing is working fine
But when a customer print a pdf Quote its show the POUND symbol instead of showing the quote currency code EURO My code is given below I have tried many ways to add currency code but it is not working
public function __construct(
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Filesystem $filesystem,
Config $pdfConfig,
\Magento\Sales\Model\Order\Pdf\Total\Factory $pdfTotalFactory,
\Magento\Sales\Model\Order\Pdf\ItemsFactory $pdfItemsFactory,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
AddressQuoteRenderer $addressQuoteRenderer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Store\Model\App\Emulation $appEmulation,
\Magento\Framework\Pricing\Helper\Data $helper,
OrderFactory $orderFactory,
array $data = []
) {
$this->orderFactory = $orderFactory;
$this->addressQuoteRenderer = $addressQuoteRenderer;
$this->helper = $helper;
$this->_appEmulation = $appEmulation;
parent::__construct(
$paymentData,
$string,
$scopeConfig,
$filesystem,
$pdfConfig,
$pdfTotalFactory,
$pdfItemsFactory,
$localeDate,
$inlineTranslation,
$addressRenderer,
$storeManager,
$appEmulation,
$data
);
}
/**
* Return PDF document
*
* #param Collection $quotes
*
* #return \Zend_Pdf
* #throws \Magento\Framework\Exception\LocalizedException
* #throws \Zend_Pdf_Exception
*/
public function getPdf($quotes = [])
{
$this->_beforeGetPdf();
$this->_initRenderer('order');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$order = $this->orderFactory->create();
foreach ($quotes as $quote) {
if ($quote->getStoreId()) {
$this->_appEmulation->startEnvironmentEmulation($quote->getStoreId());
$this->_storeManager->setCurrentStore($quote->getStoreId());
}
$page = $this->newPage();
$this->_setFontBold($page, 10);
$quote->setQuote($quote);
/* Add image */
$this->insertLogo($page, $quote->getStore());
/* Add address */
$this->insertAddress($page, $quote->getStore());
/* Add head */
$this->insertOrder($page, $quote, false);
/* Add table */
$this->_drawHeader($page);
$this->_initRenderer('default');
/* Add body */
$taxTotal = 0;
foreach ($quote->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
/* Keep it compatible with the invoice */
$item->setQty($item->getQty());
$item->setProductType($item->getProduct()->getTypeId());
$this->_initRenderer($item->getProduct()->getTypeId());
$item->setOrderItem($item);
$taxTotal += $item->getTaxAmount();
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$order->setStoreId($quote->getStoreId());
$order->setSubtotal($quote->getSubtotal());
$order->setGrandTotal($quote->getSubtotal() + $taxTotal);
$order->setShippingAmount($quote->getShippingAddress()->getShippingAmount());
$order->setTaxAmount($taxTotal);
$order->setOrder($order);
$this->insertTotals($page, $order);
if ($quote->getStoreId()) {
$this->_appEmulation->stopEnvironmentEmulation();
}
Please Help and suggest to me where I am wrong I am stuck in this problem
Thanks for your help in advance

trying to do email confirmation after user registration and getting error "Class 'App\Http\Middleware\Auth' not found

Here is my VerifyUserbyEmail custom middle-ware
Can any one please help to sort it out ?
while I have used namespace properly but still getting error
<?php
namespace App\Http\Middleware;
use App\Http\Middleware\Auth;
use Closure;
class VerifyUserbyEmail
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
$user = \App\User::findOrFail(Auth::id());
if ($user->status == 0){
Auth::logout();
return redirect('login')->with('messege', 'you need to verify your account, check your email');
}
return $next($request);
}
}
Try changing
use App\Http\Middleware\Auth;
with
use Illuminate\Support\Facades\Auth;

Symfony createView causes error

I am using Symfony 3.3.10
I have the following code
/**
* #Route("/meta/edit/{metaId}", name="edit_price_meta_data")
*/
public function editMetaAction(Request $request,ItemPriceMeta $metaId)
{
$metaDataForm = $this->createForm("ItemBundle\Form\ItemPriceMetaType");
$data = [
'metaData'=>$metaId,
'metaDataForm'=>$metaDataForm->createView(),
];
return $this->render("#Item/Prices/Manage/editMetaData.html.twig",$data);
}
It produces the following error.
Error: Maximum execution time of 60 seconds exceeded
in vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php (line 2513)
public function createEntity($className, array $data, &$hints = array()){
$class = $this->em->getClassMetadata($className);
//$isReadOnly = isset($hints[Query::HINT_READ_ONLY])
$id = $this->identifierFlattener->flattenIdentifier($class, $data);
$idHash = implode(' ', $id);
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
$entity = $this->identityMap[$class->rootEntityName][$idHash];
$oid = spl_object_hash($entity);
The actual line highlighted as causing the error is $id = $this->identifierFlattener->flattenIdentifier($class, $data);
Removing 'metaDataForm'=>$metaDataForm->createView(), from my array, removes the error, so it seems to be the rendering of the form that is causing the error.
Increase PHP memory usage in php.ini

how to: use Tx_Extbase_Domain_Repository_FrontendUserRepository in typo3 v4.5

I am trying to read the username of a front end user whose uid is known. I tried this in my controller's showAction method:
$objectManger = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// get repository
$repository = $objectManger->get('Tx_Extbase_Domain_Repository_FrontendUserRepository ');
$newObject = $repository->findByUid($coupon->getCreator()); //this is the uid of whoever was loggin in
print_r($newObject);
echo $newObject->getUsername(); die;
but when that code runs I get:
Oops, an error occured!
"Tx_Extbase_Domain_Repository_FrontendUserRepository " is not a valid cache entry identifier.
It turns out that $repository is empty, so how do I get fe_user data?
I am using typo3 v4.5 with extbase.
Thanks
Update to show complete answer.
This is the code (it goes in my CouponController) that worked (plus the typoscript mentioned):
/**
* #var Tx_Extbase_Domain_Repository_FrontendUserRepository
*/
protected $userRepository;
/**
* Inject the user repository
* #param Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository
* #return void */
public function injectFrontendUserRepository(Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository) {
$this->userRepository = $userRepository;
}
public function showAction(Tx_Coupons_Domain_Model_Coupon $coupon) {
$userRepository = $this->objectManager->get("Tx_Extbase_Domain_Repository_FrontendUserRepository");
$newObject = $userRepository->findByUid($coupon->getCreator());
$this->view->assign('coupon', $coupon);
$this->view->assign('creatorname', $newObject->getUsername() );
}
If you are using extbase yourself you dont have to call makeInstance for your objectManager, it's already there ($this->objectManager).
anyway, you should inject this repository (see my answer here: TYPO3 - Call another repository)
Clear the Cache after the Injection.
You maybe have to disable the recordtype extbase sets for its FrontendUser:
config.tx_extbase.persistence.classes.Tx_Extbase_Domain_Model_FrontendUser.mapping.recordType >
Set the source storage pid where the repository fetches the data from:
/** #var Tx_Extbase_Domain_Repository_FrontendUserRepository $repos */
$repos = $this->objectManager->get("Tx_Extbase_Domain_Repository_FrontendUserRepository");
$querySettings = $repos->createQuery()->getQuerySettings();
$querySettings->setStoragePageIds(array(123, 567));
$repos->setDefaultQuerySettings($querySettings);
$user = $repos->findByUid(56); // Queries for user 56 in storages 123 and 567

Zend Enable SQL Query logging

I am using this to retrieve the database connection atm.
$db = Zend_Db_Table::getDefaultAdapter();
I do set this up in my config like this:
resources.db.adapter = pdo_mysql
resources.db.isDefaultTableAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = password
resources.db.params.dbname = db
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler
I would like to output everything to a sql.log for example. Is this possible to apply on the default adapter? for example through the settings, so I can ignore it in production environment?
Much appriciated.
I did look at: How to enable SQL output to log file with Zend_Db? but it didn't seem to cover my issue.
/Marcus
There is an example of extending Zend_Db_Profiler so you can write the queries to /logs/db-queries.log file.
So you have to do the following:
Create My_Db_Profiler_Log class in the library folder
Add the following lines to the application.ini
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = My_Db_Profiler_Log
Note: be aware, that the log file will become very big, very soon! So it is a good idea to log only the queries you are interested in. And this example should be considered only as a starting point in implementation of such a logging system.
Here is the code for the custom profiler class:
<?php
class My_Db_Profiler_Log extends Zend_Db_Profiler {
/**
* Zend_Log instance
* #var Zend_Log
*/
protected $_log;
/**
* counter of the total elapsed time
* #var double
*/
protected $_totalElapsedTime;
public function __construct($enabled = false) {
parent::__construct($enabled);
$this->_log = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/logs/db-queries.log');
$this->_log->addWriter($writer);
}
/**
* Intercept the query end and log the profiling data.
*
* #param integer $queryId
* #throws Zend_Db_Profiler_Exception
* #return void
*/
public function queryEnd($queryId) {
$state = parent::queryEnd($queryId);
if (!$this->getEnabled() || $state == self::IGNORED) {
return;
}
// get profile of the current query
$profile = $this->getQueryProfile($queryId);
// update totalElapsedTime counter
$this->_totalElapsedTime += $profile->getElapsedSecs();
// create the message to be logged
$message = "\r\nElapsed Secs: " . round($profile->getElapsedSecs(), 5) . "\r\n";
$message .= "Query: " . $profile->getQuery() . "\r\n";
// log the message as INFO message
$this->_log->info($message);
}
}
?>
Extend the Zend_Db_Profiler to write to an SQL.log and attach the profiler to your db adapter
<?php
class File_Profiler extends Zend_Db_Profiler {
/**
* The filename to save the queries
*
* #var string
*/
protected $_filename;
/**
* The file handle
*
* #var resource
*/
protected $_handle = null;
/**
* Class constructor
*
* #param string $filename
*/
public function __construct( $filename ) {
$this->_filename = $filename;
}
/**
* Change the profiler status. If the profiler is not enabled no
* query will be written to the destination file
*
* #param boolean $enabled
*/
public function setEnabled( $enabled ) {
parent::setEnabled($enabled);
if( $this->getEnabled() ) {
if( !$this->_handle ) {
if( !($this->_handle = #fopen($this->_filename, "a")) ) {
throw new Exception("Unable to open filename {$this->_filename} for query profiling");
}
}
}
else {
if( $this->_handle ) {
#fclose($this->_handle);
}
}
}
/**
* Intercept parent::queryEnd to catch the query and write it to a file
*
* #param int $queryId
*/
public function queryEnd($queryId) {
$state = parent::queryEnd($queryId);
if(!$this->getEnabled() || $state == self::IGNORED) {
return;
}
$profile = $this->getQueryProfile($queryId);
#fwrite($this->_handle, round($profile->getElapsedSecs(),5) . " " . $profile->getQuery() . " " . ($params=$profile->getQueryParams())?$params:null);
}
}
Haven't test it, but it should do the trick. Give it a try and let me know.
Btw you do know that you can log all queries on the mysql as well?
this will let you see sql queries to the web page , IT MIGHT BE OFF TOPIC but it helpful
I am highly recommend you to use ZF debug bar , it will give you very handy information
i am using it to see my doctrine queries , and it had support for zend db too
https://github.com/jokkedk/ZFDebug