protected function assignPatternType(Pattern $pattern) { $id = $pattern->getId(); $patternIndex = false; // 0:皮夾: {6} // 1:包包: {3, 4, 5, 13, 18, 24, 28, 30, 32, 44} // 2:配件: {1, 7, 22, 23, 25, 41, 43, 46, 47, 48} $patternGroups = array(array(6), array(3, 4, 5, 13, 18, 24, 28, 30, 32, 44), array(1, 7, 22, 23, 25, 41, 43, 46, 47, 48)); foreach ($patternGroups as $key => $group) { if (in_array($id, $group)) { $patternIndex = $key; break; } } return $patternIndex; }
public function getImgRelDir(User $user) { $dirParts = array(); $dirParts[] = 'img'; $dirParts[] = 'product'; $dirParts[] = $user->getStore()->getSn(); $dirParts[] = $this->brand ? $this->brand->getName() : 'NoBrand'; $dirParts[] = $this->pattern ? $this->pattern->getName() : 'NoPattern'; $dirParts[] = $this->sn; return '/' . implode('/', $dirParts); }
/** * 品牌批次上傳自動添加程序 * * @param [string] $sBrandName [品牌名稱] * @param [string] $sBrandTypeName [款式名稱] * @param [string] $sBrandSnName [型號名稱] * @param [string] $sBrandSnColor [型號顏色] * @return [object] [this] */ protected function brandAutoProcess($sBrandName, $sBrandTypeName, $sBrandSnName, $sBrandSnColor, $colorName) { // 取得實體管理員 $em = $this->em; // 判斷品牌是否存在 // 若存在則繼續檢查款式是否存在 // 若不存在則新增傳入的品牌, 款式, 型號 // $this->oBrandSn 這行是用來讓商品綁上此型號物件用 , // 透過屬性比較快, 直接回傳也是可以可是失去鏈結性有點不喜歡 $rBrand = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Brand')->findBy(array('name' => $sBrandName)); if ($rBrand) { $oBrand = $rBrand[0]; } else { $oBrand = new Brand(); $oBrand->setName($sBrandName); $em->persist($oBrand); } if ($colorName != '') { $colors = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Color')->findBy(array('name' => $colorName)); if ($colors) { $color = $colors[0]; } else { $color = new Color(); $color->setName($colorName)->setCode('#FFFFFF'); $em->persist($color); } } else { $color = null; } if ($sBrandTypeName != '') { // 判斷款式是否存在 // 若存在則繼續檢查型號是否存在 // 若不存在則新增傳入的 款式, 型號 $patterns = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Pattern')->findBy(array('name' => $sBrandTypeName)); if ($patterns) { $pattern = $patterns[0]; } else { $pattern = new Pattern(); $pattern->setName($sBrandTypeName); $em->persist($pattern); } } $em->flush(); $this->brand = $oBrand; $this->color = $color; $this->pattern = $pattern; return $this; }