예제 #1
0
 /**
  * @param \Thelia\Core\FileFormat\Formatting\FormatterData
  * @return string|array error messages
  *
  * The method does the import routine from a FormatterData
  */
 public function retrieveFromFormatterData(FormatterData $data)
 {
     $errors = [];
     while (null !== ($row = $data->popRow())) {
         /**
          * Check for mandatory columns
          */
         $this->checkMandatoryColumns($row);
         $obj = ProductSaleElementsQuery::create()->findPk($row["id"]);
         if ($obj === null) {
             $errors[] = $this->translator->trans("The product sale element reference %id doesn't exist", ["%id" => $row["id"]]);
         } else {
             $obj->setQuantity($row["stock"]);
             if (isset($row["ean"]) && !empty($row["ean"])) {
                 $obj->setEanCode($row["ean"]);
             }
             $obj->save();
             $this->importedRows++;
         }
     }
     return $errors;
 }
예제 #2
0
 /**
  * @param \Thelia\Core\FileFormat\Formatting\FormatterData
  * @return string|array error messages
  *
  * The method does the import routine from a FormatterData
  */
 public function retrieveFromFormatterData(FormatterData $data)
 {
     $errors = [];
     $translator = Translator::getInstance();
     while (null !== ($row = $data->popRow())) {
         $this->checkMandatoryColumns($row);
         $obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]);
         if ($obj === null) {
             $errorMessage = $translator->trans("The product sale element reference %ref doesn't exist", ["%ref" => $row["ref"]]);
             $errors[] = $errorMessage;
         } else {
             $currency = null;
             if (isset($row["currency"])) {
                 $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
             }
             if ($currency === null) {
                 $currency = Currency::getDefaultCurrency();
             }
             $price = ProductPriceQuery::create()->filterByProductSaleElementsId($obj->getId())->findOneByCurrencyId($currency->getId());
             if ($price === null) {
                 $price = new ProductPrice();
                 $price->setProductSaleElements($obj)->setCurrency($currency);
             }
             $price->setPrice($row["price"]);
             if (isset($row["promo_price"])) {
                 $price->setPromoPrice($row["promo_price"]);
             }
             if (isset($row["promo"])) {
                 $price->getProductSaleElements()->setPromo((int) $row["promo"])->save();
             }
             $price->save();
             $this->importedRows++;
         }
     }
     return $errors;
 }
예제 #3
0
 public function testPopRow()
 {
     $data = new FormatterData();
     $row = ["title" => "A super book", "author" => "Manu"];
     $data->addRow($row);
     $this->assertEquals($row, $data->popRow());
     $this->assertFalse($data->getRow());
 }