Product::getId PHP Method

getId() public method

public getId ( ) : mixed
return mixed id
    public function getId()
    {
        $variantIds = array_map(function ($var) {
            return $var->id;
        }, $this->selectedVariants);
        sort($variantIds);
        return 'product_' . $this->id . '_' . implode('_', $variantIds);
    }

Usage Example

Example #1
0
 /**
  * A kosárhoz hozzá adja a terméket hozzá tartozó mennyiséggel együtt.
  * A products arrayben a termék id-je az index
  * és ugyan ezzel indexelem a qauntities tömböt, így te megoldásod is maradhat és egyértelmű.
  *
  * @param Product $product
  * @param int $quantity
  */
 public function addProduct($product, $quantity)
 {
     if (!isset($this->products[$product->getId()])) {
         $this->products[$product->getId()] = $product;
         $this->quantities[$product->getId()] = $quantity;
     } else {
         $this->quantities[$product->getId()] += $quantity;
     }
     //echo "elemek száma: " . count($this->items) . " db & " . count($this->quantity) . " db.<br>";
 }
All Usage Examples Of Product::getId