public function onMessage(ConnectionInterface $from, $msg) { $result = null; foreach ($this->clients as $client) { if ($from == $client) { $type = strtolower(substr($msg, 0, strpos($msg, '|'))); $data = substr($msg, strpos($msg, '|') + 1); switch ($type) { case 'cart': $result = Cart::getCartData($data); break; case 'prod': $result = Product::getProductData($data); break; case 'comb': $result = Combination::getCombinationData($data); break; default: break; } if (!empty($result)) { $client->send(json_encode($result)); } } } }
/** * @param null|string $id_product_attribute * @param string $product */ private function getCombination($product, $id_product_attribute) { $combo = $this->getAttributeBase($id_product_attribute); if (is_array($combo)) { foreach ($combo as $key => $value) { $combo['base_price'] = (double) Product::getOrderPrice($product); $combo['quantity'] = (int) $this->getStockQuantity($product, $id_product_attribute); $combo['id_product'] = (int) $product; $combo['product_name'] = (int) $this->getProductName($product); $pricing = $this->getAttributePricing($id_product_attribute); foreach ($pricing as $ki => $val) { $combo[$ki] = $val; } } } return $combo; }