Is there a way to add a custom button to the Member Object with Unclecheese BetterButtons? I'm extending the Member Object with a DataExtension where I want to create a BetterButtons Custom Action.
That's my code and the error I receive
private static $better_buttons_actions = array(
'createAccountPdf'
);
public function getBetterButtonsActions(){
$fields = parent::getBetterButtonsActions();
if( $this->owner->Accounts()->Count() > 0 ){
$fields->push(BetterButtonCustomAction::create('createAccountPdf', 'Datenblatt erstellen')->setSuccessMessage('PDF Datenblatt mit Zugangsdaten wurde erstellt.'));
}
return $fields;
}
Error:
Fatal error: Call to undefined method DataObject::getBetterButtonsActions() in /_website/_dev/mysite/code/Extensions/ClientMemberExtension.php on line 128
Instead of parent::getBetterButtonsActions() I also tried it with $this->owner, Member::, DataObject::
This sounds logical cause the parent of your extension doesn't have a method called "getBetterButtonActions".
From the code in BetterButtonDataObject i see there is already a hook to update ButtonActions in a DataExtension.
try:
public function updateBetterButtonsActions(&$actions) {
if( $this->owner->Accounts()->Count() > 0 ){
$actions->push(BetterButtonCustomAction::create('createAccountPdf', 'Datenblatt erstellen')->setSuccessMessage('PDF Datenblatt mit Zugangsdaten wurde erstellt.'));
}
}
Related
I am making a custom validation process for a client, but it depends on country. In the Netherlands, one can use IDIN for this.
So i need to do a check in the checkout to find out if the country is "Netherlands". If that is the case, an extra field is needed to do the validation of the customer. This can be echo'ed via a shortcode.
So far i have the following:
function validate_country( $fields, $errors ){
$return = false;
if ( $fields[ 'billing_country' ] == 'Netherlands' ) {
$return = true;
$errors->add( 'validation', 'Please fill in the IDIN requirement' );
}
return $return;
}
add_action( 'woocommerce_after_checkout_validation', 'validate_country', 10,2 );
function print_idin_form() {
if(validate_country()){
echo do_shortcode('[bluem_identificatieformulier]');
}
}
add_action('woocommerce_checkout_after_customer_details','print_idin_form');
However, when i use this, it throws an error on pageload because obviously, the validate_country function is not executed yet. The error I get is:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function validate_country(), 0 passed
How to solve this?
i have a problem
after update woocommerce this problem occurred
I appreciate your help
Fatal error: Access level to AtWCTourDataStoreCPT::read_children() must be public (as in class WC_Product_Variable_Data_Store_CPT) in /home3/abrobadg/public_html/wp-content/themes/adventure-tours/includes/classes/AtWCTourDataStoreCPT.php on line 58
enter image description here
enter image description here
first make a backup/copy of this file : \wp-content\themes\adventure-tours\includes\classes\AtWCTourDataStoreCPT.php
change this two functions’ visibility from protected to public at line 25 and 29 like this:
protected function read_children (...” to “public function read_children (....
and
protected function read_variation_attributes( ....” to “public function read_variation_attributes( ....
It worked for me
Change read_children for read_parent and read_variation_attributes for read_parent_attributes like in the code below:
protected function read_parent( &$product, $force_read = false ) {
return $this->is_variable( $product ) ? parent::parent( $product, $force_read ) : array();
}
protected function read_parent_attributes( &$product ) {
return $this->is_variable( $product ) ? parent::read_variation_attributes( $product ) : array();
}
I'd like to have the field name in addition to the error message.
I performed the following set of instructions to put all errors into an array :
$errors= array();
foreach ($newRdvForm->getErrors(true) as $key => $error) {
$errors[$key] = $error->getMessage();
}
So what can i to have the field name of each input ?
If there are other method, feel free to publish it
The FormInterface::getErrors() method returns a FormErrorIterator instance. The underlying FormError objects provide a getOrigin() method which returns the FormInterface the error relates to.
I am trying to run my first functional test in Symfony2 using the DemoController.
If I load the page from the browser the data displayed are correct.
But if I try to run the test by using the command phpunit -c app I got the following error message:
There was 1 error:
1) Blog\CoreBundle\Tests\Controller\AuthorControllerTest::testShow
Object of class Symfony\Component\DomCrawler\Crawler could not be converted to string
Here is my AuthorControllerTest class:
<?php
namespace Blog\CoreBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Class AuthorControllerTest
*/
class AuthorControllerTest extends WebTestCase
{
/**
* Test show author
*/
public function testShow()
{
$client = static::createClient();
/** #var Author $author */
$author = $client->getContainer()
->get('doctrine')
->getManager()
->getRepository('ModelBundle:Author')
->findFirst();
$authorPostCount = $author->getPosts()->count();
$crawler = $client->request('GET', '/author/'.$author->getSlug());
$this->assertTrue($client->getResponse()->isSuccessful(), 'The response was not successful');
$this->assertTrue($authorPostCount, $crawler->filter('h2'), 'There should be '.$authorPostCount.' posts');
}
}
You get the message error when you execute the following line:
$this->assertTrue($authorPostCount, $crawler->filter('h2'), 'There should be '.$authorPostCount.' posts');
The error is due to the wrong parameters you pass to assertTrue function. This is used just to assert that a condition is true.
To assert the number of elements your should use the function assertCount.
$this->assertcount($authorPostCount, $crawler->filter('h2'), 'There should be '.$authorPostCount.' posts');
$crawler->filter('h2') return an object. To compare content of it use text() method to extract information. Try
$this->assertEquals($authorPostCount, $crawler->filter('h2')->text(), 'There should be '.$authorPostCount.' posts');
EDIT:
And if you just want to compare number of posts (not the <h2> node value but number of <h2> nodes on page) use count()
$this->assertEquals($authorPostCount, $crawler->filter('h2')->count(), 'There should be '.$authorPostCount.' posts');
or just
$this->assertCount($authorPostCount, $crawler->filter('h2'), 'There should be '.$authorPostCount.' posts');
I have a method within my controller that takes a deserialized object from JMSSerializerBundle and returns the full object, ready to be persisted. The reason I'm doing this is to return the updated object so, when it's persisted, it doesn't reset everything to the default.
When ran, this method ends up throwing an ErrorException on the indicated line and puts this in my log: Warning: ReflectionProperty::setValue() expects parameter 1 to be object, null given in C:\DevelopmentProjects\keobi-web\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMetadata.php line 177 (uncaught exception) at C:\DevelopmentProjects\keobi-web\vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php line 65
For some reason, the EntityManager method find is returning (according to get_class) DefaultController, the controller class for this method. And the setFieldValue says it's NULL.
One thing that's confusing me is the Doctrine\ORM\EntityNotFoundException should be thrown if the entity isn't found. It's not being thrown. So, it's obviously finding the entity, not not returning it properly...
Incoming parameter $data is the object deserialized by JSMSerializerBundle. $em is definitely EntityManager and $metadata is definitely ClassMetadata.
I'm at a loss here. No idea how to proceed.
protected function processEntity($data)
{
$em = $this->getDoctrine()->getEntityManager();
$metadata = $em->getClassMetadata(get_class($data));
$fqcn = $metadata->getName();
$blankEntity = new $fqcn();
$id = array();
$this->get('logger')->debug('Incoming object type: ' . get_class($data)); # Keobi\ModelBundle\Entity\User
$this->get('logger')->debug('Blank entity type: ' . get_class($blankEntity)); # Keobi\ModelBundle\Entity\User
$this->get('logger')->debug('FQCN: ' . $fqcn); # Keobi\ModelBundle\Entity\User
foreach ($metadata->getIdentifierFieldNames() as $identifier)
{
$id[$identifier] = $metadata->getFieldValue($data, $identifier);
if (!$id[$identifier])
{
$this->get('logger')->debug(sprintf("Identifer '%s' missing. Assuming the object is new.", $identifier));
return $data;
}
}
$entity = $em->find($metadata->getName(), $id);
$this->get('logger')->debug(get_class($entity)); # Keobi\RestAPIBundle\DefaultController
foreach ($metadata->getFieldNames() as $field)
{
$value = $metadata->getFieldValue($data, $field);
$default = $metadata->getFieldValue($blankEntity, $field);
if ($value <> $default)
{
$metadata->setFieldValue($entity, $field, $value); # <- throws ErrorException
$this->get('logger')->debug(sprintf("Updated field '%s' in %s", $field, get_class($entity)));
}
}
return $entity;
}
Looks like there was an issue with Doctrine2. I updated it to the latest HEAD commit of the Github repo. What puzzles me is that this method actually worked not too long ago.
Couldn't find the exact commit that fixed the issue, but, as of this writing, the commit is 93cef612701b9e8caaf43c745978cd4fbd9d4e4e.
$entity = $em->find($metadata->getName(), $id);
You need to specify Repository in which you search, like:
$entity = $em->getRepository('EntitiesBundle:Entity')->find(...)