示例#1
0
 /**
  * @param TblCommodity $tblCommodity
  * @param TblBasket    $tblBasket
  *
  * @return TblBasket
  */
 public function actionCreateBasketItemsByCommodity(TblBasket $tblBasket, TblCommodity $tblCommodity)
 {
     $Manager = $this->Connection->getEntityManager();
     $tblCommodityItemList = Commodity::useService()->entityCommodityItemAllByCommodity($tblCommodity);
     /** @var TblCommodityItem $tblCommodityItem */
     foreach ($tblCommodityItemList as $tblCommodityItem) {
         $Entity = $Manager->getEntity('TblBasketItem')->findOneBy(array(TblBasketItem::ATTR_TBL_Basket => $tblBasket->getId(), TblBasketItem::ATTR_SERVICE_BILLING_COMMODITY_ITEM => $tblCommodityItem->getId()));
         if (null === $Entity) {
             $Entity = new TblBasketItem();
             $Entity->setPrice($tblCommodityItem->getTblItem()->getPrice());
             $Entity->setQuantity($tblCommodityItem->getQuantity());
             $Entity->setServiceBillingCommodityItem($tblCommodityItem);
             $Entity->setTblBasket($tblBasket);
             $Manager->bulkSaveEntity($Entity);
             Protocol::useService()->createInsertEntry($this->Connection->getDatabase(), $Entity);
         }
     }
     $Manager->flushCache();
     return $tblBasket;
 }