我是Shopware插件开发的新手,请如何调用与单个客户相关的所有地址?
Shopware v5.4。*
答案 0 :(得分:1)
您可以使用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
个对象的数组。
答案 1 :(得分:0)
经过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;
}