| <?php |
| /* |
| Example Action feed for Google Order Redirect. Create build/gen directory for generated proto classes. |
| Download lastest version of protoc from https://github.com/protocolbuffers/protobuf/releases. |
| Generate proto classes with: |
| protoc --php_out=./build/gen --proto_path=../proto/ ../proto/action.proto |
| |
| See https://protobuf.dev/reference/php/php-generated/ for more details. |
| */ |
| |
| require dirname(__FILE__).'/vendor/autoload.php'; |
| |
| use Madden\Ingestion\ActionFeed; |
| use Madden\Ingestion\ActionDetail; |
| use Madden\Ingestion\Action; |
| use Madden\Ingestion\FoodOrderingInfo; |
| use Madden\Ingestion\FoodOrderingInfo\ServiceType; |
| |
| function createFeed() { |
| // Create ActionDetail by passing the fields to the constructor |
| $actions = array( |
| // Example using one link for both takeout and delivery |
| new ActionDetail([ |
| 'entity_id' => 'merchant-1', |
| 'link_id' => 'merchant-1-takeout-delivery-action', |
| 'actions' => array( |
| new Action([ |
| 'food_ordering_info' => new FoodOrderingInfo([ |
| 'service_type' => ServiceType::DELIVERY |
| ]) |
| ]), |
| new Action([ |
| 'food_ordering_info' => new FoodOrderingInfo([ |
| 'service_type' => ServiceType::TAKEOUT |
| ]) |
| ]) |
| ), |
| 'url' => 'http://provider.com/merchant-1' |
| ]), |
| // Example using a separate link for delivery |
| new ActionDetail([ |
| 'entity_id' => 'merchant-2', |
| 'link_id' => 'merchant-2-delivery-action', |
| 'actions' => array( |
| new Action([ |
| 'food_ordering_info' => new FoodOrderingInfo([ |
| 'service_type' => ServiceType::DELIVERY |
| ]) |
| ]) |
| ), |
| 'url' => 'http://provider.com/merchant-2/delivery' |
| ]) |
| ); |
| |
| // Add ActionDetail array to feed data |
| $feed = new ActionFeed(); |
| $feed->setData($actions); |
| |
| // Serialize to JSON |
| return $feed->serializeToJsonString(); |
| } |
| |
| $feedJSON = createFeed(); |
| echo $feedJSON; |