Ejemplo n.º 1
0
 public function removeFromRelatedProducts(Product $product, $type)
 {
     $this->getRelationships($type);
     $relationship = ProductRelationship::getInstance($this, $product, $type);
     $this->relationships[$type]->removeRecord($relationship);
     $this->getRemovedRelationships()->add($relationship);
 }
Ejemplo n.º 2
0
 /**
  * @role update
  */
 public function sort()
 {
     $target = $this->request->get('target');
     if (!$target) {
         foreach ($this->request->toArray() as $key => $value) {
             if (is_array($value)) {
                 $target = $key;
                 break;
             }
         }
     }
     $product = Product::getInstanceByID($this->request->get('id'));
     $type = $this->request->get('type');
     preg_match('/_(\\d+)$/', $target, $match);
     // Get group.
     if (substr($target, 0, 8) == 'noGroup_') {
         $match = array();
     }
     foreach ($this->request->get($target, array()) as $position => $key) {
         if (empty($key)) {
             continue;
         }
         $relationship = ProductRelationship::getInstance($product, Product::getInstanceByID((int) $key), $type);
         $relationship->position->set((int) $position);
         if (isset($match[1])) {
             $relationship->productRelationshipGroup->set(ProductRelationshipGroup::getInstanceByID((int) $match[1]));
         } else {
             $relationship->productRelationshipGroup->setNull();
         }
         $relationship->save();
     }
     return new JSONResponse(false, 'success');
 }