Hello,
I have in the table "sales_order_item" 3 extra rows, which is for special attribute when a product is buying.
How can I access this via API?
I made a call at "rest/V1/orders/items/ID" and get the rows of the order. But this extendet attributes are not included.
Thank you!
I tried to write a new API Endpoint, but always has the error:
'%fieldName is a required field":
etc/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Gedo\Color\Api\ColorInterface" type="Gedo\Color\Model\Color" /> </config>
etc/webapi.xml
<?xml version="1.0"?> <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> <!-- Routing define --> <route url="/V1/color/getcolor/:getcolor" method="GET"> <service class="Gedo\Color\Api\ColorInterface" method="getcolor"/> <resources> <resource ref="anonymous"/> </resources> </route> </routes>
Api/ColorInterface.php:
<?php
namespace Gedo\Color\Api;
interface ColorInterface
{
/**
* Return the special color
*
* @param int $itemId
* @return mixed
*/
public function getcolor($itemId);
}Model/Color.php
<?php
namespace Gedo\Color\Model;
use Gedo\Color\Api\ColorInterface;
protected $_resourceConnection;
protected $_connection;
public function __construct(
\Magento\Framework\App\ResourceConnection $resourceConnection
) {
$this->_resourceConnection = $resourceConnection;
}
class Color implements ColorInterface
{
/**
* Return the special color
*
* @param string $itemId
* @return mixed
*/
public function getcolor($itemId) {
$this->_connection = $this->_resourceConnection->getConnection();
$query = "Select ral_color_picker, ral_color_text, abgetont from sales_order_item where item_id == " . $itemId ;
$collection = $this->_connection->fetchAll($query);
return $collection;
}
}
I made the GET to http://magento2.loc/rest/V1/color/getcolor/56
but get always "%fieldName is a required field"