扩展 Shopware 客户 API 以包含所有客户的地址
Extending Shopware customers API to include all customer's addresses
我是Shopware插件开发的新手,请问如何调用与单个客户相关的所有地址?
Shopware v5.4.*
您可以使用 AddressRepository
:
查找客户的所有地址
// or you can inject the session and models services
$userId = $this->container->get('session')->get('sUserId');
$addressRepository = $this->container->get('models')->getRepository(Shopware\Models\Customer\Address::class);
$addresses = $addressRepository->findBy(['customer' => $userId]);
$adresses
将是 Address
个对象的数组。
经过一些研究和 Paweł Napierała 的启发,我找到了我正在寻找的东西,这是最终结果:
public function getOne($id)
{
$result = parent::getOne($id);
$addresses = $this->getManager()
->getRepository(\Shopware\Models\Customer\Address::class)
->findBy(['customer'=>$id]);
$resultArray = $this->getManager()->toArray($addresses);
$result ['addresses'] = $resultArray;
return $result;
}
我是Shopware插件开发的新手,请问如何调用与单个客户相关的所有地址?
Shopware v5.4.*
您可以使用 AddressRepository
:
// or you can inject the session and models services
$userId = $this->container->get('session')->get('sUserId');
$addressRepository = $this->container->get('models')->getRepository(Shopware\Models\Customer\Address::class);
$addresses = $addressRepository->findBy(['customer' => $userId]);
$adresses
将是 Address
个对象的数组。
经过一些研究和 Paweł Napierała 的启发,我找到了我正在寻找的东西,这是最终结果:
public function getOne($id)
{
$result = parent::getOne($id);
$addresses = $this->getManager()
->getRepository(\Shopware\Models\Customer\Address::class)
->findBy(['customer'=>$id]);
$resultArray = $this->getManager()->toArray($addresses);
$result ['addresses'] = $resultArray;
return $result;
}