Skip to content

Instantly share code, notes, and snippets.

@marekkalnik
Created May 17, 2013 08:46
Show Gist options
  • Save marekkalnik/5597819 to your computer and use it in GitHub Desktop.
Save marekkalnik/5597819 to your computer and use it in GitHub Desktop.
Partial references with Doctrine
<?php
protected function getCart($clientCode, $salesmanCode)
{
$em = $this->getDoctrine()->getEntityManager();
$cart = $em->getRepository('TheodoExtranetBundle:ShoppingCart')
->findOneBy(array(
'customerCode' => $clientCode,
'salesmanCode' => $salesmanCode,
'status' => \Theodo\ExtranetBundle\Entity\ShoppingCart::STATUS_OPEN, ));
if (!$cart instanceof ShoppingCart) {
$cart = new ShoppingCart();
$cart->setCustomer(
$em->getPartialReference(
'Theodo\ShopDataBundle\Entity\Customer',
$clientCode
));
$cart->setSalesman(
$em->getPartialReference(
'Theodo\ShopDataBundle\Entity\Customer',
$salesmanCode
));
$cart->setBrand('00');
$cart->setBrandName('extranet');
$em->merge($cart);
$em->flush();
}
return $cart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment