操作ActionValidateOrder在验证后未触发

时间:2014-12-30 20:23:16

标签: hook prestashop

我想在prestashop中使用Curl向web服务发送订单信息,发送的是客户创建的成功,我尝试在我的模块中使用hookActimonValidateOrder,

我喜欢测试浏览器控制台发送的内容并查看响应,但我得到一个空响应。 在点击付款模块页面中的订单确认后,我想知道在哪个prestashop页面中执行了操作?

这是我的代码。

public function hookActionValidateOrder($params){

$adresses= $params['customer']->getAddresses($params['customer']->id_lang);
$i=0;
foreach ($adresses as $row){

 $info[$i]['country']=$row['country'];
 $info[$i]['state']=$row['state'];
 $info[$i]['city']=$row['city'];
 $info[$i]['adress1']= $row['adress1'];
 $info[$i]['adress2']= $row['adress2'];
 $info[$i]['firstname']= $row['firstname'];
 $info[$i]['postcode']= $row['postcode'];
 $i++;
}
$ch ='';
foreach($params['order']->getProducts() as $k=> $product){
 $json =$this->get("https://api.fortnox.se/3/articles/".$product['product_id']);
 $json = json_decode($json, true);
//echo $json;
 if(isset($json['ErrorInformation'])){// produit inexistant

  $resu=  $this->post("https://api.fortnox.se/3/articles/",
  '<?xml version="1.0" encoding="UTF-8"?>
  <Article>

  <ArticleNumber>'.$product['product_id'].'</ArticleNumber>

  <Bulky>false</Bulky>

  <ConstructionAccount></ConstructionAccount>

  <Depth>0</Depth>

  <Description>'.$product['product_name'].'</Description>

  <EAN>'.$product['product_reference'].'</EAN>

  <EUAccount></EUAccount>

  <EUVatAccount></EUVatAccount>

  <ExportAccount></ExportAccount>

  <Height>0</Height>

  <Housework>false</Housework>

  <Manufacturer></Manufacturer>

  <ManufacturerArticleNumber>'.$product['product_id'].'</ManufacturerArticleNumber>

  <Note></Note>

  <PurchaseAccount></PurchaseAccount>

  <PurchasePrice>'.$product['product_price'].'</PurchasePrice>

  <QuantityInStock>1</QuantityInStock>

  <SaleAccount>3041</SaleAccount>

  <StockGoods>false</StockGoods>

  <StockPlace>A152</StockPlace>   

  <StockWarning>0</StockWarning>

  <SupplierName></SupplierName>

  <SupplierNumber></SupplierNumber>

  <Type>0</Type>

  <Unit>St</Unit>

  <VAT>25</VAT>

  <Weight></Weight>

  <Width>0</Width>

  </Article>');
 print_r($resu);
}
    $ch.='<OrderRow>
        <AccountNumber>3011</AccountNumber>
        <ArticleNumber>'.$product['product_id'].'</ArticleNumber>
        <ContributionPercent></ContributionPercent>
        <ContributionValue></ContributionValue>
        <CostCenter></CostCenter>
        <DeliveredQuantity>'.$product['product_quantity'].'</DeliveredQuantity>
        <Description>'.$product['product_name'].'</Description>
        <Discount>'.$product['reduction_percent'].'</Discount>
        <DiscountType>PERCENT</DiscountType>
        <HouseWork>false</HouseWork>
        <OrderedQuantity>'.$product['product_quantity'].'</OrderedQuantity>
        <Price>'.$product['product_price'].'</Price>
        <Project>0</Project>
        <Total>'.$product['product_quantity']*$product['product_price'].'</Total>
        <Unit>st</Unit>
        <VAT>0</VAT>
    </OrderRow>';
}  



print_r($this->post("https://api.fortnox.se/3/orders",
'<?xml version="1.0" encoding="UTF-8"?>
<Order>
<AdministrationFee>0</AdministrationFee>
<Address1>'.$info[0]['adress1'].'</Address1>
<Address2>'.$info[0]['adress2'].'</Address2>
<BasisTaxReduction></BasisTaxReduction>
<Cancelled></Cancelled>
<City>'.$info[0]['city'].'</City>
<Comments></Comments>
<ContributionPercent></ContributionPercent>
<ContributionValue></ContributionValue>
<CopyRemarks>true</CopyRemarks>
<Country>'.$info[0]['country'].'</Country>
<CostCenter></CostCenter>
<Currency>'.$params['currency']->iso_code.'</Currency>
<CurrencyRate>1</CurrencyRate>
<CurrencyUnit>1</CurrencyUnit>
<CustomerName>'.$params['customer']->firstname.' '.$params['customer']_>lastname.'</CustomerName>
<CustomerNumber>'.$params['customer']->id.'</CustomerNumber>
<DeliveryAddress1>'.$info[0]['adress1'].'</DeliveryAddress1>
<DeliveryAddress2>'.$info[0]['adress2'].'</DeliveryAddress2>
<DeliveryCity>'.$info[0]['city'].'</DeliveryCity>
<DeliveryCountry>'.$info[0]['country'].'</DeliveryCountry>
<DeliveryDate></DeliveryDate>
<DeliveryName></DeliveryName>
<DeliveryZipCode>'.$info[0]['postcode'].'</DeliveryZipCode>
<DocumentNumber></DocumentNumber>
<EmailInformation>
    <EmailAddressTo>'.$params['customer']->email.'</EmailAddressTo>
    <EmailAddressCC></EmailAddressCC>
    <EmailAddressBCC></EmailAddressBCC>
    <EmailSubject>Order {no} frهn Demobolaget</EmailSubject>
    <EmailBody>Bifogat ser ni er order.</EmailBody>
</EmailInformation>
<Freight>1</Freight>
<Gross></Gross>
<HouseWork>false</HouseWork>
<InvoiceReference></InvoiceReference>
<Language>se</Language>
<Net></Net>
<NotCompleted>false</NotCompleted>
<OfferReference></OfferReference>
<OrderDate>'.date("Y-m-d").'</OrderDate>
<OrderRows>'.$ch.
'</OrderRows>
<OrganisationNumber></OrganisationNumber>
<OurReference>O1</OurReference>
<Phone1>0470-785000</Phone1>
<Phone2>0470-785001</Phone2>
<PriceList>A</PriceList>
<PrintTemplate>ps</PrintTemplate>
<Project></Project>
<Remarks></Remarks>
<RoundOff></RoundOff>
<Sent></Sent>
<TaxReduction></TaxReduction>
<TermsOfDeliveryCode>FVL</TermsOfDeliveryCode>
<TermsOfPaymentCode>15</TermsOfPaymentCode>
<Total>'.$params['order']->total_paid.'</Total>
<TotalVat></TotalVat>
<TransactionId1></TransactionId1>
<TransactionId2>456</TransactionId2>
<VatIncluded>true</VatIncluded>
<WayOfDeliveryCode>P</WayOfDeliveryCode>
<YourReference>Pelle</YourReference>
<YourOrderNumber></YourOrderNumber>
<ZipCode></ZipCode>
</Order>
'));
}

1 个答案:

答案 0 :(得分:1)

当客户在最终结账步骤中确认(创建,完成)他的订单时执行。如果您仍然不确定,可以通过以下方式进行检查:

  1. 转到Hook.php类文件
  2. 查找exec()方法
  3. 在方法中编写error_log($hook_name);
  4. 这样,当您执行某些操作时,您将在错误日志中找到已执行的挂钩。

    其次,您应该始终检查您的挂钩是否已注册 - 您在安装期间以install()方式注册它;如果由于某种原因它仍然无法工作,请转到您的Db,在hook表中找到钩子名称,复制其ID并检查它是否存在于hook_modules表中。

    此外,您应该在函数内部放置一些简单的echo语句,而不是使用foreach循环 - 如果由于某种原因(或数组键不存在)数组为空,该怎么办?