Example #1
0
 /**
  * Creating the Location based on sku
  *
  * @param Location $location The sku of the Location
  * @param Product  $product  The product
  *
  * @return Ambigous <Location, Ambigous, NULL, BaseEntityAbstract>
  */
 public static function create(Location $location, Product $product, PreferredLocationType $type)
 {
     $obj = new PreferredLocation();
     $items = self::getAllByCriteria('locationId = ? and productId = ? and typeId = ?', array($location->getId(), $product->getId(), $type->getId()), true, 1, 1);
     if (count($items) > 0) {
         return $items[0];
     }
     $obj->setLocation($location)->setProduct($product)->setType($type)->save();
     return $obj;
 }
 /**
  * Getting the JSon for PurchaseOrder
  *
  * @param PurchaseOrder $po
  *
  * @return Ambigous <multitype:, multitype:multitype:string  NULL >
  */
 private function _getPOJson(PurchaseOrder $po)
 {
     $array = $po->getJson();
     $array['totalProductCount'] = $po->getTotalProductCount();
     $array['totalReceivedValue'] = $po->getTotalRecievedValue();
     $array['purchaseOrderItem'] = array();
     foreach (PurchaseOrderItem::getAllByCriteria('po_item.purchaseOrderId = :purchaseOrderId', array('purchaseOrderId' => $po->getId())) as $purchaseOrderItem) {
         $product = $purchaseOrderItem->getProduct();
         $EANcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_EAN), true, 1, 1);
         $EANcodes = count($EANcodes) ? $EANcodes[0]->getCode() : '';
         $UPCcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_UPC), true, 1, 1);
         $UPCcodes = count($UPCcodes) ? $UPCcodes[0]->getCode() : '';
         $warehouseLocations = PreferredLocation::getAllByCriteria('productId = :productId and typeId = :typeId', array('productId' => $product->getId(), 'typeId' => PreferredLocationType::ID_WAREHOUSE), true, 1, 1);
         $warehouseLocation = count($warehouseLocations) > 0 && $warehouseLocations[0]->getLocation() instanceof Location ? $warehouseLocations[0]->getLocation()->getName() : '';
         $productArray = $product->getJson();
         $productArray['codes'] = array('EAN' => $EANcodes, 'UPC' => $UPCcodes);
         $productArray['warehouseLocation'] = $warehouseLocation;
         $array['purchaseOrderItem'][] = array('purchaseOrderItem' => $purchaseOrderItem->getJson(), 'product' => $productArray);
     }
     return $array;
 }
Example #3
0
 private function _setLocation(Product &$product, $param)
 {
     if (isset($param->CallbackParameter->locations) && count($locations = $param->CallbackParameter->locations) > 0) {
         //delete all price first
         $deleteIds = array();
         foreach ($locations as $location) {
             if (trim($location->active) === '0' && isset($location->id)) {
                 $deleteIds[] = trim($location->id);
             }
         }
         if (count($deleteIds) > 0) {
             PreferredLocation::updateByCriteria('active = 0', 'id in (' . str_repeat('?', count($deleteIds)) . ')', $deleteIds);
         }
         //update or create new
         foreach ($locations as $location) {
             if (isset($location->id) && in_array(trim($location->id), $deleteIds)) {
                 continue;
             }
             if (!($type = PreferredLocationType::get(trim($location->typeId))) instanceof PreferredLocationType) {
                 continue;
             }
             $locationName = trim($location->value);
             $locs = Location::getAllByCriteria('name = ?', array($locationName), true, 1, 1);
             $loc = count($locs) > 0 ? $locs[0] : Location::create($locationName, $locationName);
             if (!isset($location->id) || ($id = trim($location->id)) === '') {
                 if (trim($location->active) === '1') {
                     PreferredLocation::create($loc, $product, $type);
                 }
                 //if it's deactivated one, ignore
             } else {
                 if (($preferredLocation = PreferredLocation::get($id)) instanceof PreferredLocation) {
                     $preferredLocation->setLocation($loc)->setActive(trim($location->active) === '1')->setProduct($product)->setType($type)->save();
                 }
             }
         }
     }
     return $this;
 }
Example #4
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::getJson()
  */
 public function getJson($extra = array(), $reset = false)
 {
     try {
         $array = $extra;
         if (!$this->isJsonLoaded($reset)) {
             $array['prices'] = array_map(create_function('$a', 'return $a->getJson();'), $this->getPrices());
             $array['manufacturer'] = $this->getManufacturer() instanceof Manufacturer ? $this->getManufacturer()->getJson() : null;
             $array['supplierCodes'] = array_map(create_function('$a', 'return $a->getJson();'), SupplierCode::getAllByCriteria('productId = ?', array($this->getId())));
             $array['productCodes'] = array_map(create_function('$a', 'return $a->getJson();'), ProductCode::getAllByCriteria('productId = ?', array($this->getId())));
             $array['images'] = array_map(create_function('$a', 'return $a->getJson();'), $this->getImages());
             $array['categories'] = array_map(create_function('$a', '$json = $a->getJson(); return $json["category"];'), Product_Category::getCategories($this));
             $array['fullDescriptionAsset'] = ($asset = Asset::getAsset($this->getFullDescAssetId())) instanceof Asset ? $asset->getJson() : null;
             $array['locations'] = array_map(create_function('$a', 'return $a->getJson();'), PreferredLocation::getPreferredLocations($this));
             $array['unitCost'] = $this->getUnitCost();
             $array['priceMatchRule'] = ($i = ProductPriceMatchRule::getByProduct($this)) instanceof ProductPriceMatchRule ? $i->getJson() : null;
             $array['attributeSet'] = ($i = $this->getAttributeSet()) instanceof ProductAttributeSet ? $i->getJson() : null;
             $array['status'] = ($i = $this->getStatus()) instanceof ProductStatus ? $i->getJson() : null;
         }
     } catch (Exception $ex) {
         throw new Exception(' ********** getJson exception :' . $ex->getMessage());
     }
     return parent::getJson($array, $reset);
 }