扩展Shopware客户API以包括所有客户地址

时间:2019-07-24 12:32:40

标签: plugins shopware

我是Shopware插件开发的新手,请如何调用与单个客户相关的所有地址?

Shopware v5.4。*

2 个答案:

答案 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;
}
相关问题