コード例 #1
0
 protected function getOption($store_id, $order_id)
 {
     $option = Option::findOne(['store_id' => $store_id, 'name' => 'order_' . $order_id]);
     if (!$option) {
         throw new BadRequestHttpException("Order not found");
     }
     return $option;
 }
コード例 #2
0
 public function getAddToCartStats()
 {
     $data = [];
     $store = $this->owner;
     $option = Option::findOne(['store_id' => $store->id, 'name' => 'add_to_cart_counter_statistics']);
     if ($option) {
         $stats = Json::decode($option->value);
         if ($stats) {
             arsort($stats);
             $data = $stats;
             $client = $this->getClient();
             $product_ids = array_keys($stats);
             $result = $client->getRequest('products', ['pid' => $product_ids]);
             if (!empty($result['products'])) {
                 $products = $result['products'];
                 foreach ($products as $product) {
                     $product['added_to_cart'] = $stats[$product['product_id']];
                     $data[$product['product_id']] = $product;
                 }
             }
         }
     }
     return $data;
 }