PHP code example of requestdesk / magento-qa

1. Go to this page and download the library: Download requestdesk/magento-qa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

requestdesk / magento-qa example snippets


use RequestDesk\Qa\Model\QaLinkResolver;

// Entity-type constants
QaLinkResolver::ENTITY_BLOG_POST; // 'blog_post'
QaLinkResolver::ENTITY_PRODUCT;   // 'product'

// Read the pairs attached to an entity (ordered by position)
$pairs = $resolver->getPairsFor(QaLinkResolver::ENTITY_BLOG_POST, $postId);
// [['qa_id' => 1, 'question' => '...', 'answer' => '...'], ...]

// Just the ids (e.g. to preselect a form multiselect)
$ids = $resolver->getQaIdsFor(QaLinkResolver::ENTITY_PRODUCT, $productId);

// Attach / detach a single pair
$resolver->attach($qaId, QaLinkResolver::ENTITY_PRODUCT, $productId, $position = 0);
$resolver->detach($qaId, QaLinkResolver::ENTITY_PRODUCT, $productId);

// Replace an entity's whole set (add + remove to match exactly)
$resolver->syncForEntity(QaLinkResolver::ENTITY_BLOG_POST, $postId, [1, 4, 7]);

use RequestDesk\Qa\Model\FaqSchemaBuilder;

// Turn pairs into a schema.org FAQPage node (JSON-LD ready)
$node = $builder->build($pairs, $withContext = true);
// null when $pairs is empty