I'm receiving this message error - Warning: array_merge(): Argument #1 is not an array in - arguments

In this line i found this:
The line of this problem is themify-shoppe/admin/post-type-product.php on line 731:
/**
* Add woocommerce_enable_ajax_add_to_cart option to JS
* #param Array
* #return Array
*/
function themify_woocommerce_params($params){
return array_merge($params, array(
"option_ajax_add_to_cart" => ('yes'== get_option('woocommerce_enable_ajax_add_to_cart') )? 'yes': 'no'
) );
}

Replace that code with this:
/**
* Add woocommerce_enable_ajax_add_to_cart option to JS
* #param Array
* #return Array
*/
function themify_woocommerce_params($params){
if(is_array($params)){
return array_merge($params, array(
'option_ajax_add_to_cart' => ( 'yes' == get_option('woocommerce_enable_ajax_add_to_cart') )? 'yes': 'no'
) );
}else{
return array(
'option_ajax_add_to_cart' => ( 'yes' == get_option('woocommerce_enable_ajax_add_to_cart') )? 'yes': 'no'
);
}
}
Edit this code in Themify by going to your WP Dashboard -> Appearance -> Editor -> theme_functions.php
Visit debugman.in to know more about it.

Related

Unable to post data

Hello, it is a very important project for me. I wrote an api and I want to pull data from 2 different sites with this api. While you can pull healthy data from one site, empty results are returned due to captcha from the other site. Now I scraped data from the same site before using pyhton selenium, bs4, but I can't scrape it with laravel api. I'm testing this info from postman.
The solution of the captcha is to combine my pyhton file, which I have provided, with my laravel api file, if possible, by converting the captcha to audio and then to text, which skips this part.
Another method is to write a pyhton service that can work with the captcha(pyhton) file.
The last and actually the most useful method for me if I can provide action is to skip captcha with my laravel service without entering the captcha event. I tried skipping by changing the cookie, but it was a very tiring and unhealthy method. I want to trick some kind of captcha here.
<?php
namespace App\Services\Mde;
use App\Core\ServiceResponse;
use App\Interfaces\IPricePredictionService;
class PricePredictionService extends BaseMDeService implements IPricePredictionService
{
/**
* #param mixed $brand
* #param mixed $model
* #param mixed $kilometerFrom
* #param mixed $kilometerTo
* #param mixed $yearFrom
* #param mixed $yearTo
* #param mixed $fuelTypes
* #param mixed $gearBoxes
* #param mixed $powerFrom
* #param mixed $powerTo
*
* #return ServiceResponse
*/
public function getByParameters(
$brand,
$model,
$kilometerFrom,
$kilometerTo,
$yearFrom,
$yearTo,
$fuelTypes,
$gearBoxes,
$powerFrom,
$powerTo
): ServiceResponse
{
$endpoint = $this->baseUrl . '&ms=' . $brand . '%3B' . $model;
$priceList = [];
for ($pageCounter = 1; $pageCounter <= 50; $pageCounter++) {
$parameters = [
'ml' => $kilometerFrom,
'ml%3A' => $kilometerTo, // duzelt
'fr' => $yearFrom, // duzelt
'fr%3A' => $yearTo, // duzelt
'fuel' => implode(' ', $fuelTypes), //ft=DIESEL
'gear' => implode(' ', $gearBoxes), //tr=MANUAL_GEAR
'powertype' => 'kw',
'pw' => $powerFrom, // duzelt
'pw%3A' => $powerTo, // duzelt
'page' => $pageCounter,
];
$response = $this->client->get($endpoint . '?' . http_build_query($parameters), [
'headers' => [
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
//'Accept' => 'application/json',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' //,
],
]);
$clean1 = str_replace(["\n", "\t", "\r", " "], null, $response->getBody()->getContents());
$clean2 = str_replace(["""], null, $clean1);
$clean3 = preg_replace('~{(.*?)}~', null, $clean2);
$cleanResult = preg_replace('~{(.*?)}~', null, $clean3);
preg_match_all('~<a class="link--muted no--text--decoration result-item" (.*?)</a>~', $cleanResult, $articles);
//return $lists; // bos geliyor.
if ($articles[1]) {
foreach ($articles[1] as $article) {
preg_match('~<span class="h3 u-block" .*?>(.*?)</p>~', $article, $priceObject);
$priceWithCurrency = str_replace(',-', null, $priceObject[1]);
$priceWithoutCurrency = explode(' ', $priceWithCurrency)[1];
$price = intval(str_replace('.', null, $priceWithoutCurrency));
$priceList[] = $price;
}
}
}
$averagePrice = array_sum($priceList) / count($priceList);
return new ServiceResponse(
true,
'Average price calculated successfully.',
200,
intval($averagePrice)
);
}
}
I don't insist that these methods are just the ones that come to my mind, I want to proceed in this way, I just want to provide fast and practical transactions whenever possible. I'm sorry if I said something illogical and wrong. But I desperately need the ideas and guidance you will convey to me. Thank you from now. I'm also adding my api codes in case you want to take a look.
The controller class is below.
```
<?php
namespace App\Http\Controllers\Api\M;
use App\Core\Controller;
use App\Core\HttpResponse;
use App\Http\Requests\Api\M\PricePredictionController\CheckRequest;
use App\Interfaces\IPricePredictionService_M;
class PricePredictionController extends Controller
{
use HttpResponse;
/**
* #var $mService
*/
private $mService;
public function __construct(IPricePredictionService_M $mService)
{
$this->mService = $mService;
}
/**
* #param CheckRequest $request
*/
public function check(CheckRequest $request)
{
$response = $this->mService->getByParameters(
$request->brand_and_model,
$request->kilometerFrom_kilometerTo,
$request->yearFrom_yearTo,
$request->fuelTypes ?? [],
$request->gearBoxes ?? [],
$request->powerFrom_powerTo,
$request->country,
$request->bodyType,
$request->doors
);
return $this->httpResponse(
$response->getMessage(),
$response->getStatusCode(),
$response->getData(),
$response->isSuccess()
);
}
}
> The interfaces class is below.
```
<?php
namespace App\Interfaces;
use App\Core\ServiceResponse;
interface IPricePredictionService_M
{
/**
* #param mixed $brand_and_model
* #param $kilometerFrom_kilometerTo
* #param mixed $yearFrom_yearTo
* #param mixed $fuelTypes
* #param mixed $gearBoxes
* #param mixed $powerFrom_powerTo
* #param mixed $country
* #param mixed $bodyType
* #param mixed $doors
*
* #return ServiceResponse
*/
public function getByParameters(
$brand_and_model,
$kilometerFrom_kilometerTo,
$yearFrom_yearTo,
$fuelTypes,
$gearBoxes,
$powerFrom_powerTo,
$country,
$bodyType,
$doors
): ServiceResponse;
}

How to assert mockery shouldReceive

I'm trying to implement middleware unit test using Mockery
public function handle() {
// create user
$user = factory(User::class)->create();
// log in as admin user
$this->be($user, 'api');
$response = \Mockery::mock('Illuminate\Http\JsonResponse')->shouldReceive('getContent', 'setData')->once()->andReturn(json_encode(['data' => [], 'meta' => []]))->getMock();
$request = Request::create('/admin/customers', 'GET');
$middlewareResponse = $this->middleware->handle($request, function () use ($response) {
return $response;
});
print_r($middlewareResponse); exit;
}
How can I get setData and perform assertion?
here is the middlewareResponse
[_mockery_receivedMethodCalls:protected] => Mockery\ReceivedMethodCalls Object
(
[methodCalls:Mockery\ReceivedMethodCalls:private] => Array
(
[0] => Mockery\MethodCall Object
(
[method:Mockery\MethodCall:private] => getContent
[args:Mockery\MethodCall:private] => Array
(
)
)
[1] => Mockery\MethodCall Object
(
[method:Mockery\MethodCall:private] => setData
[args:Mockery\MethodCall:private] => Array
(
[0] => Array
(
[data] => Array
(
)
[meta] => Array
(
[home] => /customer/test/dashboard/consectetur-architecto-nostrum
)
)
)
)
)
)
Here is my HomePage middleware
class HomePage
{
/**
* Handle an incoming request.
*
* #param Request $request
* #param Closure $next
* #return mixed
*/
public function handle($request, Closure $next) {
// get original response
$response = $next($request);
$responseData = json_decode($response->getContent(), true);
$data['meta'] = [
'home' => null,
];
//print_r($response);exit;
if($response instanceof JsonResponse) {
// get banner meta data
$data['meta'] = $this->getHomePageUrl();
}
// merge meta data into original
$payloadWithMeta = array_merge_recursive($responseData, $data);
$response->setData($payloadWithMeta);
return $response;
}
/**
* generate dashboard url for user's first customer of first profile
*
* #return array
*/
private function getHomePageUrl() {
// first initialise an empty profile
$profile = null;
// fetch user's first customer
$user = Auth::user();
$customer = $user->customers()->orderBy('title')->first();
// set profile if customer found
if($customer) {
$customer->activateDatabase();
$profile = Profile::orderBy('title')->first();
}
return [
'home' => $profile ? 'customer/settings' : null
];
}
}
``

Change item ordering in sonata_type_model

In my Admin I'v defined this:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
/* ... */
->add('camps', 'sonata_type_model', array(
'btn_add' => false, //Specify a custom label
'choices' => $this->tema_service->getCampsDefinicio($this->getSubject()),
'sortable' => true,
'multiple' => true,
), array(
'placeholder' => 'No selected'
))
;
/* ... */
}
Function getCampsDefinicio returns an array of items ordered. Inspite of it, the options appear sorted according its id.
What can I do to get it respect the order given?
It does not care if I have to override any template. In that case which files I have to look for/override?
Finally I solved this.
I was a little confused.
The order in the choises array is respected only for selectionable items.
The order for the SELECTED items is defined by te ArrayCollection provided in the entity function
/**
* Get camps
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCamps()
{
return $this->camps;
}

Symfony2 validate text input when containing something only

I want to validate a form which holds a dropdown menu and a text input field.
The user can choose a project from the dropdown menu. If he wants to create a new project he can use the text input field next to the dropdown menu.
Here is my upload type:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->setAction('upload')
->setMethod('POST')
// project name dropdown menu
->add('projectname', 'choice' , array(
'label' => 'upload_project_label',
'choices' => $this->projects,
'attr' => array(
'class' => 'form-control some',
'required' => 'true'
)
))
// newprojectname text input
->add('newprojectname', 'text', array(
'label' => false,
'attr' => array(
'class' => 'form-control',
'required' => false,
'placeholder' => 'upload_newprojectname_placeholder'
)
)
)
...
And this is a snippet from my upload entity:
/**
* #ORM\Column(type="text")
*
* #var string $projectname
* #Assert\NotBlank()
*/
protected $projectname;
/**
* #ORM\Column(type="text")
*
* #var string $newprojectname
* #Assert\Length(
* min = 3,
* max = 7,
* minMessage = "min message",
* maxMessage = "max message"
* )
*/
protected $newprojectname;
My question is is there a possibility of a query to check if the field newproject is set (i.e. a string is entered)? And if so let the Assert annotation do its job.
This can be done a number of ways, all of which will likely satisfy your requirements.
Use a custom callback - this is the quickest and most straightforward
Use an expression validator - a lot of people have issues with embedding a meta-language within PHP which is perfectly valid but this is another quick-ish way of doing things
Use group sequences, specifically the group sequence provider functionality
Which one you choose is up to you but callbacks are a quick and easy starting point that you can build on if your validation constraints become more complex.
This is the code block for advised solution as custom callback validation.
I had to add another function in my upload entity which looks like this:
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Function holds custom validation for fields in import/upload form
* #Assert\Callback
* #param ExecutionContextInterface $context
*/
public function validate(ExecutionContextInterface $context)
{
// check new project name
$newProjectName = $this->getNewprojectname();
if(!empty($newProjectName)) {
// letters only
$pattern = '/[a-zA-Z]/';
if($this->isPatternWrong($newProjectName, $pattern)) {
$context
->buildViolation('Please use letters only.')
->atPath('newprojectname')
->addViolation();
}
// text max. 7 digits
$maxlength = 7;
if($this->isStringTooLong($newProjectName, $maxlength)) {
$context
->buildViolation('Max. length 7 digits.')
->atPath('newprojectname')
->addViolation();
}
}
}
private function isPatternWrong($string, $pattern)
{
$result = preg_match($pattern, $string);
if($result === 0) {
return true;
}
return false;
}
private function isStringTooLong($string, $length)
{
if(strlen($string) > $length) {
return true;
}
return false;
}

magento this letter cannot be sent for particular mail only

Hi programatically i add mail in magento. Default mail system works well. but my mail through this bug.
2013-10-08T05:06:17+00:00 ERR (3):
exception 'Exception' with message 'This letter cannot be sent.' in /home/domain/public_html/fashion/app/code/core/Mage/Core/Model/Email/Template.php:398
Stack trace:
#0 /home/mall140/public_html/fashion/app/code/local/seller/Marketplaceseller/controllers/SendmailController.php(18): Mage_Core_Model_Email_Template->send('amia.1901#...', 'victor', Array)
#1 /home/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Webkul_Marketplacepartner_SendmailController->indexAction()
#2 /home/fashion/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#3 /home/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 /home/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 /home/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#6 /home/index.php(87): Mage::run('', 'store')
This is error code. please help me
This exception means Mage_Core_Model_Email_Template::isValidForSend() returned false:
public function isValidForSend()
{
return !Mage::getStoreConfigFlag('system/smtp/disable')
&& $this->getSenderName()
&& $this->getSenderEmail()
&& $this->getTemplateSubject();
}
Without seeing the code setting up your email template before sending it's hard to say which of the four conditions fails.
My wild guess would be that SMTP mails are disabled in your backend.
Check whether System -> Configuration -> System -> Mail sending settings -> Disable Email Communications is set to "No".
I was also getting same error during calling sendTransactional() function. I was thinking that there is some issue in email template in subject. To find exact issue as mentioned by Jurgen Thalen in his answer I inspected Mage_Core_Model_Email_Template::isValidForSend() function like below
public function isValidForSend()
{
//remove this after checking, never change core files
Mage::log("Sender Name:".$this->getSenderName());
Mage::log("Sender email:".$this->getSenderEmail());
Mage::log("Template subject:".$this->getTemplateSubject());
Mage::log("Email disabled:".Mage::getStoreConfigFlag('system/smtp/disable'));
return !Mage::getStoreConfigFlag('system/smtp/disable')
&& $this->getSenderName()
&& $this->getSenderEmail()
&& $this->getTemplateSubject();
}
Now check your system.log for me template subject was coming fine but sender name and sender email was not coming.
Below was my code:
sendTransactional(
$template,
"myemail#gmail.com",
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
)
Below is send transaction function in core file:
/**
* Send transactional email to recipient
*
* #param int $templateId
* #param string|array $sender sneder informatio, can be declared as part of config path
* #param string $email recipient email
* #param string $name recipient name
* #param array $vars varianles which can be used in template
* #param int|null $storeId
* #return Mage_Core_Model_Email_Template
*/
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
As you can see second parameter $sender should be String or array, as I was passing string but was not accepting.
I changed my sendTransactional() like below: second parameter passing as array
sendTransactional(
$template,
array(
'email' => "myemail#gmail.com",
'name' => "satish sojitra",
),
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
)
It works like charm! Don't forget to remove Mage::log statements from core files.
Below is complete code snippet to send transactional email
$translate = Mage::getSingleton('core/translate');
//#var $translate Mage_Core_Model_Translate
$translate->setTranslateInline(false);
$mailTemplate = Mage::getModel('core/email_template');
//add bcc
$mailTemplate->addBcc("bccemail#gmail.com");//accept array also
//add cc: $Cc_email_ids can be array or string
$mailTemplate->getMail()->addCc($Cc_email_ids);//accept array also
/* #var $mailTemplate Mage_Core_Model_Email_Template */
//template path
$templateConfigPath = "configuration/product_settings/failure_template";
$template = Mage::getStoreConfig($templateConfigPath, Mage::app()->getStore()->getId());
$to = array(
array("email"=> "to_1#gmail.com","name"=>"to_name"),
array("email"=> "to_2#gmail.com","name"=>"to_name")
);
$sendTo = array();
foreach ($to as $recipient)
{
if (is_array($recipient))
{
$sendTo[] = $recipient;
}
else
{
$sendTo[] = array(
'email' => $recipient,
'name' => null,
);
}
}
$myvar1 = 0;
$myvar2 = 0;
$myvar3 = 0;
$myvar4 = "transactional email testing";
foreach ($sendTo as $recipient) {
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>Mage::app()->getStore()->getId()))
->sendTransactional(
$template,
array(
'email' => "myemail#gmail.com",
'name' => "satish sojitra",
),
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
);
}
$translate->setTranslateInline(true);
I hope this will help someone.
If your code is like following
$emailTemplate->sendTransactional($emailTemplateId, $sender, $emailAddress, $name, $data, $store);
and Mage_Core_Model_Email_Template::isValidForSend() returned false. Then most probabbly you are not passing sender information correct.
Check app\code\core\Mage\Core\Model\Email\Template.php
/**
* Send transactional email to recipient
*
* #param int $templateId
* #param string|array $sender sender information, can be declared as part of config path
* #param string $email recipient email
* #param string $name recipient name
* #param array $vars variables which can be used in template
* #param int|null $storeId
*
* #throws Mage_Core_Exception
*
* #return Mage_Core_Model_Email_Template
*/
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
Pass sender data as an array
$sender = array(
'name' => $fromEmail,
'email' => $fromName
);
$emailTemplate->sendTransactional($emailTemplateId, $sender, $emailAddress, $fullName, $data, $store);
then after check if it works.

Resources