Manufacturer::addToStore PHP Method

addToStore() public method

public addToStore ( $storeId )
    public function addToStore($storeId)
    {
        if (!ManufacturerToStore::model()->countByAttributes(array('manufacturer_id' => $this->manufacturer_id, 'store_id' => $storeId))) {
            $manufacturerToStore = new ManufacturerToStore();
            $manufacturerToStore->manufacturer_id = $this->manufacturer_id;
            $manufacturerToStore->store_id = $storeId;
            return $manufacturerToStore->save();
        }
        return false;
    }

Usage Example

Beispiel #1
0
 public function save()
 {
     $manufacturer = Manufacturer::model()->findByPk($this->id);
     if (is_null($manufacturer)) {
         // is insert
         $manufacturer = new Manufacturer();
     }
     $manufacturer->name = $this->name;
     $manufacturer->image = $this->image;
     $manufacturer->sort_order = $this->sortOrder;
     $manufacturer->save();
     // SEO Keyword
     $manufacturer->updateSEOKeyword($this->seoKeyword);
     // Stores
     $manufacturer->clearAllStoresRelations();
     if (isset($this->stores) && count($this->stores)) {
         foreach ($this->stores as $storeId) {
             $manufacturer->addToStore($storeId);
         }
     }
 }