function testPushRegion()
 {
     $mock = $this->getMockWithCart();
     $r = new AjaxHTTPResponse();
     $r->pushRegion('TestSideCart', $mock);
     $json = $r->getBody();
     $data = json_decode($json, true);
     $this->assertNotEmpty($data[AjaxHTTPResponse::REGIONS_KEY]['TestSideCart'], 'should contain an entry for the side cart');
     $this->assertEquals($data[AjaxHTTPResponse::REGIONS_KEY]['TestSideCart'], $mock->renderWith('TestSideCart')->forTemplate(), 'SideCart entry should match the sidecart template');
 }
 /**
  * Add status message to the response (only if `show_ajax_messages` config is set)
  * @param AjaxHTTPResponse $response
  * @param Form|null $form the form instance
  */
 protected function triggerStatusMessage($response, $form = null)
 {
     if (!self::config()->show_ajax_messages) {
         return;
     }
     $message = '';
     $type = '';
     if ($this->owner->cart) {
         $message = $this->owner->cart->getMessage();
         $type = $this->owner->cart->getMessageType();
         $this->owner->cart->clearMessage();
     }
     if ($form) {
         // if the message was not previously set via cart, get the message from $form
         if (empty($message)) {
             $message = $form->Message();
             $type = $form->MessageType();
         }
         $form->clearMessage();
     }
     if (!empty($message)) {
         $response->triggerEvent('statusmessage', array('content' => $message, 'type' => $type));
     }
 }
 /**
  * Adds some standard render contexts for pulled regions.
  *
  * @param AjaxHTTPResponse $response
  * @param GroupedProduct $groupedProduct
  * @param Form $form
  */
 protected function setupRenderContexts(AjaxHTTPResponse $response, $groupedProduct, $form)
 {
     if ($this->owner->getController()->hasMethod('Cart')) {
         $cart = $this->owner->getController()->Cart();
         if ($cart instanceof ViewableData) {
             $response->addRenderContext('CART', $this->owner->getController()->Cart());
         }
     }
     $response->addRenderContext('PRODUCT', $groupedProduct);
     $response->addRenderContext('FORM', $form);
 }
 /**
  * Adds some standard render contexts for pulled regions.
  *
  * @param AjaxHTTPResponse $response
  * @param Buyable $buyable [optional]
  */
 protected function setupRenderContexts(AjaxHTTPResponse $response, $buyable = null)
 {
     if ($this->owner->hasMethod('Cart')) {
         $cart = $this->owner->Cart();
         if ($cart instanceof ViewableData) {
             $response->addRenderContext('CART', $this->owner->Cart());
         }
     }
     if ($buyable) {
         $response->addRenderContext('BUYABLE', $buyable);
         // this could be a Product or ProductVariation (or something else)
         // but we want a render target available for the product specifically
         // for rendering ProductGroupItem in a category or search view
         if ($buyable instanceof Product) {
             $response->addRenderContext('PRODUCT', $buyable);
         } elseif ($buyable->hasMethod('Product')) {
             $response->addRenderContext('PRODUCT', $buyable->Product());
         }
     }
 }