Exemple #1
0
 public function testUpdatePseSale()
 {
     $sale = $this->getRandomSale();
     $date = new \DateTime();
     $product = ProductQuery::create()->findOne();
     $attrAv = AttributeAvQuery::create()->findOne();
     $event = new SaleUpdateEvent($sale->getId());
     $event->setStartDate($date->setTimestamp(strtotime("today - 1 month")))->setEndDate($date->setTimestamp(strtotime("today + 1 month")))->setActive(1)->setDisplayInitialPrice(1)->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)->setPriceOffsets([CurrencyQuery::create()->findOne()->getId() => 10])->setProducts([$product->getId()])->setProductAttributes([$product->getId() => [$attrAv->getId()]])->setLocale('en_US')->setTitle('test update sale title')->setChapo('test update sale short description')->setDescription('test update sale description')->setPostscriptum('test update sale postscriptum')->setSaleLabel('test create sale label');
     $saleAction = new Sale($this->getMockEventDispatcher());
     $saleAction->update($event, null, $this->getMockEventDispatcher());
     $updatedSale = $event->getSale();
     $this->assertInstanceOf('Thelia\\Model\\Sale', $updatedSale);
     $this->assertEquals(1, $updatedSale->getActive());
     $this->assertEquals('test update sale title', $updatedSale->getTitle());
     $this->assertEquals('test update sale short description', $updatedSale->getChapo());
     $this->assertEquals('test update sale description', $updatedSale->getDescription());
     $this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum());
     $this->assertEquals('test create sale label', $updatedSale->getSaleLabel());
 }
Exemple #2
0
 /**
  * Creates the update event with the provided form data
  *
  * @param  array           $formData
  * @return SaleUpdateEvent
  */
 protected function getUpdateEvent($formData)
 {
     // Build the product attributes array
     $productAttributes = [];
     foreach ($formData['product_attributes'] as $productId => $attributeAvIdList) {
         if (!empty($attributeAvIdList)) {
             $productAttributes[$productId] = explode(',', $attributeAvIdList);
         }
     }
     $saleUpdateEvent = new SaleUpdateEvent($formData['id']);
     $saleUpdateEvent->setStartDate($formData['start_date'])->setEndDate($formData['end_date'])->setActive($formData['active'])->setDisplayInitialPrice($formData['display_initial_price'])->setPriceOffsetType($formData['price_offset_type'])->setPriceOffsets($formData['price_offset'])->setProducts($formData['products'])->setProductAttributes($productAttributes)->setLocale($formData['locale'])->setTitle($formData['title'])->setSaleLabel($formData['label'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum']);
     return $saleUpdateEvent;
 }